表挪動儲存空間後,對之上的sql的執行計劃的影響的探究
以前的一個測試例子,置於此以作記錄。
資料庫版本:
SQL> SELECT * FROM (SELECT * FROM V$VERSION) WHERE ROWNUM<5;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
測試表為csdn的那個600w+的表,大家懂的...
SQL> desc csdn
Name Null? Type
----------------------------------------- -------- ----------------------------
NAME VARCHAR2(30)
PASSWD VARCHAR2(100)
EMAIL VARCHAR2(100)
SQL> select * from (select name from csdn) where rownum<3;
NAME
------------------------------
zdg
LaoZheng
------------------------------
zdg
LaoZheng
SQL> select table_name,tablespace_name from user_tables where table_name='CSDN';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
CSDN A
------------------------------ ------------------------------
CSDN A
建立測試索引
SQL> create index idxcsdn on csdn(name);
SQL> create index idxcsdn on csdn(name);
Index created.
收集並檢視執行計劃
SQL> explain plan for select name from csdn where name='zdg';
SQL> explain plan for select name from csdn where name='zdg';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 141053954
--------------------------------------------------------------------------------
Plan hash value: 141053954
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IDXCSDN | 1 | 11 | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IDXCSDN | 1 | 11 | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
---------------------------------------------------
1 - access("NAME"='zdg')
13 rows selected.
注:顯然是走的索引idxcsdn
挪動表所在表空間
SQL> alter table csdn move tablespace b;
Table altered.
再次收集並檢視執行計劃
SQL> explain plan for select name from csdn where name='zdg';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3550140955
--------------------------------------------------------------------------------
Plan hash value: 3550140955
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 6854 (1)| 00:01:23 |
|* 1 | TABLE ACCESS FULL| CSDN | 1 | 11 | 6854 (1)| 00:01:23 |
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 6854 (1)| 00:01:23 |
|* 1 | TABLE ACCESS FULL| CSDN | 1 | 11 | 6854 (1)| 00:01:23 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
---------------------------------------------------
1 - filter("NAME"='zdg')
13 rows selected.
注:顯然不走索引,而是全表掃描
再次將表挪回原來的表空間
SQL> alter table csdn move tablespace a;
SQL> alter table csdn move tablespace a;
Table altered.
再次收集並檢視執行計劃
SQL> explain plan for select name from csdn where name='zdg';
SQL> explain plan for select name from csdn where name='zdg';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3550140955
--------------------------------------------------------------------------------
Plan hash value: 3550140955
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 6854 (1)| 00:01:23 |
|* 1 | TABLE ACCESS FULL| CSDN | 1 | 11 | 6854 (1)| 00:01:23 |
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 6854 (1)| 00:01:23 |
|* 1 | TABLE ACCESS FULL| CSDN | 1 | 11 | 6854 (1)| 00:01:23 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
---------------------------------------------------
1 - filter("NAME"='zdg')
13 rows selected.
注:即使挪回原來的表空間,還是不走索引,走全表掃描
重建索引
SQL> alter index idxcsdn rebuild;
Index altered.
再次收集並檢視執行計劃
SQL> explain plan for select name from csdn where name='zdg';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 141053954
--------------------------------------------------------------------------------
Plan hash value: 141053954
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IDXCSDN | 1 | 11 | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 2 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IDXCSDN | 1 | 11 | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
---------------------------------------------------
1 - access("NAME"='zdg')
13 rows selected.
注:sql執行計劃又恢復正常!
結論:將表挪動表空間後,在表之上的sql執行計劃將發生變化,甚至是將表又挪回原來的表空間,表之上的sql的執行計劃也會發生變化。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26143577/viewspace-717975/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- cluster factor對執行計劃的影響
- 索引及排序對執行計劃的影響索引排序
- 表資料的儲存對索引的影響索引
- 透過空間佔用和執行計劃瞭解SQL Server的行儲存索引SQLServer索引
- oracle cardinality對於執行計劃的影響Oracle
- not-null約束對執行計劃的影響Null
- oracle動態sql執行table表中儲存的sqlOracleSQL
- 儲存過程中檢視sql執行計劃的方法儲存過程SQL
- Oracle優化案例-統計資訊對執行計劃的影響(十三)Oracle優化
- 實驗-資料分佈對執行計劃的影響.txt
- _complex_view_merging對執行計劃的影響View
- [DB2]表空間之DMS、自動儲存的DMS表空間DB2
- 收集統計資訊中的no_invalidate選項對執行計劃的影響
- Alter修改表結構對資料儲存的影響PP
- 時區調整對job的執行時間的影響
- 引數Optimizer_index_cost_adj 對執行計劃的影響Index
- 一條SQL語句的執行計劃變化探究SQL
- SQL的執行計劃SQL
- arraysize/TDU/SDU的設定對sql執行代價的影響SQL
- 表在表空間中的儲存情況
- 再說索引與Null值對於Hints及執行計劃的影響索引Null
- 不等號影響執行計劃的相關實驗
- 影響執行計劃之oracle sql baseline與sql profile之互動OracleSQL
- SYSAUX表空間滿對資料庫的影響以及解決措施UX資料庫
- rbo下針對表與表之間的連線執行計劃的確定原則!
- sql的執行計劃 詳解SQL
- CLUSTERING_FACTOR影響執行計劃
- try catch 對程式碼執行的效能影響
- 表的storage (MINEXTENTS 屬性對truncate後表大小的影響
- 新增欄位對SQL的影響SQL
- 【CURSOR】Oracle繫結變數、執行計劃對遊標的影響Oracle變數
- 【儲存管理】表空間概念
- sql最佳化:使用儲存提綱穩定sql執行計劃SQL
- Oracle的表空間的儲存管理與最佳化技術Oracle
- 有關執行計劃,空間釋放的另一些
- 如何檢視SQL的執行計劃SQL
- 檢視SQL的執行計劃方法SQL
- 獲取SQL執行計劃的方式:SQL