[20220328]查詢游標為什麼不共享指令碼.txt
[20220328]查詢游標為什麼不共享指令碼.txt
> @ ashtop machine,client_id sql_id='cks1xuhvjt1a2' &day
Total Distinct Distinct
Seconds AAS %This MACHINE CLIENT_ID FIRST_SEEN LAST_SEEN Execs Seen Tstamps
--------- ------- ------- -------------------- ----------- ------------------- ------------------- ---------- --------
195 .0 31% | oda1 127.0.0.1 2022-03-27 03:15:27 2022-03-27 03:17:08 1 195
> @ sql_id cks1xuhvjt1a2
--SQL_ID = cks1xuhvjt1a2
SELECT /* pxhcdr.sql Cursor Sharing as per Reason */
CHR(10)||'<tr>'||CHR(10)||
'<td>'||ROWNUM||'</td>'||CHR(10)||
'<td>'||v2.reason||'</td>'||CHR(10)||
'<td>'||v2.inst_id||'</td>'||CHR(10)||
'<td>'||v2.cursors||'</td>'||CHR(10)||
'</tr>'
FROM (
SELECT 'ACL_MISMATCH' reason, inst_id, COUNT(*) cursors FROM gv$sql_shared_cursor WHERE ACL_MISMATCH = 'Y' GROUP BY inst_id
UNION ALL
SELECT 'ANYDATA_TRANSFORMATION' reason, inst_id, COUNT(*) cursors FROM gv$sql_shared_cursor WHERE ANYDATA_TRANSFORMATION = 'Y' GROUP BY inst_id
UNION ALL
...
UNION ALL
SELECT 'USER_BIND_PEEK_MISMATCH' reason, inst_id, COUNT(*) cursors FROM gv$sql_shared_cursor WHERE USER_BIND_PEEK_MISMATCH = 'Y' GROUP BY inst_id
UNION ALL
SELECT 'USE_FEEDBACK_STATS' reason, inst_id, COUNT(*) cursors FROM gv$sql_shared_cursor WHERE USE_FEEDBACK_STATS = 'Y' GROUP BY inst_id
ORDER BY reason, inst_id ) v2;
--//不知道那個管理者執行注意看時間是凌晨3點。檢視為什麼游標不共享的指令碼,這樣查詢當然效率很低。
--//我記憶裡我好像以前收集過一個生成指令碼,查了一下日記,發現連結:
--//http://blog.itpub.net/267265/viewspace-2144458/ =>[20170904]11Gr2 查詢游標為什麼不共享指令碼。
--//參考連結下面的註解指令碼:
--//carlos-sierra.net/2017/09/01/poors-man-script-to-summarize-reasons-why-cursors-are-not-shared/
SELECT 'select reason_not_shared, count(*) cursors, count(distinct sql_id) sql_ids
from v$sql_shared_cursor
unpivot(val for reason_not_shared in(
'
|| LISTAGG
(
' '
|| LISTAGG (column_name, ',') WITHIN GROUP (ORDER BY column_id)
,',
'
)
WITHIN GROUP (ORDER BY line_no)
|| '
))
where val = ''Y''
group by reason_not_shared
order by 2 desc, 3, 1;'
sql_text
FROM (SELECT column_name
,column_id
,CEIL (ROW_NUMBER () OVER (ORDER BY column_id) / 4) line_no
FROM dba_tab_columns
WHERE owner = 'SYS'
AND table_name = 'V_$SQL_SHARED_CURSOR'
AND data_length = 1)
GROUP BY line_no;
--//利用unpivot,LISTAGG生成指令碼。
select reason_not_shared, count(*) cursors, count(distinct sql_id) sql_ids
from v$sql_shared_cursor
unpivot(val for reason_not_shared in(
UNBOUND_CURSOR,SQL_TYPE_MISMATCH,OPTIMIZER_MISMATCH,OUTLINE_MISMATCH,
STATS_ROW_MISMATCH,LITERAL_MISMATCH,FORCE_HARD_PARSE,EXPLAIN_PLAN_CURSOR,
BUFFERED_DML_MISMATCH,PDML_ENV_MISMATCH,INST_DRTLD_MISMATCH,SLAVE_QC_MISMATCH,
TYPECHECK_MISMATCH,AUTH_CHECK_MISMATCH,BIND_MISMATCH,DESCRIBE_MISMATCH,
LANGUAGE_MISMATCH,TRANSLATION_MISMATCH,BIND_EQUIV_FAILURE,INSUFF_PRIVS,
INSUFF_PRIVS_REM,REMOTE_TRANS_MISMATCH,LOGMINER_SESSION_MISMATCH,INCOMP_LTRL_MISMATCH,
OVERLAP_TIME_MISMATCH,EDITION_MISMATCH,MV_QUERY_GEN_MISMATCH,USER_BIND_PEEK_MISMATCH,
TYPCHK_DEP_MISMATCH,NO_TRIGGER_MISMATCH,FLASHBACK_CURSOR,ANYDATA_TRANSFORMATION,
PDDL_ENV_MISMATCH,TOP_LEVEL_RPI_CURSOR,DIFFERENT_LONG_LENGTH,LOGICAL_STANDBY_APPLY,
DIFF_CALL_DURN,BIND_UACS_DIFF,PLSQL_CMP_SWITCHS_DIFF,CURSOR_PARTS_MISMATCH,
STB_OBJECT_MISMATCH,CROSSEDITION_TRIGGER_MISMATCH,PQ_SLAVE_MISMATCH,TOP_LEVEL_DDL_MISMATCH,
MULTI_PX_MISMATCH,BIND_PEEKED_PQ_MISMATCH,MV_REWRITE_MISMATCH,ROLL_INVALID_MISMATCH,
OPTIMIZER_MODE_MISMATCH,PX_MISMATCH,MV_STALEOBJ_MISMATCH,FLASHBACK_TABLE_MISMATCH,
LITREP_COMP_MISMATCH,PLSQL_DEBUG,LOAD_OPTIMIZER_STATS,ACL_MISMATCH,
FLASHBACK_ARCHIVE_MISMATCH,LOCK_USER_SCHEMA_FAILED,REMOTE_MAPPING_MISMATCH,LOAD_RUNTIME_HEAP_FAILED,
HASH_MATCH_FAILED,PURGED_CURSOR,BIND_LENGTH_UPGRADEABLE,USE_FEEDBACK_STATS
))
where val = 'Y'
group by reason_not_shared
order by 2 desc, 3, 1;
REASON_NOT_SHARED CURSORS SQL_IDS
----------------------------- ---------- ----------
ROLL_INVALID_MISMATCH 8756 3297
BIND_EQUIV_FAILURE 876 63
USE_FEEDBACK_STATS 783 314
PURGED_CURSOR 375 370
OPTIMIZER_MISMATCH 315 114
BIND_LENGTH_UPGRADEABLE 277 201
BIND_MISMATCH 207 120
LANGUAGE_MISMATCH 197 48
OPTIMIZER_MODE_MISMATCH 140 60
HASH_MATCH_FAILED 75 68
BIND_UACS_DIFF 60 60
USER_BIND_PEEK_MISMATCH 56 15
DIFFERENT_LONG_LENGTH 37 15
LOAD_OPTIMIZER_STATS 29 28
INST_DRTLD_MISMATCH 16 4
AUTH_CHECK_MISMATCH 12 8
TRANSLATION_MISMATCH 10 6
MULTI_PX_MISMATCH 5 1
STATS_ROW_MISMATCH 5 2
PQ_SLAVE_MISMATCH 4 2
TYPCHK_DEP_MISMATCH 4 2
DIFF_CALL_DURN 1 1
22 rows selected.
--//如果換成gv$sql_shared_cursor,時間增加不少,我的測試v$sql_shared_cursor 3秒,gv$sql_shared_cursor 17秒。
--//我看了以前我們舊系統LANGUAGE_MISMATCH 排名第一,這個是因為我們在安裝部署應用軟體時使用兩套字符集的原因。
NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
--//簡單探究是什麼原因導致的問題。
SELECT sql_id, COUNT (*)
FROM v$sql_shared_cursor
WHERE ROLL_INVALID_MISMATCH = 'Y'
GROUP BY sql_id
HAVING COUNT (*) >= 20
ORDER BY 2 DESC;
SQL_ID COUNT(*)
------------- ----------
70pnyzz8hgjxm 113
bp20933j1aa5p 94
1msndsv11mzc1 90
4t5w0d69u8sm7 69
b748a8a4y15ra 50
d4cdrjs9vnyaw 36
9zg9qd9bm4spu 31
2zpn9zwhv6w9m 25
9u8gp6xtzf60f 24
1va57mnax09r7 23
g93p68x9afrra 21
11 rows selected.
--//這個原因實際上由於晚上10點分析表導致原先的游標失效。以前的分析是關閉的。
--//BIND_EQUIV_FAILURE 的原因可能是返回記錄出現很大變化時就會出現。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2884546/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20220420]完善查詢游標為什麼不共享指令碼.txt指令碼
- [20200129]子游標不共享BIND_EQUIV_FAILURE.txtUIAI
- [20180724]Flashback query和子游標共享.txt
- [20180813]重新整理共享池與父子游標.txt
- [20180613]子游標不共享BIND_EQUIV_FAILUREUIAI
- Oracle 查詢行數很少,為什麼不走索引?Oracle索引
- [20200325]慎用標量子查詢.txt
- [20210112]完善查詢繫結變數指令碼bind_cap.txt變數指令碼
- phpstrom用模型where查詢,欄位為什麼不會提示?PHP模型
- Oracle - 共享遊標、父子游標、硬軟解析Oracle
- [20220421]完善查詢表分析的歷史th.sql指令碼.txtSQL指令碼
- [20220422]為什麼執行不報錯.txt
- 【轉載】為什麼 MySQL 不推薦使用子查詢和 joinMySql
- [轉載] 為什麼 MySQL 不推薦使用子查詢和 joinMySql
- ClickHouse為什麼查詢速度快?
- 索引為什麼能提供查詢效能...索引
- [20211220]關於標量子查詢問題.txt
- [20210902]為什麼會使用多個共享記憶體段.txt記憶體
- [20180626]函式與標量子查詢14.txt函式
- [20180612]函式與標量子查詢10.txt函式
- [20180611]函式與標量子查詢9.txt函式
- [20180607]函式與標量子查詢8.txt函式
- [20180602]函式與標量子查詢4.txt函式
- [20180602]函式與標量子查詢3.txt函式
- 20180601]函式與標量子查詢2.txt函式
- [20211214]18c標量子查詢unnest.txt
- 為什麼 Redis 的查詢很快, Redis 如何保證查詢的高效Redis
- 什麼是shell指令碼?Linux為什麼學習shell?指令碼Linux
- MySQL中MyISAM為什麼比InnoDB查詢快MySql
- Jmeter 本身能錄製指令碼,為什麼還要用 Fiddler 生成指令碼?JMeter指令碼
- [20210812]測試sql語句子游標的效能.txtSQL
- 技術分享 | 為什麼 SELECT 查詢選擇全表掃描,而不走索引?索引
- Sqlserver查詢alwayson同步情況指令碼(2)SQLServer指令碼
- 為什麼我使用了索引,查詢還是慢?索引
- 告訴你MySQL主鍵查詢為什麼這麼快MySql
- win10筆記本滑鼠游標不見了怎麼辦 win10滑鼠游標恢復的方法Win10筆記
- html標籤種類很多,為什麼不都用div?HTML
- [20180819]關於父子游標問題(11g).txt