分享
 
 
 

关于PUSH_SUBQ提示的说明

王朝other·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

PUSH_SUBQ 可以用来控制子查询的执行 这个是PUSH_SUBQ 的本意

我那个例子的意思是说:

PUSH_SUBQ 本质上是个CBO的hints(当然RBO也提不上hints)

由于PUSH_SUBQ 的引入就是为了来解决unnesting的某些不足

所以在不同的版本上,这个hints发挥的作用也有所不同了.

8i上这个提示的作用更接近本原:

$ sqlplus "/ as sysdba"

SQL*Plus: Release 8.1.5.0.0 - Production on Sun Sep 12 20:51:21 2004

(c) Copyright 1999 Oracle Corporation.

All rights reserved.

Connected to:

Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production

With the Partitioning and Java options

PL/SQL Release 8.1.5.0.0 - Production

SQL connect scott/tiger

Connected.

SQL create table dept1 as select * from dept;

Table created.

SQL set linesize 120

SQL select a.*

2

from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

EMPNO ENAME

JOB

MGR HIREDATE

SAL

COMM

DEPTNO

----- ---------- --------- ---------- --------- ---------- ---------- ----------

7369

SMITH

CLERK

7902 17-DEC-80

800

20

7499

ALLEN

SALESMAN

7698 20-FEB-81

1600

300

30

7521

WARD

SALESMAN

7698 22-FEB-81

1250

500

30

7566

JONES

MANAGER

7839 02-APR-81

2975

20

7654

MARTIN

SALESMAN

7698 28-SEP-81

1250

1400

30

7698

BLAKE

MANAGER

7839 01-MAY-81

2850

30

7782

CLARK

MANAGER

7839 09-JUN-81

2450

10

7788

SCOTT

ANALYST

7566 19-APR-87

3000

20

7839

KING

PRESIDENT

17-NOV-81

5000

10

7844

TURNER

SALESMAN

7698 08-SEP-81

1500

0

30

7876

ADAMS

CLERK

7788 23-MAY-87

1100

20

EMPNO ENAME

JOB

MGR HIREDATE

SAL

COMM

DEPTNO

----- ---------- --------- ---------- --------- ---------- ---------- ----------

7900

JAMES

CLERK

7698 03-DEC-81

950

30

7902

FORD

ANALYST

7566 03-DEC-81

3000

20

7934

MILLER

CLERK

7782 23-JAN-82

1300

10

14 rows selected.

Execution Plan

----------------------------------------------------------

0

SELECT STATEMENT Optimizer=CHOOSE

1

0

FILTER ---------------'最初push_subq的使命是为了消除/提高这个filter的效率的'

2

1

NESTED LOOPS

3

2

TABLE ACCESS (FULL) OF 'EMP'

4

2

TABLE ACCESS (BY INDEX ROWID) OF 'DEPT'

5

4

INDEX (UNIQUE SCAN) OF 'PK_DEPT' (UNIQUE)

6

1

TABLE ACCESS (FULL) OF 'DEPT1'

Statistics

----------------------------------------------------------

0

recursive calls

52

db block gets

21

consistent gets

0

physical reads

0

redo size

2715

bytes sent via SQL*Net to client

751

bytes received via SQL*Net from client

4

SQL*Net roundtrips to/from client

1

sorts (memory)

0

sorts (disk)

14

rows processed

用于push_subq是个CBO hints,这里我们可以看到COST的出现:

SQL select /*+ push_subq */ a.*

2

from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

EMPNO ENAME

JOB

MGR HIREDATE

SAL

COMM

DEPTNO

----- ---------- --------- ---------- --------- ---------- ---------- ----------

7782

CLARK

MANAGER

7839 09-JUN-81

2450

10

7839

KING

PRESIDENT

17-NOV-81

5000

10

7934

MILLER

CLERK

7782 23-JAN-82

1300

10

7369

SMITH

CLERK

7902 17-DEC-80

800

20

7566

JONES

MANAGER

7839 02-APR-81

2975

20

7788

SCOTT

ANALYST

7566 19-APR-87

3000

20

7876

ADAMS

CLERK

7788 23-MAY-87

1100

20

7902

FORD

ANALYST

7566 03-DEC-81

3000

20

7499

ALLEN

SALESMAN

7698 20-FEB-81

1600

300

30

7521

WARD

SALESMAN

7698 22-FEB-81

1250

500

30

7654

MARTIN

SALESMAN

7698 28-SEP-81

1250

1400

30

EMPNO ENAME

JOB

MGR HIREDATE

SAL

COMM

DEPTNO

------ ---------- --------- ---------- --------- ---------- ---------- ----------

7698 BLAKE

MANAGER

7839 01-MAY-81

2850

30

7844 TURNER

SALESMAN

7698 08-SEP-81

1500

0

30

7900 JAMES

CLERK

7698 03-DEC-81

950

30

14 rows selected.

Execution Plan

----------------------------------------------------------

0

SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=1 Bytes=122)

1

0

NESTED LOOPS (Cost=3 Card=1 Bytes=122)

2

1

TABLE ACCESS (FULL) OF 'DEPT' (Cost=1 Card=2 Bytes=44)

3

2

TABLE ACCESS (FULL) OF 'DEPT1' (Cost=1 Card=1 Bytes=9)--------'这里消除了之前的filter'

4

1

TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=21 Bytes=2100)

Statistics

----------------------------------------------------------

204

recursive calls

85

db block gets

38

consistent gets

0

physical reads

0

redo size

2706

bytes sent via SQL*Net to client

768

bytes received via SQL*Net from client

4

SQL*Net roundtrips to/from client

5

sorts (memory)

0

sorts (disk)

14

rows processed

再看CBO下:

正常情况下,没什么好说的:

SQL set autotrace traceonly

SQL exec dbms_stats.gather_schema_stats('SCOTT')

PL/SQL procedure successfully completed.

SQL select a.*

2

from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

14 rows selected.

Execution Plan

----------------------------------------------------------

0

SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=5 Bytes=275)

1

0

FILTER

2

1

NESTED LOOPS (Cost=2 Card=5 Bytes=275)

3

2

TABLE ACCESS (FULL) OF 'DEPT' (Cost=1 Card=1 Bytes=18)

4

2

TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=518)

5

1

TABLE ACCESS (FULL) OF 'DEPT1' (Cost=1 Card=1 Bytes=9)

Statistics

----------------------------------------------------------

39

recursive calls

68

db block gets

21

consistent gets

0

physical reads

0

redo size

2708

bytes sent via SQL*Net to client

751

bytes received via SQL*Net from client

4

SQL*Net roundtrips to/from client

1

sorts (memory)

0

sorts (disk)

14

rows processed

在CBO下push_subq发挥了同样的作用:

SQL select /*+ push_subq */ a.*

2

from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

14 rows selected.

Execution Plan

----------------------------------------------------------

0

SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=5 Bytes=275)

1

0

NESTED LOOPS (Cost=2 Card=5 Bytes=275)

2

1

TABLE ACCESS (FULL) OF 'DEPT' (Cost=1 Card=1 Bytes=18)

3

2

TABLE ACCESS (FULL) OF 'DEPT1' (Cost=1 Card=1 Bytes=9)---'注意这里'

4

1

TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=518)

Statistics

----------------------------------------------------------

0

recursive calls

84

db block gets

11

consistent gets

0

physical reads

0

redo size

2709

bytes sent via SQL*Net to client

768

bytes received via SQL*Net from client

4

SQL*Net roundtrips to/from client

1

sorts (memory)

0

sorts (disk)

14

rows processed

而在Oracle9i之中:

[oracle@jumper oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Sun Sep 12 21:42:57 2004

Copyright (c) 1982, 2002, Oracle Corporation.

All rights reserved.

Connected to:

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

SQL connect scott/tiger

Connected.

SQL set linesize 120

SQL set autotrace traceonly

SQL select a.*

2

from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

11 rows selected.

Execution Plan

----------------------------------------------------------

0

SELECT STATEMENT Optimizer=CHOOSE

1

0

FILTER

2

1

NESTED LOOPS

3

2

TABLE ACCESS (FULL) OF 'EMP'

4

2

TABLE ACCESS (BY INDEX ROWID) OF 'DEPT'

5

4

INDEX (UNIQUE SCAN) OF 'PK_DEPT' (UNIQUE)

6

1

TABLE ACCESS (FULL) OF 'DEPT1'

Statistics

----------------------------------------------------------

0

recursive calls

0

db block gets

26

consistent gets

0

physical reads

0

redo size

1164

bytes sent via SQL*Net to client

503

bytes received via SQL*Net from client

2

SQL*Net roundtrips to/from client

0

sorts (memory)

0

sorts (disk)

11

rows processed

SQL select /*+ push_subq */ a.*

2

from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

11 rows selected.

Execution Plan

----------------------------------------------------------

0

SELECT STATEMENT Optimizer=CHOOSE (Cost=8 Card=82 Bytes=9676)

1

0

HASH JOIN (SEMI) (Cost=8 Card=82 Bytes=9676)

2

1

HASH JOIN (Cost=5 Card=82 Bytes=8938)

3

2

TABLE ACCESS (FULL) OF 'EMP' (Cost=2 Card=82 Bytes=7134)

4

2

TABLE ACCESS (FULL) OF 'DEPT' (Cost=2 Card=82 Bytes=1804)

5

1

TABLE ACCESS (FULL) OF 'DEPT1' (Cost=2 Card=82 Bytes=738)

Statistics

----------------------------------------------------------

0

recursive calls

0

db block gets

10

consistent gets

0

physical reads

0

redo size

1195

bytes sent via SQL*Net to client

503

bytes received via SQL*Net from client

2

SQL*Net roundtrips to/from client

0

sorts (memory)

0

sorts (disk)

11

rows processed

SQL exec dbms_stats.gather_schema_stats('scott')

PL/SQL procedure successfully completed.

SQL select a.*

2

from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

11 rows selected.

Execution Plan

----------------------------------------------------------

0

SELECT STATEMENT Optimizer=CHOOSE (Cost=8 Card=11 Bytes=682)

1

0

HASH JOIN (SEMI) (Cost=8 Card=11 Bytes=682)

2

1

HASH JOIN (Cost=5 Card=11 Bytes=572)

3

2

TABLE ACCESS (FULL) OF 'DEPT' (Cost=2 Card=4 Bytes=52)

4

2

TABLE ACCESS (FULL) OF 'EMP' (Cost=2 Card=11 Bytes=429)

5

1

TABLE ACCESS (FULL) OF 'DEPT1' (Cost=2 Card=4 Bytes=40)

Statistics

----------------------------------------------------------

172

recursive calls

0

db block gets

60

consistent gets

0

physical reads

0

redo size

1196

bytes sent via SQL*Net to client

503

bytes received via SQL*Net from client

2

SQL*Net roundtrips to/from client

6

sorts (memory)

0

sorts (disk)

11

rows processed

SQL select /*+ push_subq */ a.*

2

from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

11 rows selected.

Execution Plan

----------------------------------------------------------

0

SELECT STATEMENT Optimizer=CHOOSE (Cost=8 Card=11 Bytes=682)

1

0

HASH JOIN (SEMI) (Cost=8 Card=11 Bytes=682)

2

1

HASH JOIN (Cost=5 Card=11 Bytes=572)

3

2

TABLE ACCESS (FULL) OF 'DEPT' (Cost=2 Card=4 Bytes=52)

4

2

TABLE ACCESS (FULL) OF 'EMP' (Cost=2 Card=11 Bytes=429)

5

1

TABLE ACCESS (FULL) OF 'DEPT1' (Cost=2 Card=4 Bytes=40)

Statistics

----------------------------------------------------------

0

recursive calls

0

db block gets

10

consistent gets

0

physical reads

0

redo size

1196

bytes sent via SQL*Net to client

503

bytes received via SQL*Net from client

2

SQL*Net roundtrips to/from client

0

sorts (memory)

0

sorts (disk)

11

rows processed

SQL

可以肯定的是push_subq从8i到9i的作用发生了变化

这个变化可能来自于CBO的更加优化

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有