在資料分佈嚴重不均的列上使用繫結變數容易錯過更好的執行計劃
SQL> desc tt
名稱 是否為空? 型別
----------------------------------------- -------- ----------------------------
OWNER VARCHAR2(30)
OBJECT_NAME VARCHAR2(128)
SUBOBJECT_NAME VARCHAR2(30)
OBJECT_ID NUMBER
DATA_OBJECT_ID NUMBER
OBJECT_TYPE VARCHAR2(19)
CREATED DATE
LAST_DDL_TIME DATE
TIMESTAMP VARCHAR2(19)
STATUS VARCHAR2(7)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
SQL> select count(*) from tt;
COUNT(*)
----------
46080
SQL> update tt set object_id=999 where object_id>5;
已更新46064行。
SQL> commit;
提交完成。
SQL> create index idx_tt on tt(object_id) tablespace users;
索引已建立。
SQL> set autotrace traceonly
SQL> variable i number
SQL> exec :i := 2;
PL/SQL 過程已成功完成。
SQL> set linesize 200
SQL> select * from tt where object_id=:i;
執行計劃
----------------------------------------------------------
Plan hash value: 6977672
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 548 | 96996 | 22 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TT | 548 | 96996 | 22 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_TT | 219 | | 19 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=TO_NUMBER(:I))
Note
-----
- dynamic sampling used for this statement
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
7 consistent gets
0 physical reads
0 redo size
1472 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
4 rows processed
SQL> exec :i := 999;
PL/SQL 過程已成功完成。
SQL> select * from tt where object_id=:i;
已選擇46064行。
執行計劃
----------------------------------------------------------
Plan hash value: 6977672
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 548 | 96996 | 22 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TT | 548 | 96996 | 22 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_TT | 219 | | 19 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=TO_NUMBER(:I))
Note
-----
- dynamic sampling used for this statement
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
6774 consistent gets
98 physical reads
0 redo size
4572424 bytes sent via SQL*Net to client
34155 bytes received via SQL*Net from client
3072 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
46064 rows processed
SQL> select * from tt where object_id=2;
執行計劃
----------------------------------------------------------
Plan hash value: 6977672
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 708 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TT | 4 | 708 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_TT | 4 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=2)
Note
-----
- dynamic sampling used for this statement
統計資訊
----------------------------------------------------------
9 recursive calls
0 db block gets
89 consistent gets
0 physical reads
0 redo size
1472 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
4 rows processed
SQL> select * from tt where object_id=999;
已選擇46064行。
執行計劃
----------------------------------------------------------
Plan hash value: 264906180
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 54823 | 9476K| 253 (1)| 00:00:04 |
|* 1 | TABLE ACCESS FULL| TT | 54823 | 9476K| 253 (1)| 00:00:04 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"=999)
Note
-----
- dynamic sampling used for this statement
統計資訊
----------------------------------------------------------
9 recursive calls
0 db block gets
4248 consistent gets
0 physical reads
0 redo size
1920772 bytes sent via SQL*Net to client
34155 bytes received via SQL*Net from client
3072 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
46064 rows processed
SQL>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/19602/viewspace-1056780/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 程式中使用繫結變數,執行計劃不正確變數
- sqm執行計劃的繫結
- 執行計劃繫結
- 使用spm繫結執行計劃來線上優化資料庫優化資料庫
- 【CURSOR】Oracle繫結變數、執行計劃對遊標的影響Oracle變數
- 11.2 繫結變數執行計劃怎麼這樣?求助!變數
- Event 10053 執行計劃 繫結變數 Bind peeking變數
- 實驗-資料分佈對執行計劃的影響.txt
- Oracle-繫結執行計劃Oracle
- 通過ERRORSTACK找出正在執行的SQL中的繫結變數值ErrorSQL變數
- 如何解決執行計劃繫結變數bind peeking重新硬解析變數
- [20231210]執行計劃與繫結變數.txt變數
- oracle對非使用繫結變數的語句去重Oracle變數
- 在oracle的plsql中為cursor使用繫結變數OracleSQL變數
- 如何更好的解讀QianBase MPP資料庫執行計劃資料庫
- 繫結變數的使用範圍變數
- 關於繫結變數的使用變數
- mongodb資料庫範圍分片資料分佈不均勻MongoDB資料庫
- sqlprofile繫結執行計劃實驗測試SQL
- 知識篇 | ORACLE 如何執行計劃繫結Oracle
- 在繫結變數下使用outline變數
- 使用hint改變執行計劃
- 使用繫結變數的一點總結!變數
- 使用字面量或者繫結變數在HANA Studio裡執行SQL語句變數SQL
- oracle10g_11g_繫結變數bind_與最優執行計劃explain planOracle變數AI
- PLSQL使用繫結變數SQL變數
- 【優化】使用繫結變數 OR 不使用繫結變數,這不是問題!優化變數
- 【SQL】在SQLPLUS中使用繫結變數的寫法SQL變數
- PostgreSQL DBA(9) - 執行計劃資料結構SQL資料結構
- 【最佳化】使用繫結變數 OR 不使用繫結變數,這不是問題!變數
- PLSQL中使用繫結變數的語法SQL變數
- 執行計劃變化的處理
- Oracle 通過註釋改變執行計劃Oracle
- 繫結變數分級導致共享池佔用過大變數
- 【YashanDB知識庫】繫結引數,同一個sql多個執行計劃的問題SQL
- MYSQL 5.6 5.7處理資料分佈不均的問題(eq_range_index_dive_limit引數)MySqlIndexMIT
- 繫結變數的測試變數
- 數以億計執行PHP的網站即將面臨嚴重的安全風險PHP網站