關於cursor_sharing = similar(ZT)
關於cursor_sharing = similar
摘要:本文透過簡單實驗來嘗試說明cursor_sharing=similar的含義。
[@more@]
1.1. 實驗現象
我們先看看在表沒有分析無統計資料情況下的表現
SQL> alter session set cursor_sharing = similar;
Session altered.
SQL> select name,value from v$sysstat where name like @#%parse%@#;
NAME VALUE
---------------------------------------------------------------- ----------
parse time cpu 4948
parse time elapsed 4468
parse count (total) 170148
parse count (hard) 1619 (硬分析次數)
parse count (failures) 80
SQL> select count(*) from t where object_id = 1000;
COUNT(*)
----------
0
SQL> select name,value from v$sysstat where name like @#%parse%@#;
NAME VALUE
parse time cpu 4948
parse time elapsed 4468
parse count (total) 170172
parse count (hard) 1620
parse count (failures) 80
SQL> /
NAME VALUE
---------------------------------------------------------------- ----------
parse time cpu 4948
parse time elapsed 4468
parse count (total) 170176
parse count (hard) 1620
parse count (failures) 80
SQL> select count(*) from t where object_id = 1000;
COUNT(*)
----------
0
SQL> select name,value from v$sysstat where name like @#%parse%@#;
NAME VALUE
---------------------------------------------------------------- ----------
parse time cpu 4948
parse time elapsed 4468
parse count (total) 170178
parse count (hard) 1620
parse count (failures) 80
SQL> select count(*) from t where object_id = 1001;
COUNT(*)
----------
0
SQL> select name,value from v$sysstat where name like @#%parse%@#;
NAME VALUE
---------------------------------------------------------------- ----------
parse time cpu 4948
parse time elapsed 4468
parse count (total) 170180
parse count (hard) 1620(即使object_id發生變化依然沒有硬解析)
parse count (failures) 80
我們再來看分析表和欄位資訊後的表現
SQL> analyze table t1 compute statistics for table for columns object_id;
Table analyzed.
SQL> select name,value from v$sysstat where name like @#%parse%@#;
NAME VALUE
---------------------------------------------------------------- ----------
parse time cpu 4973
parse time elapsed 4495
parse count (total) 170982
parse count (hard) 1640
parse count (failures) 80
SQL> select count(*) from t1 where object_id = 5000;
COUNT(*)
----------
0
SQL> select name,value from v$sysstat where name like @#%parse%@#;
NAME VALUE
---------------------------------------------------------------- ----------
parse time cpu 4973
parse time elapsed 4495
parse count (total) 170984
parse count (hard) 1641
parse count (failures) 80
SQL> select count(*) from t1 where object_id = 5000;
COUNT(*)
----------
0
SQL> select name,value from v$sysstat where name like @#%parse%@#;
NAME VALUE
---------------------------------------------------------------- ----------
parse time cpu 4973
parse time elapsed 4495
parse count (total) 171008
parse count (hard) 1641 (重複執行沒發生變化)
parse count (failures) 80
SQL> select count(*) from t1 where object_id = 5001;
COUNT(*)
----------
0
SQL> select name,value from v$sysstat where name like @#%parse%@#;
NAME VALUE
---------------------------------------------------------------- ----------
parse time cpu 4973
parse time elapsed 4495
parse count (total) 171010
parse count (hard) 1642 (當object_id變化的時候產生硬分析)
parse count (failures) 80
SQL>
SQL> select sql_text,child_number from v$sql where sql_text like @#select count(*) from t1 where%@#;
SQL_TEXT
------------------------------------------------------------------------------
CHILD_NUMBER
------------
select count(*) from t1 where object_id = :"SYS_B_0"
0
select count(*) from t1 where object_id = :"SYS_B_0"
1
1.2. 結論
可以看出若存在object_id的 histograms ,則每次是不同的值的時候都產生硬解析 ,若不存在 histograms,則不產生硬解析。換句話說,當表的欄位被分析過存在histograms的時候,similar 的表現和exact一樣,當表的欄位沒被分析,不存在histograms的時候,similar的表現和force一樣。這樣避免了一味地如force一樣轉換成變數形式,因為有histograms的情況下轉換成變數之後就容易產生錯誤的執行計劃,沒有利用上統計資訊。而exact呢,在沒有histograms的情況下也要分別產生硬解析,這樣的話,由於執行計劃不會受到資料分佈的影響(因為沒有統計資訊)重新解析是沒有實質意義的。而similar則綜合了兩者的優點。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/271283/viewspace-1003337/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 關於SQL Server中索引使用及維護簡介(zt)SQLServer索引
- 【Leetcode】800. Similar RGB ColorLeetCodeMILA
- AtCoder Beginner Contest 282 G - Similar PermutationMILA
- LeetCode之Leaf-Similar Trees(Kotlin)LeetCodeMILAKotlin
- [20180803]cursor_sharing = force.txt
- INSTEAD OF(zt)
- lsof(zt)
- ORACLE中Cursor_sharing引數詳解Oracle
- [20210627]cursor_sharing=force與orade by.txt
- SQLSERVER SELECT(zt)SQLServer
- V$LOCK(zt)
- EXISTS、IN、NOT EXISTS、NOT IN(zt)
- Event Reference(zt)
- oracle enqueue(zt)OracleENQ
- Fallacies Of The CBO(zt)
- [LeetCode] 1750. Minimum Length of String After Deleting Similar EndsLeetCodeMILA
- [20241012]cursor_sharing=force與函式索引.txt函式索引
- DBMS_PROFILER(zt)
- oracle event 2 (zt)Oracle
- ORA-00604(zt)
- 物化檢視(zt)
- SQL Access Advisor(zt)SQL
- DBMS_SUPPORT(zt)
- LOCK_SGA(zt)
- oracle job管理(zt)Oracle
- histogram與10053(zt)Histogram
- sybase複製(zt)
- DBMS_TRACE(zt)
- Understanding System Statistics(zt)
- ORACLE LARGE MEMORY(zt)Oracle
- dbms_stats(zt)
- 切換UNDO(zt)
- ora_rowscn(zt)
- checkpoint詳解(zt)
- 初始化引數遊標之cursor_sharing
- SQLSERVER日期函式(zt)SQLServer函式
- SqlServer鎖的概述(zt)SQLServer
- how to show hidden parameter(zt)
- checkpoint是什麼(zt)