[20201126]使用cursor_sharing_exact与给sql打补丁2.txt --//以前我记忆里给sql语句打补丁,好像在11g下打上cursor_sharing_exact提示无效的,看链接 --//https://hourim.wordpress.com/2020/10/24/function-based-indexes-and-cursor-sharing/ --//感觉我视乎做错一些步骤,自己重复测试: 1.环境: SCOTT@book> @ ver1 PORT_STRING VERSION BANNER ------------------------------ -------------- -------------------------------------------------------------------------------- x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production SCOTT@book> select /*+ full(dept) */ * from dept where deptno=10; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK SCOTT@book> @ hash HASH_VALUE SQL_ID CHILD_NUMBER HASH_HEX ---------- ------------- ------------ --------- 3262421396 g0qybdz1796cn 0 c2749994 declare v_sql CLOB; begin select distinct sql_text into v_sql from v$sql where sql_id='&sql_id'; sys.dbms_sqldiag_internal.i_create_patch( sql_text => v_sql, hint_text => 'cursor_sharing_exact IGNORE_OPTIM_EMBEDDED_HINTS)', name => 'user_extents_patch'); end; / --//输入sql_id=g0qybdz1796cn. SYS@book> select name, status, created, sql_text from dba_sql_patches where name='user_extents_patch'; NAME STATUS CREATED SQL_TEXT ------------------ -------- -------------------------- ---------------------------------------------------- user_extents_patch ENABLED 2020-11-26 11:14:51.000000 select /*+ full(dept) */ * from dept where deptno=10 SYS@book> alter system flush shared_pool; System altered. SYS@book> alter system flush shared_pool; System altered. --//退出会话重新登录: SCOTT@book> alter session set cursor_sharing=force; Session altered. SCOTT@book> select /*+ full(dept) */ * from dept where deptno=10; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK SCOTT@book> @ dpc '' '' PLAN_TABLE_OUTPUT ------------------------------------- SQL_ID 73trg5tn9pzqf, child number 0 ------------------------------------- select /*+ full(dept) */ * from dept where deptno=:"SYS_B_0" Plan hash value: 3383998547 --------------------------------------------------------------------------- | Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 3 (100)| | |* 1 | TABLE ACCESS FULL| DEPT | 1 | 20 | 3 (0)| 00:00:01 | --------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 / DEPT@SEL$1 Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("DEPTNO"=:SYS_B_0) 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 --//可以发现我这样操作不行,实际上应该使用sql_id=73trg5tn9pzqf来打补丁,我以前这样做是错误的。 SYS@book> exec sys.dbms_sqldiag.drop_sql_patch('user_extents_patch'); PL/SQL procedure successfully completed. SYS@book> select name, status, created, sql_text from dba_sql_patches where name='user_extents_patch'; no rows selected declare v_sql CLOB; begin select distinct sql_text into v_sql from v$sql where sql_id='&sql_id'; sys.dbms_sqldiag_internal.i_create_patch( sql_text => v_sql, hint_text => 'cursor_sharing_exact IGNORE_OPTIM_EMBEDDED_HINTS)', name => 'user_extents_patch'); end; / --//注意输入sql_id=73trg5tn9pzqf SYS@book> select name, status, created, sql_text from dba_sql_patches where name='user_extents_patch' 2 @ prxx ============================== NAME : user_extents_patch STATUS : ENABLED CREATED : 2020-11-26 11:17:05.000000 SQL_TEXT : select /*+ full(dept) */ * from dept where deptno=:"SYS_B_0" PL/SQL procedure successfully completed. --//退出会话重新登录: SYS@book> alter system flush shared_pool; System altered. SYS@book> alter system flush shared_pool; System altered. SCOTT@book> alter session set cursor_sharing=force; Session altered. SCOTT@book> select /*+ full(dept) */ * from dept where deptno=10; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK SCOTT@book> @ dpc '' '' PLAN_TABLE_OUTPUT ------------------------------------- SQL_ID g0qybdz1796cn, child number 0 ------------------------------------- select /*+ full(dept) */ * from dept where deptno=10 Plan hash value: 2852011669 ---------------------------------------------------------------------------------------- | Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time | ---------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 1 (100)| | | 1 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 20 | 1 (0)| 00:00:01 | |* 2 | INDEX UNIQUE SCAN | PK_DEPT | 1 | | 0 (0)| | ---------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 / DEPT@SEL$1 2 - SEL$1 / DEPT@SEL$1 Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("DEPTNO"=10) Note ----- - SQL patch "user_extents_patch" used for this statement - 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 32 rows selected. --//注意看下执行计划sql_id=g0qybdz1796cn.对于的是select /*+ full(dept) */ * from dept where deptno=10。 --//语句做一些改动。 SCOTT@book> Select /*+ full(dept) */ * from dept where deptno= 40; DEPTNO DNAME LOC ---------- -------------- ------------- 40 OPERATIONS BOSTON --//注意我写的S是大写,后面的参数带入40. 参数40前我还加了一个空格。 SCOTT@book> @ dpc '' '' PLAN_TABLE_OUTPUT ------------------------------------- SQL_ID 943r9wd5qa6hg, child number 0 ------------------------------------- Select /*+ full(dept) */ * from dept where deptno= 40 Plan hash value: 2852011669 ---------------------------------------------------------------------------------------- | Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time | ---------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 1 (100)| | | 1 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 20 | 1 (0)| 00:00:01 | |* 2 | INDEX UNIQUE SCAN | PK_DEPT | 1 | | 0 (0)| | ---------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 / DEPT@SEL$1 2 - SEL$1 / DEPT@SEL$1 Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("DEPTNO"=40) Note ----- - SQL patch "user_extents_patch" used for this statement - 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 32 rows selected. --//一样生效。看来以前的学习不认真,犯了一个小错误。 --//有了这个就可以在使用 cursor_sharing=force的情况下,在一些谓词条件to_char的情况下实现使用函数索引。 --//当然缺点就是无法共享相同光标了,消耗大量共享池资源,每次语句不同可能都需要硬解析。 --//有机会再测试看看。顺便看看解析的情况: --//收尾: SYS@book> exec sys.dbms_sqldiag.drop_sql_patch('user_extents_patch'); PL/SQL procedure successfully completed.
[20201126]使用cursor_sharing_exact与给sql打补丁2.txt
来源:这里教程网
时间:2026-03-03 16:16:50
作者:
编辑推荐:
- [20201126]使用cursor_sharing_exact与给sql打补丁2.txt03-03
- [20201126]使用cursor_sharing_exact与给sql打补丁3.txt03-03
- [202021127]sql打补丁问题.txt03-03
- [20202117]Function based indexes and cursor sharing.txt03-03
- Oracle 12c 业务用户密码大小写不敏感03-03
- Oracle TPS指标03-03
- [20201111]11.2.0.4版本仍然存在的一个未修复Bug ora-00600 [13013].txt03-03
- [20201112]nid改变数据库名字.txt03-03
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- oracle删除表中数据(delete与truncate)
oracle删除表中数据(delete与truncate)
26-03-03 - SQL Server数据库mdf文件中了勒索病毒*.mdf.[helpbackup@email.tg].Devos
- G006-ORACLE-INS-SIFS-01 ORACLE 19C SIFS Ins ON RHEL 8.2
- G008-ORACLE-DG ORACLE 19C Active Data Guard DML Redirection
- 查看oracle数据库中,哪些表的字段是null值比较多
查看oracle数据库中,哪些表的字段是null值比较多
26-03-03 - Oracle数据库服务器dbf文件中了勒索病毒,扩展名被篡改为.CC7H
Oracle数据库服务器dbf文件中了勒索病毒,扩展名被篡改为.CC7H
26-03-03 - 数据库范式
数据库范式
26-03-03 - 沙龙回顾丨开发者掌握这些背后的技术路径,可助力企业智能化升级
沙龙回顾丨开发者掌握这些背后的技术路径,可助力企业智能化升级
26-03-03 - Oracle的awr报告分析
Oracle的awr报告分析
26-03-03 - DDD 在京东 DevOps 项目协作领域的落地实战
DDD 在京东 DevOps 项目协作领域的落地实战
26-03-03
