[20241012]cursor_sharing=force与函数索引.txt --//今天听了一个课程,提到使用cursor_sharing=force解决sql语句使用文字变量问题以及局限性,实际上一些局限性在新的oracle版 --//本已经不存在, 突然想起今年3月份的事情,使用cursor_sharing_exact给sql语句打补丁5条,仅仅1条有效(11g环境)。 --//参考链接:[20240327]使用cursor_sharing_exact与给sql打补丁问题5.txt --//也就是在11g下可以使用提示cursor_sharing_exact打补丁解决时,我遇到了问题,我记忆里使用12.2 测试过,今天在21c下重复测 --//试. --//关于这部分内容可以参考链接:https://hourim.wordpress.com/2020/10/24/function-based-indexes-and-cursor-sharing/ 1.环境: SCOTT@book01p> @ver2 ============================== PORT_STRING : x86_64/Linux 2.4.xx VERSION : 21.0.0.0.0 BANNER : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production BANNER_FULL : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production Version 21.3.0.0.0 BANNER_LEGACY : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production CON_ID : 0 PL/SQL procedure successfully completed. 2.测试建立: SCOTT@book01p> create table empx as select * from emp; Table created. SCOTT@book01p> create index if_empx_hiredate on empx(to_char(hiredate,'yyyymmdd')); Index created. --//分析略。 3.测试: SCOTT@book01p> alter session set cursor_sharing=force; Session altered. SCOTT@book01p> select * from empx where to_char(hiredate,'yyyymmdd') = '20220302'; no rows selected SCOTT@book01p> @dpc '' '' '' PLAN_TABLE_OUTPUT ------------------------------------- SQL_ID f567tudmra8p4, child number 0 ------------------------------------- select * from empx where to_char(hiredate,:"SYS_B_0") = :"SYS_B_1" Plan hash value: 976799893 --------------------------------------------------------------------------------------------------------- | Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time | --------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 2 (100)| | | 1 | TABLE ACCESS BY INDEX ROWID BATCHED| EMPX | 1 | 47 | 2 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | IF_EMPX_HIREDATE | 1 | | 1 (0)| 00:00:01 | --------------------------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 / "EMPX"@"SEL$1" 2 - SEL$1 / "EMPX"@"SEL$1" Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("EMPX"."SYS_NC00009$"=:SYS_B_1) Note ----- - Warning: basic plan statistics not available. These are only collected when: * hint 'gather_plan_statistics' is used for the statement or * parameter 'statistics_level' is set to 'ALL', at session or system level 31 rows selected. --//注意看到sql语句select * from empx where to_char(hiredate,:"SYS_B_0") = :"SYS_B_1",它不像使用提示 --//cursor_sharing_exact打补丁,会产生大量的文字变量sql语句。 SCOTT@book01p> select ename from empx Where to_char(hiredate,'yyyymmdd') = '20220302'; no rows selected SCOTT@book01p> @dpc '' '' '' PLAN_TABLE_OUTPUT ------------------------------------- SQL_ID 776d1zq9amy2p, child number 0 ------------------------------------- select ename from empx Where to_char(hiredate,:"SYS_B_0") = :"SYS_B_1" Plan hash value: 976799893 --------------------------------------------------------------------------------------------------------- | Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time | --------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 2 (100)| | | 1 | TABLE ACCESS BY INDEX ROWID BATCHED| EMPX | 1 | 15 | 2 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | IF_EMPX_HIREDATE | 1 | | 1 (0)| 00:00:01 | --------------------------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 / "EMPX"@"SEL$1" 2 - SEL$1 / "EMPX"@"SEL$1" Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("EMPX"."SYS_NC00009$"=:SYS_B_1) Note ----- - Warning: basic plan statistics not available. These are only collected when: * hint 'gather_plan_statistics' is used for the statement or * parameter 'statistics_level' is set to 'ALL', at session or system level 31 rows selected. --//谓词条件换成to_char(hiredate,'yyyy') = '2022'。 SCOTT@book01p> select ename from empx Where to_char(hiredate,'yyyy') = '2022'; no rows selected SCOTT@book01p> @dpc '' '' '' PLAN_TABLE_OUTPUT ------------------------------------- SQL_ID 776d1zq9amy2p, child number 1 ------------------------------------- select ename from empx Where to_char(hiredate,:"SYS_B_0") = :"SYS_B_1" Plan hash value: 722738080 --------------------------------------------------------------------------- | Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 3 (100)| | |* 1 | TABLE ACCESS FULL| EMPX | 1 | 14 | 3 (0)| 00:00:01 | --------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 / "EMPX"@"SEL$1" Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter(TO_CHAR(INTERNAL_FUNCTION("HIREDATE"),:SYS_B_0)=:SYS_B_1) Note ----- - Warning: basic plan statistics not available. These are only collected when: * hint 'gather_plan_statistics' is used for the statement or * parameter 'statistics_level' is set to 'ALL', at session or system level 29 rows selected. --//函数索引不支持,选择全表扫描。产生新的子光标。 SCOTT@book01p> @ gunshare 776d1zq9amy2p --- host vim /tmp/unshare.tmp --- host cat /tmp/unshare.tmp REASON_NOT_SHARED CURSORS SQL_IDS ----------------------------- ---------- ---------- HASH_MATCH_FAILED 1 1 4.简单总结: --//至少目前的版本解决cursor_sharing=force一些局限性,至于复杂的sql语句是否有效,我没有测试。 --//我看了以前的测试11g下使用cursor_sharing_exact给sql语句打补丁还是存在许多问题。
[20241012]cursor_sharing=force与函数索引.txt
来源:这里教程网
时间:2026-03-03 20:40:44
作者:
编辑推荐:
- [20241012]cursor_sharing=force与函数索引.txt03-03
- [20241012]dbms_shared_pool.keep减少硬分析吗.txt03-03
- [20241012]ORA-01792 maximum number of columns in a table or view is 1000.txt03-03
- 数据库管理-第244期 一次无法switchover的故障处理(20240928)03-03
- [20241012]ora-12526.txt03-03
- 史上最详细的,Oracle数据库AI落地理论及实践03-03
- [20240927]学习SQL MASCROS.txt03-03
- 数据库管理-第247期 23ai:全球分布式数据库-Schema对象(20241004)03-03
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- 数据库管理-第244期 一次无法switchover的故障处理(20240928)
- 史上最详细的,Oracle数据库AI落地理论及实践
史上最详细的,Oracle数据库AI落地理论及实践
26-03-03 - 数据库管理-第247期 23ai:全球分布式数据库-Schema对象(20241004)
- Oracle 数据库架构
Oracle 数据库架构
26-03-03 - Oracle + JSON = 王炸!!!
Oracle + JSON = 王炸!!!
26-03-03 - 大事件! Oracle CloudWorld 是"真高光"还是"挤牙膏"?
- 掌握CMD命令:轻松切换IP地址
掌握CMD命令:轻松切换IP地址
26-03-03 - 5大公有云厂商增强很猛~作为DBA的,有点焦虑!
5大公有云厂商增强很猛~作为DBA的,有点焦虑!
26-03-03 - ORA-01558: out of transaction ID's in rollback segment SYSTEM---惜分飞
- 一个很小的系统为什么负载那么高?
一个很小的系统为什么负载那么高?
26-03-03
