我的编程空间,编程开发者的网络收藏夹
学习永远不晚

[20211215]提示precompute_subquery补充.txt

短信预约 信息系统项目管理师 报名、考试、查分时间动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

[20211215]提示precompute_subquery补充.txt

[20211215]提示precompute_subquery补充.txt

[20211215]提示precompute_subquery补充.txt

--//前几天测试precompute_subquery,我仔细想一下好像以前看书或者别人的blog见到使用过.
--//我翻看以前的工作日志,发现blog如下:

D: otes>dir /s/b *precompute_subquery*
D: otes2014201408[20140829]PRECOMPUTE_SUBQUERY hint.txt
D: otes2015201503[20150316]PRECOMPUTE_SUBQUERY.txt

--//我自己都写过两篇文章,时间太久远了,有点记不住了,加上很少使用这个提示.仔细看了原来的文章,发现当时自己的功力实在太差了.
--//不过里面提到的几个细节我给重复测试看看.

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

2.测试1:
SCOTT@book> select * from dual where dummy in (select chr(level) from dual connect by level<=100);
D
-
X
---//多执行几次.
SCOTT@book> @hash
HASH_VALUE SQL_ID        CHILD_NUMBER KGL_BUCKET PLAN_HASH_VALUE SQL_EXEC_START      SQL_EXEC_ID
---------- ------------- ------------ ---------- --------------- ------------------- -----------
2725646910 c437vsqj7c4jy            3       4670       272002086 2021-12-15 09:34:22    16777219

SCOTT@book> select sql_id,child_number from v$sql where sql_id="c437vsqj7c4jy";
SQL_ID        CHILD_NUMBER
------------- ------------
c437vsqj7c4jy            0
c437vsqj7c4jy            1
c437vsqj7c4jy            2
c437vsqj7c4jy            3


SCOTT@book> @nonshared c437vsqj7c4jy
Show why existing SQL child cursors were not reused (V$SQL_SHARED_CURSOR)...
SQL_ID                        : c437vsqj7c4jy
ADDRESS                       : 000000007D702AC8
CHILD_ADDRESS                 : 000000007C330B70
CHILD_NUMBER                  : 0
REASON                        : 09PQ Slave mismatch(1)1x467108864
-----------------
SQL_ID                        : c437vsqj7c4jy
ADDRESS                       : 000000007D702AC8
CHILD_ADDRESS                 : 000000007D10AAD8
CHILD_NUMBER                  : 1
CURSOR_PARTS_MISMATCH         : Y
REASON                        : 19PQ Slave mismatch(1)1x467108864
-----------------
SQL_ID                        : c437vsqj7c4jy
ADDRESS                       : 000000007D702AC8
CHILD_ADDRESS                 : 000000007BFE2E18
CHILD_NUMBER                  : 2
CURSOR_PARTS_MISMATCH         : Y
REASON                        : 29PQ Slave mismatch(1)1x467108864
-----------------
SQL_ID                        : c437vsqj7c4jy
ADDRESS                       : 000000007D702AC8
CHILD_ADDRESS                 : 000000007C121608
CHILD_NUMBER                  : 3
CURSOR_PARTS_MISMATCH         : Y
REASON                        :
-----------------
PL/SQL procedure successfully completed.

--//换一个语句尝试:
SCOTT@book> select * from dept where deptno not in (select deptno from emp);
    DEPTNO DNAME          LOC
---------- -------------- -------------
        40 OPERATIONS     BOSTON
---//多执行几次.

SCOTT@book> @ hash
HASH_VALUE SQL_ID        CHILD_NUMBER KGL_BUCKET PLAN_HASH_VALUE SQL_EXEC_START      SQL_EXEC_ID
---------- ------------- ------------ ---------- --------------- ------------------- -----------
1533076182 b58wqt9dq1sqq            3      58070      3383998547 2021-12-15 09:36:34    16777219

SCOTT@book> select sql_id,child_number from v$sql where sql_id="b58wqt9dq1sqq";
SQL_ID        CHILD_NUMBER
------------- ------------
b58wqt9dq1sqq            0
b58wqt9dq1sqq            1
b58wqt9dq1sqq            2
b58wqt9dq1sqq            3
--//问题依旧。

SCOTT@book> @nonshared b58wqt9dq1sqq
Show why existing SQL child cursors were not reused (V$SQL_SHARED_CURSOR)...

SQL_ID                        : b58wqt9dq1sqq
ADDRESS                       : 000000007CD50B68
CHILD_ADDRESS                 : 000000007D8DE4E8
CHILD_NUMBER                  : 0
REASON                        : 09PQ Slave mismatch(1)1x467108864
-----------------
SQL_ID                        : b58wqt9dq1sqq
ADDRESS                       : 000000007CD50B68
CHILD_ADDRESS                 : 000000007C932BA8
CHILD_NUMBER                  : 1
CURSOR_PARTS_MISMATCH         : Y
REASON                        : 19PQ Slave mismatch(1)1x467108864
-----------------
SQL_ID                        : b58wqt9dq1sqq
ADDRESS                       : 000000007CD50B68
CHILD_ADDRESS                 : 000000007D276458
CHILD_NUMBER                  : 2
CURSOR_PARTS_MISMATCH         : Y
REASON                        : 29PQ Slave mismatch(1)1x467108864
-----------------
SQL_ID                        : b58wqt9dq1sqq
ADDRESS                       : 000000007CD50B68
CHILD_ADDRESS                 : 000000007BC6F920
CHILD_NUMBER                  : 3
CURSOR_PARTS_MISMATCH         : Y
REASON                        :
-----------------
PL/SQL procedure successfully completed.

3.测试2:
--//内层使用绑定变量呢?
variable v_sal number;
exec :v_sal := 1000;

SCOTT@book> @ sl all
alter session set statistics_level = all;

Session altered.

SCOTT@book> select * from dept where deptno not in (select deptno from emp where sal > :v_sal);
    DEPTNO DNAME          LOC
---------- -------------- -------------
        40 OPERATIONS     BOSTON

SCOTT@book> @dpc "" ""
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  260bdkx0wpcrt, child number 1
-------------------------------------
select * from dept where deptno not in (select deptno from emp where sal > :v_sal)
Plan hash value: 2100826622
---------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation          | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
---------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |      1 |        |       |   216M(100)|          |      1 |00:00:00.01 |      12 |      5 |       |       |          |
|*  1 |  HASH JOIN ANTI NA |      |      1 |      1 |    27 |   216M  (1)|722:44:41 |      1 |00:00:00.01 |      12 |      5 |  1321K|  1321K| 1074K (0)|
|   2 |   TABLE ACCESS FULL| DEPT |      1 |      4 |    80 |     3   (0)| 00:00:01 |      4 |00:00:00.01 |       6 |      0 |       |       |          |
|*  3 |   TABLE ACCESS FULL| EMP  |      1 |    166M|  1112M|   216M  (1)|722:44:35 |     12 |00:00:00.01 |       6 |      5 |       |       |          |
---------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$5DA710D3
   2 - SEL$5DA710D3 / DEPT@SEL$1
   3 - SEL$5DA710D3 / EMP@SEL$2
Peeked Binds (identified by position):
--------------------------------------
   1 - (NUMBER): 1000
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access("DEPTNO"="DEPTNO")
   3 - filter("SAL">:V_SAL)
--//如果使用绑定变量,提示失效。

SCOTT@book> select * from dept where deptno not in (select deptno from emp where sal > 1000);
    DEPTNO DNAME          LOC
---------- -------------- -------------
        40 OPERATIONS     BOSTON

SCOTT@book> @dpc "" ""
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  cabmj7fg33ty7, child number 0
-------------------------------------
select * from dept where deptno not in (select deptno from emp where sal > 1000)
Plan hash value: 3383998547
--------------------------------------------------------------------------------------------------------------------
| Id  | Operation         | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers |
--------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |      1 |        |       |     3 (100)|          |      1 |00:00:00.01 |       6 |
|*  1 |  TABLE ACCESS FULL| DEPT |      1 |      2 |    40 |     3   (0)| 00:00:01 |      1 |00:00:00.01 |       6 |
--------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / DEPT@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter(("DEPTNO"<>10 AND "DEPTNO"<>20 AND "DEPTNO"<>30))

SCOTT@book> select sql_id,child_number from v$sql where sql_id="cabmj7fg33ty7";
SQL_ID        CHILD_NUMBER
------------- ------------
cabmj7fg33ty7            0
cabmj7fg33ty7            1

4.总结:
--//1.怪不得这个提示很少人提及,每次都产生1个新的子光标,每次都是一次"硬分析"。
--//2.使用范围很窄,一旦内层使用绑定变量,提示失效。

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

[20211215]提示precompute_subquery补充.txt

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

[20211215]提示precompute_subquery补充.txt

[20211215]提示precompute_subquery补充.txt--//前几天测试precompute_subquery,我仔细想一下好像以前看书或者别人的blog见到使用过.--//我翻看以前的工作日志,发现blog如下:D:otes>dir /s
[20211215]提示precompute_subquery补充.txt
2020-08-25

编程热搜

目录