_sort_elimination_cost_radit和sort排序
摘自ITPUB的一篇帖子http://www.itpub.net/thread-1605027-1-1.html
Oracle 9I下optimizer_mode為first_rows,而此時的一個隱含引數_sort_elimination_cost_radit為0,也就是cbo會盡量避免sort,認為sort消耗巨大,此引數可能會引起執行計劃的不合理,而在10g中該引數已經修改為1,也就是排序與不排序的成本是一樣的。
SQL> alter session set optimizer_mode=first_rows;
Session altered
SQL> create table test01 as select * from dba_objects;
Table created
SQL> insert into test01 select * from dba_objects;
49745 rows inserted
SQL> insert into test01 select * from dba_objects;
49745 rows inserted
SQL> insert into test01 select * from dba_objects;
49745 rows inserted
SQL>
SQL> insert into test01 select * from dba_objects;
49745 rows inserted
SQL> commit;
Commit complete
SQL> create index index_a on test01(object_type);
Index created
SQL> create index index_b on test01(object_id);
Index created
SQL> alter ssession set "_sort_elimination_cost_ratio"=0;
Session altered
SQL> explain plan for select * from test01 where object_type='VIEW' and object_id between 800 and 56402 order by object_id;
Explained
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 769283169
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Tim
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 19090 | 3299K| 241K (1)| 00:
|* 1 | TABLE ACCESS BY INDEX ROWID| TEST01 | 19090 | 3299K| 241K (1)| 00:
|* 2 | INDEX RANGE SCAN | INDEX_B | 251K| | 541 (2)| 00:
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_TYPE"='VIEW')
2 - access("OBJECT_ID">=800 AND "OBJECT_ID"<=56402)
filter("OBJECT_ID">=800 AND "OBJECT_ID"<=56402)
Note
-----
- dynamic sampling used for this statement
20 rows selected
其中這個object_id已經返回了表中90%的資料,選擇性很差,無論是走全表掃描還是利用object_type上的索引都會減小很多消耗,而由於設定_sort_elimination_cost_ratio=0 cbo會認為sort消耗巨大,而利用了低效率的索引
當不排序成本/排序成本>_sort_elimination_cost_ratio 執行計劃走排序反之則不走排序,也就是當設定較大的_sort_elimination_cost_ratio或者不設定時,很有可能會導致不合理的執行計劃,這也體現了oracle 10g中該引數預設為1的來由!(大多網友提到了9I升級到10G後,會頻繁引起上述錯誤的執行計劃,有點不解,應該是在9I後出現較多,而在10g後應該大量減少才是)
SQL> alter session set
2 "_sort_elimination_cost_ratio"=1;
Session altered
SQL> explain plan for select * from test01 where object_type='VIEW' and object_id between 800 and 56402 order by object_id;
Explained
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 4262596394
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 19090 | 3299K| | 1510 (2)| 00:00
| 1 | SORT ORDER BY | | 19090 | 3299K| 7848K| 1510 (2)| 00:00
|* 2 | TABLE ACCESS FULL| TEST01 | 19090 | 3299K| | 765 (3)| 00:00
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("OBJECT_TYPE"='VIEW' AND "OBJECT_ID">=800 AND
"OBJECT_ID"<=56402)
Note
-----
- dynamic sampling used for this statement
19 rows selected
[@more@]來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25362835/viewspace-1057986/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- sort排序排序
- Javascript陣列排序sort方法和自定義排序方法JavaScript陣列排序
- 堆排序 Heap Sort排序
- Elasticsearch script sort 排序Elasticsearch排序
- 快速排序 (Quick Sort)排序UI
- Collections sort()排序方法排序
- 希爾排序(Shell Sort)排序
- 計數排序 - Counting Sort排序
- 插入排序(Insertion Sort)排序
- golang sort.Sort () 排序演算法學習Golang排序演算法
- C++筆記— 排序函式sort() 和vector容器C++筆記排序函式
- Python教程:sort和sorted實現排序之對比Python排序
- Sorting 排序演算法: Quick Sort 快速排序排序演算法UI
- Array.sort排序問題排序
- go sort.Interface 排序介面Go排序
- SS241115C. 排序(sort)排序
- Collections.sort()方法,字元排序字元排序
- 排序演算法(3)插入排序(Insertion Sort)排序演算法
- 排序演算法之「歸併排序(Merge Sort)」排序演算法
- 排序演算法之「插入排序(Insertion Sort)」排序演算法
- Python 排序---sort與sorted學習Python排序
- 【c++】結構體sort排序C++結構體排序
- 【Oracle】排序與sort_area_sizeOracle排序
- 排序演算法之「快速排序(Quick Sort) _c++ 」排序演算法UIC++
- 用原生Js利用sort方法 實現圖片的正 倒排序和隨機排序JS排序隨機
- Sort排序專題(5)快速排序(QuickSort)(C++實現)排序UIC++
- List排序Collections.sort 重寫compare排序
- 【轉】堆排序Heap Sort——Java實現排序Java
- 在命令列用 sort 進行排序命令列排序
- Algorithm-sort 排序演算法 pythonGo排序演算法Python
- C++ partial_sort(部分排序)C++排序
- 排序(對於 sort 函式的使用)排序函式
- Python中用來排序的方法sort、sortedPython排序
- Arrays.sort(arr)是什麼排序排序
- java中Collections.sort排序詳解Java排序
- 簡單選擇排序(Simple Selection Sort)排序
- 快速排序演算法(Quick_Sort)排序演算法UI
- 009 Linux 檔案大小統計與排序( du於df和sort)Linux排序
- Sort排序專題(7)歸併排序(MergeSort)(C++實現)排序C++