分散式查詢優化SERIAL_FROM_REMOTE
SQL> set autotrace on
SQL> select * from zhouwf.temp1@cslndc,zhouwf.temp2 where temp1.id=temp2.id;
ID MC
---------- ------------------------------------------------------------
ID MC
---------- ------------------------------------------------------------
1 1
1 1
2 2
2 2
3 3
3 3
ID MC
---------- ------------------------------------------------------------
ID MC
---------- ------------------------------------------------------------
4 4
4 4
5 5
5 5
6 6
6 6
ID MC
---------- ------------------------------------------------------------
ID MC
---------- ------------------------------------------------------------
7 7
7 7
8 8
8 8
9 9
9 9
ID MC
---------- ------------------------------------------------------------
ID MC
---------- ------------------------------------------------------------
10 10
10 10
11 11
11 11
12 12
12 12
ID MC
---------- ------------------------------------------------------------
ID MC
---------- ------------------------------------------------------------
13 13
13 13
14 14
14 14
15 15
15 15
ID MC
---------- ------------------------------------------------------------
ID MC
---------- ------------------------------------------------------------
16 16
16 16
17 17
17 17
18 18
18 18
ID MC
---------- ------------------------------------------------------------
ID MC
---------- ------------------------------------------------------------
19 19
19 19
20 20
20 20
100 100
100 100
已選擇21行。
執行計劃
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TEMP2'
2 1 NESTED LOOPS
3 2 REMOTE* CSLNDC
4 2 INDEX (RANGE SCAN) OF 'IDX_TEMP2' (NON-UNIQUE)
3 SERIAL_FROM_REMOTE SELECT "ID","MC" FROM "ZHOUWF"."TEMP1" "TEMP
1"
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
10 consistent gets
0 physical reads
0 redo size
995 bytes sent via SQL*Net to client
522 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
21 rows processed
SQL>
對於執行計劃:SERIAL_FROM_REMOTE
http://yaanzy.itpub.net/post/1263/31064
所有的遠端資料傳到本地來處理。所以對於這類查詢最好換成排序合併連線或者hash連線。
下面例子中的表aaa、bbb分別位於兩個庫,aaa所在庫通過資料庫鏈db244訪問bbb表:
create table aaa as select * from dba_objects;
create table bbb as select * from dba_objects;
1、巢狀迴圈連線
SQL> select count(*) from aaa a
where exists
(select * from bbb@db244 b where a.object_id=b.object_id);
COUNT(*)
----------
27165
Elapsed: 00:04:04.74
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (AGGREGATE)
2 1 FILTER
3 2 TABLE ACCESS (FULL) OF 'AAA'
4 2 REMOTE* DB244.US.ORACLE.COM
4 SERIAL_FROM_REMOTE SELECT "OBJECT_ID" FROM "BBB" "B" WHERE "OBJECT_ID"=:1
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
437 consistent gets
0 physical reads
0 redo size
381 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
2、排序合併連線
SQL> select count(*) from aaa a
where a.object_id in
(select object_id from bbb@db244 b);
COUNT(*)
----------
27165
Elapsed: 00:00:00.59
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (AGGREGATE)
2 1 MERGE JOIN
3 2 SORT (JOIN)
4 3 TABLE ACCESS (FULL) OF 'AAA'
5 2 SORT (JOIN)
6 5 VIEW OF 'VW_NSO_1'
7 6 SORT (UNIQUE)
8 7 REMOTE* DB244.US.ORACLE.COM
8 SERIAL_FROM_REMOTE SELECT "OBJECT_ID" FROM "BBB" "B"
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
437 consistent gets
0 physical reads
0 redo size
381 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
3 sorts (memory)
0 sorts (disk)
1 rows processed
3、通過提示改用hash連線
SQL> select /*+ use_hash(a,b) */count(*) from aaa a
where exists
(select * from bbb@db244 b
where a.object_id=b.object_id);
COUNT(*)
----------
27165
Elapsed: 00:00:00.51
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=91 Card=1 Bytes=26)
1 0 SORT (AGGREGATE)
2 1 HASH JOIN (SEMI) (Cost=91 Card=27172 Bytes=706472)
3 2 TABLE ACCESS (FULL) OF 'AAA' (Cost=47 Card=27172 Bytes=353236)
4 2 VIEW OF 'VW_SQ_1' (Cost=42 Card=32509 Bytes=422617)
5 4 REMOTE* (Cost=42 Card=32509 Bytes=422617)
DB244.US.ORACLE.COM
5 SERIAL_FROM_REMOTE SELECT "OBJECT_ID" FROM "BBB" "B"
Statistics
----------------------------------------------------------
3 recursive calls
0 db block gets
468 consistent gets
0 physical reads
0 redo size
381 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:456820211101
Followup:
the query plan showed us that -- two remote operations followed by a filter.
gives us the remote query that was executed and all.
it is basically taking:
2 select tracknum, status, transdate, insseq
10:09:24 3 from workhistory@wkl
10:09:24 4 where tracknum in (select distinct tracknum from workhistory@wkl
where insseq = 142);
and executing it like this:
for x in ( select * from remote_table )
loop
query remote table again by tracknum to get tracknum and insseq
if one of the the returned insseq's is 142
then
output record
end if
end loop
Execution Plan
----------------------------------------------------------
0 INSERT STATEMENT Optimizer=CHOOSE (Cost=172346 Card=57009 By
tes=2052324)
1 0 FILTER
2 1 REMOTE* (Cost=1319 Card=57009 Bytes=2052324) WKL
3 1 REMOTE* (Cost=3 Card=1 Bytes=24) WKL
2 SERIAL_FROM_REMOTE SELECT "TRACKNUM","STATUS","TRANSDATE","INSS
EQ" FROM "WORKHISTORY" "SYS_ALIAS_1"
3 SERIAL_FROM_REMOTE SELECT "TRACKNUM","INSSEQ" FROM "WORKHISTORY
" "WORKHISTORY" WHERE "TRACKNUM"=:1
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/756652/viewspace-242245/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 查詢優化優化
- Kafka分散式查詢引擎Kafka分散式
- SQL Server 分散式查詢SQLServer分散式
- pgsql查詢優化之模糊查詢SQL優化
- Oracle in 查詢優化Oracle優化
- MySQL查詢優化MySql優化
- join 查詢優化優化
- HBase查詢優化優化
- 查詢優化器優化
- SQL查詢優化SQL優化
- MySQL 的查詢優化MySql優化
- 分頁查詢優化優化
- MySQL 慢查詢優化MySql優化
- KunlunDB 查詢優化(一)優化
- MySQL優化COUNT()查詢MySql優化
- 優化sql查詢速度優化SQL
- EntityFramework優化:查詢效能Framework優化
- EntityFramework優化:查詢WITH(NOLOCK)Framework優化
- 優化星型查詢優化
- mysql查詢優化檢查 explainMySql優化AI
- MySQL調優之查詢優化MySql優化
- 資料庫查詢優化:巢狀查詢資料庫優化巢狀
- Citus 分散式 PostgreSQL 叢集 - SQL Reference(查詢分散式表 SQL)分散式SQL
- Presto:Facebook的分散式SQL查詢引擎REST分散式SQL
- MySQL-效能優化-索引和查詢優化MySql優化索引
- MySQL——優化巢狀查詢和分頁查詢MySql優化巢狀
- MySQL查詢優化利刃-EXPLAINMySql優化AI
- exists與in子查詢優化優化
- MySQL索引與查詢優化MySql索引優化
- 效能優化之分頁查詢優化
- APP查詢圖片優化APP優化
- MySQL分頁查詢優化MySql優化
- 資料庫查詢優化資料庫優化
- mysql關聯查詢優化MySql優化
- SQL Server 查詢優化功能SQLServer優化
- 全文查詢的效能優化優化
- SQL查詢優化的方法SQL優化
- 效能優化查詢語句優化