成人性生交大片免费看视频r_亚洲综合极品香蕉久久网_在线视频免费观看一区_亚洲精品亚洲人成人网在线播放_国产精品毛片av_久久久久国产精品www_亚洲国产一区二区三区在线播_日韩一区二区三区四区区区_亚洲精品国产无套在线观_国产免费www

主頁(yè) > 知識(shí)庫(kù) > 遠(yuǎn)程數(shù)據(jù)庫(kù)的表超過(guò)20個(gè)索引的影響詳細(xì)解析

遠(yuǎn)程數(shù)據(jù)庫(kù)的表超過(guò)20個(gè)索引的影響詳細(xì)解析

熱門(mén)標(biāo)簽:南昌呼叫中心外呼系統(tǒng)哪家好 怎么申請(qǐng)400熱線電話 怎么去開(kāi)發(fā)一個(gè)電銷(xiāo)機(jī)器人 泗洪正規(guī)電話機(jī)器人找哪家 ai電話電話機(jī)器人 簡(jiǎn)單的智能語(yǔ)音電銷(xiāo)機(jī)器人 河北便宜電銷(xiāo)機(jī)器人軟件 湖南保險(xiǎn)智能外呼系統(tǒng)產(chǎn)品介紹 小程序智能電話機(jī)器人

昨天同事參加了一個(gè)研討會(huì),有提到一個(gè)案例。一個(gè)通過(guò)dblink查詢(xún)遠(yuǎn)端數(shù)據(jù)庫(kù),原來(lái)查詢(xún)很快,但是遠(yuǎn)端數(shù)據(jù)庫(kù)增加了一個(gè)索引之后,查詢(xún)一下子變慢了。

經(jīng)過(guò)分析,發(fā)現(xiàn)那個(gè)通過(guò)dblink的查詢(xún)語(yǔ)句,查詢(xún)遠(yuǎn)端數(shù)據(jù)庫(kù)的時(shí)候,是走索引的,但是遠(yuǎn)端數(shù)據(jù)庫(kù)添加索引之后,如果索引的個(gè)數(shù)超過(guò)20個(gè),就會(huì)忽略第一個(gè)建立的索引,如果查詢(xún)語(yǔ)句恰好用到了第一個(gè)建立的索引,被忽略之后,只能走Full Table Scan了。

聽(tīng)了這個(gè)案例,我查了一下,在oracle官方文檔中,關(guān)于Managing a Distributed Database有一段話:

Several performance restrictions relate to access of remote objects:

Remote views do not have statistical data.
Queries on partitioned tables may not be optimized.
No more than 20 indexes are considered for a remote table.
No more than 20 columns are used for a composite index.

說(shuō)到,如果遠(yuǎn)程數(shù)據(jù)庫(kù)使用超過(guò)20個(gè)索引,這些索引將不被考慮。這段話,在oracle 9i起的文檔中就已經(jīng)存在,一直到12.2還有。

那么,超過(guò)20個(gè)索引,是新的索引被忽略了?還是老索引被忽略了?如何讓被忽略的索引讓oracle意識(shí)到?我們來(lái)測(cè)試一下。
(本文基于12.1.0.2的遠(yuǎn)程庫(kù)和12.2.0.1的本地庫(kù)進(jìn)行測(cè)試,如果對(duì)測(cè)試過(guò)程沒(méi)興趣的,可以直接拉到文末看“綜上”部分)

(一)初始化測(cè)試表:

--創(chuàng)建遠(yuǎn)程表:
DROP TABLE t_remote;
 CREATE TABLE t_remote (
col01 NUMBER,
col02 NUMBER,
col03 VARCHAR2(50),
col04 NUMBER,
col05 NUMBER,
col06 VARCHAR2(50),
col07 NUMBER,
col08 NUMBER,
col09 VARCHAR2(50),
col10 NUMBER,
col11 NUMBER,
col12 VARCHAR2(50),
col13 NUMBER,
col14 NUMBER,
col15 VARCHAR2(50),
col16 NUMBER,
col17 NUMBER,
col18 VARCHAR2(50),
col19 NUMBER,
col20 NUMBER,
col21 VARCHAR2(50),
col22 NUMBER,
col23 NUMBER,
col24 VARCHAR2(50),
col25 NUMBER,
col26 NUMBER,
col27 VARCHAR2(50)
);
alter table t_remote modify (col01 not null);
INSERT INTO t_remote
SELECT
rownum, rownum, rpad('*',50,'*'),
rownum, rownum, rpad('*',50,'*'),
rownum, rownum, rpad('*',50,'*'),
rownum, rownum, rpad('*',50,'*'),
rownum, rownum, rpad('*',50,'*'),
rownum, rownum, rpad('*',50,'*'),
rownum, rownum, rpad('*',50,'*'),
rownum, rownum, rpad('*',50,'*'),
rownum, rownum, rpad('*',50,'*')
FROM dual
CONNECT BY level = 10000;
commit; 
create unique index t_remote_i01_pk on t_remote (col01);
alter table t_remote add (constraint t_remote_i01_pk primary key (col01) using index t_remote_i01_pk);
create index t_remote_i02 on t_remote (col02);
create index t_remote_i03 on t_remote (col03);
create index t_remote_i04 on t_remote (col04);
create index t_remote_i05 on t_remote (col05);
create index t_remote_i06 on t_remote (col06);
create index t_remote_i07 on t_remote (col07);
create index t_remote_i08 on t_remote (col08);
create index t_remote_i09 on t_remote (col09);
create index t_remote_i10 on t_remote (col10);
create index t_remote_i11 on t_remote (col11);
create index t_remote_i12 on t_remote (col12);
create index t_remote_i13 on t_remote (col13);
create index t_remote_i14 on t_remote (col14);
create index t_remote_i15 on t_remote (col15);
create index t_remote_i16 on t_remote (col16);
create index t_remote_i17 on t_remote (col17);
create index t_remote_i18 on t_remote (col18);
create index t_remote_i19 on t_remote (col19);
create index t_remote_i20 on t_remote (col20);
 
exec dbms_stats.gather_table_stats(user,'T_REMOTE');
--創(chuàng)建本地表:
drop table t_local;
 
CREATE TABLE t_local (
col01 NUMBER,
col02 NUMBER,
col03 VARCHAR2(50),
col04 NUMBER,
col05 NUMBER,
col06 VARCHAR2(50)
);
 
INSERT INTO t_local
SELECT
rownum, rownum, rpad('*',50,'*'),
rownum, rownum, rpad('*',50,'*')
FROM dual
CONNECT BY level = 50;
 
COMMIT;
 
create index t_local_i01 on t_local (col01);
create index t_local_i02 on t_local (col02);
create index t_local_i03 on t_local (col03);
create index t_local_i04 on t_local (col04);
create index t_local_i05 on t_local (col05);
create index t_local_i06 on t_local (col06);
 
exec dbms_stats.gather_table_stats(user,'t_local');
 
 
create database link dblink_remote CONNECT TO test IDENTIFIED BY test USING 'ora121';
 
 
SQL> select host_name from v$instance@dblink_remote;
 
HOST_NAME
----------------------------------------------------------------
testdb2
 
SQL> select host_name from v$instance;
 
HOST_NAME
----------------------------------------------------------------
testdb10
 
SQL>

可以看到,遠(yuǎn)程表有27個(gè)字段,目前還只是在前20個(gè)字段建立了索引,且第一個(gè)字段是主鍵。本地表,有6個(gè)字段,6個(gè)字段都建索引。

(二)第一輪測(cè)試,遠(yuǎn)程表上有20個(gè)索引。

測(cè)試場(chǎng)景1:

在遠(yuǎn)程表20索引的情況下,本地表和遠(yuǎn)程表關(guān)聯(lián),用本地表的第一個(gè)字段關(guān)聯(lián)遠(yuǎn)程表的第一個(gè)字段:

select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25
from t_local l, t_remote@dblink_remote r
where l.col01=r.col01
;
select * from table( dbms_xplan.display_cursor(null, null, 'typical LAST') );
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 04schqc3d9rgm, child number 0
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col01=r.col01
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 53 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 53 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  1 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL01","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL01"
  (accessing 'DBLINK_REMOTE' )
 
23 rows selected.
SQL> 
-- 我們這里注意一下,WHERE :1="COL01"的存在,正是因?yàn)檫@個(gè)條件,所以在遠(yuǎn)程是走了主鍵而不是全表掃。我們把這個(gè)語(yǔ)句帶入到遠(yuǎn)程執(zhí)行。
遠(yuǎn)程:
SQL> explain plan for
 2 SELECT "COL01","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL01";
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
Plan hash value: 829680338
-----------------------------------------------------------------------------------------------
| Id | Operation     | Name   | Rows | Bytes | Cost (%CPU)| Time  |
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT   |     |  1 | 63 |  2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_REMOTE  |  1 | 63 |  2 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN   | T_REMOTE_I01_PK |  1 |  |  1 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
---------------------------------------------------
 2 - access("COL01"=TO_NUMBER(:1))
14 rows selected.

我們可以看到,對(duì)于遠(yuǎn)程表的執(zhí)行計(jì)劃,這是走主鍵的。

測(cè)試場(chǎng)景2:

在遠(yuǎn)程表20索引的情況下,本地表和遠(yuǎn)程表關(guān)聯(lián),用本地表的第一個(gè)字段關(guān)聯(lián)遠(yuǎn)程表的第20個(gè)字段:

select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25
from t_local l, t_remote@dblink_remote r
where l.col01=r.col20
;
select * from table( dbms_xplan.display_cursor(null, null, 'typical LAST') );
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 5rwtbwcnv0tsm, child number 0
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col01=r.col20
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20"
  (accessing 'DBLINK_REMOTE' )
 
23 rows selected.
SQL> 
遠(yuǎn)程:
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
Plan hash value: 3993494813
----------------------------------------------------------------------------------------------------
| Id | Operation       | Name   | Rows | Bytes | Cost (%CPU)| Time  |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT     |    |  1 | 63 |  2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T_REMOTE  |  1 | 63 |  2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN     | T_REMOTE_I20 |  1 |  |  1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
---------------------------------------------------
 2 - access("COL20"=TO_NUMBER(:1))
14 rows selected.
SQL>

我們可以看到,對(duì)于遠(yuǎn)程表的執(zhí)行計(jì)劃,這是走索引范圍掃描的。

測(cè)試場(chǎng)景3:

在遠(yuǎn)程表20索引的情況下,本地表和遠(yuǎn)程表關(guān)聯(lián),用本地表的第2個(gè)字段關(guān)聯(lián)遠(yuǎn)程表的第2個(gè)字段:

select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25
from t_local l, t_remote@dblink_remote r
where l.col02=r.col02
;
select * from table( dbms_xplan.display_cursor(null, null, 'typical LAST') );
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 81ctrx5huhfvq, child number 0
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col02=r.col02
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL02","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL02"
  (accessing 'DBLINK_REMOTE' )
 
23 rows selected.
SQL> 
遠(yuǎn)程:
SQL> explain plan for 
 2 SELECT "COL02","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL02";
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
Plan hash value: 2505594687
----------------------------------------------------------------------------------------------------
| Id | Operation       | Name   | Rows | Bytes | Cost (%CPU)| Time  |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT     |    |  1 | 63 |  2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T_REMOTE  |  1 | 63 |  2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN     | T_REMOTE_I02 |  1 |  |  1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
---------------------------------------------------
 2 - access("COL02"=TO_NUMBER(:1))
14 rows selected.
SQL>

我們可以看到,對(duì)于遠(yuǎn)程表的執(zhí)行計(jì)劃,這是走索引范圍掃描的。

測(cè)試場(chǎng)景4:

在遠(yuǎn)程表20索引的情況下,本地表和遠(yuǎn)程表關(guān)聯(lián),用本地表的第2個(gè)字段關(guān)聯(lián)遠(yuǎn)程表的第20個(gè)字段:

select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25
from t_local l, t_remote@dblink_remote r
where l.col02=r.col20
;
select * from table( dbms_xplan.display_cursor(null, null, 'typical LAST') );
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 407pxjh9mgbry, child number 0
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col02=r.col20
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20"
  (accessing 'DBLINK_REMOTE' )
23 rows selected.
SQL> 
遠(yuǎn)程:
SQL> explain plan for
 2 SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20";
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
Plan hash value: 3993494813
----------------------------------------------------------------------------------------------------
| Id | Operation       | Name   | Rows | Bytes | Cost (%CPU)| Time  |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT     |    |  1 | 63 |  2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T_REMOTE  |  1 | 63 |  2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN     | T_REMOTE_I20 |  1 |  |  1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
---------------------------------------------------
 2 - access("COL20"=TO_NUMBER(:1))
14 rows selected.
SQL>

我們可以看到,對(duì)于遠(yuǎn)程表的執(zhí)行計(jì)劃,這是走索引范圍掃描的。

(三)建立第21個(gè)索引:

create index t_remote_i21 on t_remote (col21);
exec dbms_stats.gather_table_stats(user,'T_REMOTE');

(四)遠(yuǎn)程表上現(xiàn)在有21個(gè)索引,重復(fù)上面4個(gè)測(cè)試:

測(cè)試場(chǎng)景1:

PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 04schqc3d9rgm, child number 1
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col01=r.col01
Plan hash value: 830255788
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 156 (100)|   |  |  |
|* 1 | HASH JOIN   |   | 50 | 6300 | 156 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE | 10000 | 644K| 153 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
 1 - access("L"."COL01"="R"."COL01")
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL01","COL25","COL26","COL27" FROM "T_REMOTE" "R" (accessing
  'DBLINK_REMOTE' )
 
28 rows selected.
SQL>
--我們看到,這里已經(jīng)沒(méi)有了之前的 WHERE :1="COL01",即使不帶入到遠(yuǎn)程看執(zhí)行計(jì)劃,我們也可以猜到它是全表掃。
遠(yuǎn)程:
SQL> explain plan for
 2 SELECT "COL01","COL25","COL26","COL27" FROM "T_REMOTE" "R";
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
Plan hash value: 4187688566
------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   | 10000 | 615K| 238 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T_REMOTE | 10000 | 615K| 238 (0)| 00:00:01 |
------------------------------------------------------------------------------
8 rows selected.
SQL>

我們可以看到,對(duì)于遠(yuǎn)程表的執(zhí)行計(jì)劃,如果關(guān)聯(lián)條件是遠(yuǎn)程表的第一個(gè)字段,第一個(gè)字段上的索引是被忽略的,執(zhí)行計(jì)劃是選擇全表掃描的。

測(cè)試場(chǎng)景2:

PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 5rwtbwcnv0tsm, child number 1
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col01=r.col20
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20"
  (accessing 'DBLINK_REMOTE' )
 
23 rows selected.
SQL> 
遠(yuǎn)程:
SQL> explain plan for
 2 SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20";
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
Plan hash value: 3993494813
----------------------------------------------------------------------------------------------------
| Id | Operation       | Name   | Rows | Bytes | Cost (%CPU)| Time  |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT     |    |  1 | 63 |  2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T_REMOTE  |  1 | 63 |  2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN     | T_REMOTE_I20 |  1 |  |  1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
---------------------------------------------------
 2 - access("COL20"=TO_NUMBER(:1))
14 rows selected.
SQL>

我們可以看到,對(duì)于遠(yuǎn)程表的執(zhí)行計(jì)劃,如果關(guān)聯(lián)條件是遠(yuǎn)程表的第20個(gè)字段,這第20個(gè)字段上的索引是沒(méi)有被忽略的,執(zhí)行計(jì)劃是走索引。

測(cè)試場(chǎng)景3:

PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 81ctrx5huhfvq, child number 1
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col02=r.col02
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL02","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL02"
  (accessing 'DBLINK_REMOTE' )
 
23 rows selected.
SQL> 
遠(yuǎn)程:
SQL> explain plan for
 2 SELECT "COL02","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL02";
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
Plan hash value: 2505594687
----------------------------------------------------------------------------------------------------
| Id | Operation       | Name   | Rows | Bytes | Cost (%CPU)| Time  |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT     |    |  1 | 63 |  2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T_REMOTE  |  1 | 63 |  2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN     | T_REMOTE_I02 |  1 |  |  1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
---------------------------------------------------
 2 - access("COL02"=TO_NUMBER(:1))
14 rows selected.
SQL>

我們可以看到,對(duì)于遠(yuǎn)程表的執(zhí)行計(jì)劃,如果關(guān)聯(lián)條件是遠(yuǎn)程表的第2個(gè)字段,這第2個(gè)字段上的索引是沒(méi)有被忽略的,執(zhí)行計(jì)劃是走索引。

測(cè)試場(chǎng)景4:

PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 407pxjh9mgbry, child number 1
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col02=r.col20
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20"
  (accessing 'DBLINK_REMOTE' )
 
23 rows selected.
SQL> 
遠(yuǎn)程:
SQL> explain plan for
 2 SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20";
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
Plan hash value: 3993494813
----------------------------------------------------------------------------------------------------
| Id | Operation       | Name   | Rows | Bytes | Cost (%CPU)| Time  |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT     |    |  1 | 63 |  2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T_REMOTE  |  1 | 63 |  2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN     | T_REMOTE_I20 |  1 |  |  1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------
---------------------------------------------------
 2 - access("COL20"=TO_NUMBER(:1))
14 rows selected.
SQL>

我們可以看到,對(duì)于遠(yuǎn)程表的執(zhí)行計(jì)劃,如果關(guān)聯(lián)條件是遠(yuǎn)程表的第20個(gè)字段,這第20個(gè)字段上的索引是沒(méi)有被忽略的,執(zhí)行計(jì)劃是走索引。

我們目前可以總結(jié)到,當(dāng)遠(yuǎn)程表第21個(gè)索引建立的時(shí)候,通過(guò)dblink關(guān)聯(lián)本地表和遠(yuǎn)程表,如果關(guān)聯(lián)條件是遠(yuǎn)程表的第1個(gè)建立的索引的字段,那么這個(gè)索引將被忽略,從而走全表掃描。如果關(guān)聯(lián)條件是遠(yuǎn)程表的第2個(gè)建立索引的字段,則不受影響。

似乎是有效索引的窗口是20個(gè),當(dāng)新建第21個(gè),那么第1個(gè)就被無(wú)視了。

(五)建立第22個(gè)索引,我們?cè)趤?lái)看看上述猜測(cè)是否符合。

create index t_remote_i22 on t_remote (col22);
exec dbms_stats.gather_table_stats(user,'T_REMOTE');

(六),目前遠(yuǎn)程表有22個(gè)索引,重復(fù)上面4個(gè)測(cè)試:

測(cè)試場(chǎng)景1:

PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 04schqc3d9rgm, child number 2
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col01=r.col01
Plan hash value: 830255788
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 156 (100)|   |  |  |
|* 1 | HASH JOIN   |   | 50 | 6300 | 156 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE | 10000 | 644K| 153 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
 1 - access("L"."COL01"="R"."COL01")
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL01","COL25","COL26","COL27" FROM "T_REMOTE" "R" (accessing
  'DBLINK_REMOTE' )
 
28 rows selected.
SQL>

測(cè)試場(chǎng)景2:

PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 5rwtbwcnv0tsm, child number 2
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col01=r.col20
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20"
  (accessing 'DBLINK_REMOTE' )
23 rows selected.
SQL>

測(cè)試場(chǎng)景3:

PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 81ctrx5huhfvq, child number 2
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col02=r.col02
Plan hash value: 830255788
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 156 (100)|   |  |  |
|* 1 | HASH JOIN   |   | 50 | 6300 | 156 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE | 10000 | 644K| 153 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
 1 - access("L"."COL02"="R"."COL02")
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL02","COL25","COL26","COL27" FROM "T_REMOTE" "R" (accessing
  'DBLINK_REMOTE' )
 
28 rows selected.
SQL>

測(cè)試場(chǎng)景4:

PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 407pxjh9mgbry, child number 2
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col02=r.col20
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20"
  (accessing 'DBLINK_REMOTE' )
23 rows selected.
SQL>

上述的測(cè)試,其實(shí)是可以驗(yàn)證我們的猜測(cè)的。oracle對(duì)于通過(guò)dblink關(guān)聯(lián)訪問(wèn)遠(yuǎn)程表,只是會(huì)意識(shí)到最近創(chuàng)建的20個(gè)索引的字段。這個(gè)意識(shí)到索引的窗口是20個(gè),一旦建立了一個(gè)新索引,那么最舊的一個(gè)索引會(huì)被無(wú)視。

(七)我們嘗試rebuild索引,看看有沒(méi)有效果:

rebuild第2個(gè)索引

alter index t_remote_i02 rebuild;
exec dbms_stats.gather_table_stats(user,'T_REMOTE');

(八)在第2個(gè)索引rebuild之后,重復(fù)上面4個(gè)測(cè)試:

--測(cè)試場(chǎng)景1:
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 04schqc3d9rgm, child number 0
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col01=r.col01
Plan hash value: 830255788
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 156 (100)|   |  |  |
|* 1 | HASH JOIN   |   | 50 | 6300 | 156 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE | 10000 | 644K| 153 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
 1 - access("L"."COL01"="R"."COL01")
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL01","COL25","COL26","COL27" FROM "T_REMOTE" "R" (accessing
  'DBLINK_REMOTE' )
28 rows selected.
SQL> 
--測(cè)試場(chǎng)景2:
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 5rwtbwcnv0tsm, child number 0
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col01=r.col20
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20"
  (accessing 'DBLINK_REMOTE' )
23 rows selected.
SQL> 
--測(cè)試場(chǎng)景3:
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 81ctrx5huhfvq, child number 0
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col02=r.col02
Plan hash value: 830255788
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 156 (100)|   |  |  |
|* 1 | HASH JOIN   |   | 50 | 6300 | 156 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE | 10000 | 644K| 153 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
 1 - access("L"."COL02"="R"."COL02")
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL02","COL25","COL26","COL27" FROM "T_REMOTE" "R" (accessing
  'DBLINK_REMOTE' )
28 rows selected.
SQL>
--測(cè)試場(chǎng)景4:
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 407pxjh9mgbry, child number 0
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col02=r.col20
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20"
  (accessing 'DBLINK_REMOTE' )
23 rows selected.
SQL>

所以我們看到,索引rebuild,是不能起到重新“喚醒”索引的作用。

(九)我們嘗試 drop and recreate 第2個(gè)索引。

drop index t_remote_i02;
create index t_remote_i02 on t_remote (col02);
 
exec dbms_stats.gather_table_stats(user,'T_REMOTE');

(十)重復(fù)上面的測(cè)試3和測(cè)試4:

測(cè)試3:
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 81ctrx5huhfvq, child number 1
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col02=r.col02
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL02","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL02"
  (accessing 'DBLINK_REMOTE' )
23 rows selected.
SQL>
測(cè)試4:
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID 407pxjh9mgbry, child number 1
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col02=r.col20
Plan hash value: 631452043
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 103 (100)|   |  |  |
| 1 | NESTED LOOPS  |   | 50 | 6300 | 103 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE |  1 | 66 |  2 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL20","COL25","COL26","COL27" FROM "T_REMOTE" "R" WHERE :1="COL20"
  (accessing 'DBLINK_REMOTE' )
23 rows selected.
SQL> 
此時(shí),其實(shí)我們可以預(yù)測(cè),遠(yuǎn)程表此時(shí)col03上的索引是用不到的,我們來(lái)測(cè)試驗(yàn)證一下:
測(cè)試5:
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------
SQL_ID bhkczcfrhvsuw, child number 0
-------------------------------------
select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25 from t_local l,
t_remote@dblink_remote r where l.col03=r.col03
Plan hash value: 830255788
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   |  |  | 157 (100)|   |  |  |
|* 1 | HASH JOIN   |   | 500K| 89M| 157 (1)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 5400 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE | 10000 | 781K| 153 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
 1 - access("L"."COL03"="R"."COL03")
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL03","COL25","COL26","COL27" FROM "T_REMOTE" "R" (accessing
  'DBLINK_REMOTE' )
28 rows selected.
SQL> 

我們可以看到,通過(guò)drop之后再重建,是可以“喚醒”第二個(gè)索引的。這也證明了我們20個(gè)索引識(shí)別的移動(dòng)窗口,是按照索引的創(chuàng)建時(shí)間來(lái)移動(dòng)的。

綜上:

1. 對(duì)于通過(guò)dblink關(guān)聯(lián)本地表和遠(yuǎn)程表,如果遠(yuǎn)程表的索引個(gè)數(shù)少于20個(gè),那么不受影響。
2. 對(duì)于通過(guò)dblink關(guān)聯(lián)本地表和遠(yuǎn)程表,如果遠(yuǎn)程表的索引個(gè)數(shù)增加到21個(gè)或以上,那么oracle在執(zhí)行遠(yuǎn)程操作的時(shí)候,將忽略最早創(chuàng)建的那個(gè)索引,但是會(huì)以20個(gè)為窗口移動(dòng),最新建立的索引會(huì)被意識(shí)到。此時(shí)如果查詢(xún)的關(guān)聯(lián)條件中,使用到最早創(chuàng)建的那個(gè)索引的字段,由于忽略了索引,會(huì)走全表掃描。
3. 要“喚醒”對(duì)原來(lái)索引的意識(shí),rebuild索引無(wú)效,需要drop create索引。
4. 在本地表數(shù)據(jù)量比較少,遠(yuǎn)程表的數(shù)據(jù)量很大,而索引數(shù)量超過(guò)20個(gè),且關(guān)聯(lián)條件的字段時(shí)最早索引的情況下,可以考慮使用DRIVING_SITE的hint,將本地表的數(shù)據(jù)全量到遠(yuǎn)程中,此時(shí)遠(yuǎn)程的關(guān)聯(lián)查詢(xún)可以意識(shí)到那個(gè)索引??梢?jiàn)文末的例子。是否使用hint,需要評(píng)估本地表數(shù)據(jù)全量推送到遠(yuǎn)程的成本,和遠(yuǎn)程表使用全表掃的成本。

附:在22個(gè)索引的情況下,嘗試采用DRIVING_SITE的hint:

SQL> select l.col06,l.col05,l.col04,r.col27, r.col26,r.col25
 2 from t_local l, t_remote@dblink_remote r
 3 where l.col02=r.col02
 4 ;
50 rows selected.
Elapsed: 00:00:00.03
Execution Plan
----------------------------------------------------------
Plan hash value: 830255788
-----------------------------------------------------------------------------------------------
| Id | Operation   | Name  | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |   | 50 | 6300 | 156 (0)| 00:00:01 |  |  |
|* 1 | HASH JOIN   |   | 50 | 6300 | 156 (0)| 00:00:01 |  |  |
| 2 | TABLE ACCESS FULL| T_LOCAL | 50 | 3000 |  3 (0)| 00:00:01 |  |  |
| 3 | REMOTE   | T_REMOTE | 10000 | 644K| 153 (0)| 00:00:01 | DBLIN~ | R->S |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
 1 - access("L"."COL02"="R"."COL02")
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL02","COL25","COL26","COL27" FROM "T_REMOTE" "R" (accessing
  'DBLINK_REMOTE' )
Statistics
----------------------------------------------------------
  151 recursive calls
   0 db block gets
  246 consistent gets
   26 physical reads
   0 redo size
  2539 bytes sent via SQL*Net to client
  641 bytes received via SQL*Net from client
   5 SQL*Net roundtrips to/from client
   10 sorts (memory)
   0 sorts (disk)
   50 rows processed
SQL>
--可以看到遠(yuǎn)程表示走全表掃。
SQL> select /*+DRIVING_SITE(r)*/ l.col06,l.col05,l.col04,r.col27, r.col26,r.col25
 2 from t_local l, t_remote@dblink_remote r
 3 where l.col02=r.col02
 4 ;
50 rows selected.
Elapsed: 00:00:00.03
Execution Plan
----------------------------------------------------------
Plan hash value: 1716516160
-------------------------------------------------------------------------------------------------------------
| Id | Operation     | Name   | Rows | Bytes | Cost (%CPU)| Time  | Inst |IN-OUT|
-------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT REMOTE  |    | 50 | 6450 | 103 (0)| 00:00:01 |  |  |
| 1 | NESTED LOOPS    |    | 50 | 6450 | 103 (0)| 00:00:01 |  |  |
| 2 | NESTED LOOPS    |    | 50 | 6450 | 103 (0)| 00:00:01 |  |  |
| 3 | REMOTE     | T_LOCAL  | 50 | 3300 |  3 (0)| 00:00:01 |  ! | R->S |
|* 4 | INDEX RANGE SCAN   | T_REMOTE_I02 |  1 |  |  1 (0)| 00:00:01 | ORA12C |  |
| 5 | TABLE ACCESS BY INDEX ROWID| T_REMOTE  |  1 | 63 |  2 (0)| 00:00:01 | ORA12C |  |
-------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
 4 - access("A2"."COL02"="A1"."COL02")
Remote SQL Information (identified by operation id):
----------------------------------------------------
 3 - SELECT "COL02","COL04","COL05","COL06" FROM "T_LOCAL" "A2" (accessing '!' )
Note
-----
 - fully remote statement
 - this is an adaptive plan
Statistics
----------------------------------------------------------
  137 recursive calls
   0 db block gets
  213 consistent gets
   25 physical reads
   0 redo size
  2940 bytes sent via SQL*Net to client
  641 bytes received via SQL*Net from client
   5 SQL*Net roundtrips to/from client
   10 sorts (memory)
   0 sorts (disk)
   50 rows processed
SQL>
--可以看到本地表是走全表掃,但是遠(yuǎn)程表使用了第2個(gè)字段的索引。

總結(jié)

以上就是本文關(guān)于遠(yuǎn)程數(shù)據(jù)庫(kù)的表超過(guò)20個(gè)索引的影響詳細(xì)解析的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:SQL提取數(shù)據(jù)庫(kù)表名及字段名等信息代碼示例、MySQL數(shù)據(jù)庫(kù)表分區(qū)注意事項(xiàng)大全【推薦】等,有什么問(wèn)題可以直接留言,小編會(huì)及時(shí)回復(fù)大家的。感謝朋友們對(duì)本站的支持!

您可能感興趣的文章:
  • Oracle數(shù)據(jù)庫(kù)中建立索引的基本方法講解
  • 什么是數(shù)據(jù)庫(kù)索引 有哪些類(lèi)型和特點(diǎn)
  • mysql數(shù)據(jù)庫(kù)索引損壞及修復(fù)經(jīng)驗(yàn)分享
  • pymongo為mongodb數(shù)據(jù)庫(kù)添加索引的方法
  • oracle數(shù)據(jù)庫(kù)索引失效

標(biāo)簽:江蘇 景德鎮(zhèn) 威海 那曲 瀘州 荊門(mén) 淮安 柳州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《遠(yuǎn)程數(shù)據(jù)庫(kù)的表超過(guò)20個(gè)索引的影響詳細(xì)解析》,本文關(guān)鍵詞  遠(yuǎn)程,數(shù)據(jù)庫(kù),的,表,超過(guò),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《遠(yuǎn)程數(shù)據(jù)庫(kù)的表超過(guò)20個(gè)索引的影響詳細(xì)解析》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于遠(yuǎn)程數(shù)據(jù)庫(kù)的表超過(guò)20個(gè)索引的影響詳細(xì)解析的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    日韩欧美亚洲国产| 免费黄频在线观看| 1000精品久久久久久久久| 国产精品久久久久久久久久久久久久久久久久| 91高清在线免费观看| 91久久国语露脸精品国产高跟| 亚洲国产精品成人一区二区在线| 精品一区二区三区中文字幕视频| 欧美综合久久久| 精品久久久一区| 青青草国产一区二区三区| 亚洲成人国产| 日本一区二区三区四区在线视频| 91亚洲精品国偷拍自产在线观看| 亚洲不卡系列| 日韩欧美在线一区二区三区| 综合国产第二页| 成人福利免费在线观看| 欧美激情黑人| 成人黄色av网址| 99国产精品免费视频观看| 国产又粗又硬视频| 香蕉久久一区| 亚洲免费一区| 黄色视屏免费在线观看| 成人一区二区三区视频在线观看| 成人免费无遮挡无码黄漫视频| 免费在线视频你懂得| 日韩黄色动漫| 欧美女人天堂| 国内精品视频在线观看| 韩国三级hd两男一女| 99在线精品视频| 日本精品视频一区二区三区| 九色porny视频在线观看| 久草视频观看| 欧美亚洲另类色图| 亚洲国产日韩一区无码精品久久久| 国产一线二线三线在线观看| 午夜久久一区| 97精品国产91久久久久久| 成 年 人 黄 色 大 片大 全| 手机av在线看| 精品写真视频在线观看| 欧美一区二区视频在线观看2022| 亚洲人成免费电影| 色婷婷在线播放| 国产精选第一页| 精品99一区二区| 久久精品国产精品亚洲精品色| 亚洲国产精品久久91精品| 亚洲伊人色欲综合网| 日韩欧美一区二区三区不卡视频| 在线无限看免费粉色视频| 久久久免费高清视频| 久久久久日韩精品久久久男男| 亚洲欧美一级二级三级| 欧美猛男同性videos| 成人一对一视频| 色视频网站在线观看| 精品国内亚洲在观看18黄| 日韩精选在线| 涩涩涩视频在线观看| 色久视频在线播放| 免费h网站在线观看| 午夜天堂精品久久久久| 国产刺激高潮av| 午夜一级久久| av亚洲精华国产精华| 人禽交欧美网站| 免费黄色网址网站| 国产日产欧美视频| 波多野结衣不卡视频| 亚洲精品mp4| 一区二区三区四区视频精品免费| 成人情视频高清免费观看电影| 亚洲精品国产suv一区88| 久久国产毛片| 影音先锋中文字幕在线视频| 国产1区2区3区在线| 国产精品欧美久久久久一区二区| 久久久久久久久免费看无码| 天天操天天操天天操| 国产伦理在线观看| 亚洲视频成人| 东方aⅴ免费观看久久av| 国产成人在线一区| 日本精品一区在线| 亚洲欧美电影一区二区| 日韩在线激情视频| 成人激情文学综合网| 一个色综合网| 日本三级黄色大片| 欧美精品一区二区三区国产精品| 91se在线观看| 三级成人在线视频| 亚洲婷婷伊人| 综合av第一页| 成人黄色小视频| 亚洲综合精品伊人久久| 久久久久久久高潮| 91精品久久久久久9s密挑| 99精品在线| 国产精品白丝在线| 国产精品久久久久一区二区| 黄色国产小视频| 欧美精品第1页| 久久本道综合色狠狠五月| 免费在线观看的毛片| 天堂网在线.www天堂在线视频| 免费一级欧美片在线观看| 成人手机在线电影| 国产欧美日韩中文字幕在线| 亚洲综合中文字幕在线观看| 97视频免费在线观看| www.中文字幕在线观看| 精品国产无码在线| 亚洲精选成人| 日韩欧美国产wwwww| 午夜激情福利电影| 97超碰资源站| 不卡的av电影在线观看| 99热这里只有精品9| 亚洲综合在线免费| 午夜在线视频观看日韩17c| 在线观看国产一区二区三区| 免费观看欧美成人禁片| 日本色护士高潮视频在线观看| 蜜桃视频成人在线观看| 在线播放成人| 精品国产凹凸成av人网站| 91福利在线播放| 国产 日韩 欧美 综合 一区| 一区二区三区免费观看视频| 亚洲欧美一区二区三区不卡| 国产精品卡一卡二| 亚洲一区精品电影| 大胆欧美熟妇xx| 网友自拍区视频精品| 免费h视频在线观看| 亚洲精品资源在线| 高清国产mv在线观看| 亚洲国产日韩一区无码精品久久久| 国内在线高清免费视频| 欧美又粗又长又爽做受| 韩国成人二区| 亚洲天堂网av在线| 免费成人深夜夜行视频| 天堂网在线免费观看| 欧美性xxxx极品高清hd直播| 66精品视频在线观看| 亚洲成年人av| 精品久久美女| 欧美一区2区视频在线观看| 香蕉视频在线播放| 日韩久久精品视频| 日本在线视频中文字幕| 国产情侣在线视频| 美女福利一区二区| 综合久久2019| 国产精品白浆| www.av视频在线观看| 又紧又大又爽精品一区二区| 欧美人与禽zoz0善交| 精品久久免费| 天堂av中文在线| 欧美久久一二区| 性农村xxxxx小树林| 欧美一二区在线观看| 2020国产精品视频| 伊人色综合久久久天天蜜桃| 中文字幕成人在线观看| 成人午夜视频一区二区播放| 久久精品午夜福利| 欧美多人爱爱视频网站| 精品少妇v888av| 在线国产成人影院| 久久精品99国产精品酒店日本| 蜜桃视频一区二区在线观看| 国产三级做爰高清在线| 成人精品一二三区| freesex欧美| 国产一区二区h| 成人精品电影在线| 香港三级韩国三级日本三级| 无码人妻精品一区二区三| 国产精品亚洲综合一区在线观看| 国产精品自拍偷拍| 虎白女粉嫩尤物福利视频| www.蜜臀av| 欧美一级片在线播放| 欧美日韩国产精品成人| 五月天免费网站| 成人福利免费在线观看| 亚洲色图激情小说| 人妻熟女一二三区夜夜爱| 成人18网址在线观看| 人妻少妇被粗大爽9797pw| 国产一区二区免费电影| 五月天婷婷久久| 性欧美激情精品| 成人av蜜桃| 91极品尤物在线播放国产| 麻豆视频在线免费观看| 污视频在线免费观看| 18一19gay欧美视频网站| 欧美人与牲动交xxxxbbbb| 欧美国产1区2区| 99国产精品一区二区三区| 欧美videosex性极品hd| 亚洲午夜伦理| 久久97精品| 成人一区二区三区视频| 在线播放一区二区精品视频| 日韩一卡二卡三卡国产欧美| 国产目拍亚洲精品99久久精品| 成人在线国产| 波多野结衣中文字幕久久| 午夜欧美在线一二页| 亚洲欧美综合另类在线卡通| 精品网站在线| 九九热这里只有精品免费看| 国内精品国产成人国产三级| 可以直接看的无码av| 欧美—级在线免费片| 嗯~啊~轻一点视频日本在线观看| 公肉吊粗大爽色翁浪妇视频| 91在线你懂的| 午夜激情在线观看| 精品国产乱码久久久久久樱花| 欧美另类激情| 国模私拍一区二区| 色诱亚洲精品久久久久久| 精品国产乱码久久久久久牛牛| missav|免费高清av在线看| 国产主播性色av福利精品一区| 黄色在线视频网| 亚洲一区二区三区四区中文字幕| 欧美激情自拍偷拍| 欧美日韩欧美一区二区| 99精品在线免费在线观看| 国产九色porn网址| 欧美日韩激情一区二区| 韩国亚洲精品| 国产视频一二三四区| 国产精品美女久久久久高潮| 影音先锋中文字幕在线播放| 国产三区视频在线观看| 国产精品一区二区欧美黑人喷潮水| 国产精品色视频| 日韩一区精品| 国产福利三区| 内射无码专区久久亚洲| 精品久久国产一区| 久久久久久无码午夜精品直播| 97视频久久久| 国产又粗又猛又爽又黄的| 免费日韩精品中文字幕视频在线| 校园春色综合网| 亚洲精品手机在线观看| 成人国产电影网| 日韩精品一区二区三区第95| 精品999在线| 欧美午夜久久久| 蜜桃专区在线| 伊人国产精品视频| 欧美精品久久久久性色| 国产中文在线| 精品久久久三级| freehdxxxx护士| www.天堂乱色| 欧美在线影院| 欧美一激情一区二区三区| 一本色道久久综合熟妇| 在线观看精品一区| 黄色国产精品视频| 在线观看免费播放网址成人| 无码国产色欲xxxx视频| 99视频在线视频| 成人看的视频| 欧美夫妻性生活视频| 国产88在线观看入口| 国产麻豆精品入口在线观看| 免费高清在线观看免费| 午夜久久久久久久久久| 国产精品久久久久影院亚瑟| 欧美视频第三页| 精品国产一区二区三区无码| 国产精品综合色区在线观看| wwwav91com| 美女裸体自慰在线观看| 国精产品一区二区三区有限公司| 亚洲欧美中文字幕在线一区| 在线视频日韩| 一本色道久久88亚洲综合88| 韩国av免费在线| 精品视频成人| 亚洲综合激情网| 欧美老**bbbb毛片| 国模精品娜娜一二三区| 亚洲精品久久久北条麻妃| 一本一道波多野毛片中文在线| 成年女人毛片| 男女毛片免费视频看| 欧美中文字幕在线观看| aa国产精品| 蜜臀av性久久久久av蜜臀妖精| 国产亚洲天堂网| 凹凸成人精品亚洲精品密奴| 五月激情四射婷婷| 日本一本草久p| 亚洲国产精品二十页| 精品国产欧美一区二区五十路| 亚洲第一av| 91精品一区国产高清在线gif| 亚洲国产欧美91| 国产高清一区二区三区视频| 免费看美剧网站| 永久免费不卡在线观看黄网站| 91国内精品野花午夜精品| 亚洲精品自产拍在线观看| 中文字幕第三区| 精品麻豆剧传媒av国产九九九| 欧美一区二区三区喷汁尤物| 丝袜一区二区三区| 亚洲色图 欧美| 91国内精品在线视频| 97人妻人人澡人人爽人人精品|