_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排序
- sort排序排序
- Javascript陣列排序sort方法和自定義排序方法JavaScript陣列排序
- Collections sort()排序方法排序
- 堆排序 Heap Sort排序
- Elasticsearch script sort 排序Elasticsearch排序
- 桶排序bucket sort排序
- 快速排序(Quick Sort)排序UI
- 希爾排序(Shell Sort)排序
- 快速排序 (Quick Sort)排序UI
- 氣泡排序 bubble sort排序
- Lucene 排序 Sort與SortField排序
- [Shell] Sort排序的例子排序
- golang sort.Sort () 排序演算法學習Golang排序演算法
- C++筆記— 排序函式sort() 和vector容器C++筆記排序函式
- 排序演算法-氣泡排序(Bubble Sort)排序演算法
- linux sort 多列正排序,倒排序Linux排序
- 計數排序 - Counting Sort排序
- Array.sort排序問題排序
- Collections.sort()方法,字元排序字元排序
- 插入排序(Insertion Sort)排序
- go sort.Interface 排序介面Go排序
- R排序sort、order、rank、arrange排序
- 拓撲排序 - Topological Sort排序
- [CareerCup] 3.6 Sort Stack 棧排序排序
- Sorting 排序演算法: Quick Sort 快速排序排序演算法UI
- 經典排序演算法 - 快速排序Quick sort排序演算法UI
- Python教程:sort和sorted實現排序之對比Python排序
- 【Oracle】排序與sort_area_sizeOracle排序
- 【c++】結構體sort排序C++結構體排序
- 75. Sort Colors:計數排序排序
- 《shell下sort排序命令的使用》排序
- sort按照數值大小排序排序
- C# 字典排序Array.SortC#排序
- nls_sort與漢字排序排序
- 線性時間的排序 - Decision Tree Model & Counting Sort & Radix Sort & Bucket Sort排序
- 排序演算法(3)插入排序(Insertion Sort)排序演算法
- 排序演算法之「快速排序(Quick Sort) _c++ 」排序演算法UIC++