【发布时间】:2019-11-01 09:03:57
【问题描述】:
我想知道进程的顺序,先执行什么..
首先我创建表 =>
SQL> create table ramin.tab001 ( id number, name varchar2(20));
Table created.
SQL> select *from ramin.tab001;
ID NAME
---------- --------------------
1 kamran
2 emin
3 ramin
4 john
在此之后,我使用带有自动跟踪选项的相关子查询 =>
SQL>delete from ramin.tab001 a where exists( select * from ramin.tab001 where id = a.id );
执行计划 =>
Execution Plan
----------------------------------------------------------
Plan hash value: 906765530
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | DELETE STATEMENT | | 6 | 36 | 6 (0)| 00:00:01 |
| 1 | DELETE | TAB001 | | | | |
|* 2 | HASH JOIN SEMI | | 6 | 36 | 6 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| TAB001 | 6 | 18 | 3 (0)| 00:00:01 |
| 4 | TABLE ACCESS FULL| TAB001 | 6 | 18 | 3 (0)| 00:00:01 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"="A"."ID")
Statistics
----------------------------------------------------------
0 recursive calls
7 db block gets
6 consistent gets
0 physical reads
1204 redo size
848 bytes sent via SQL*Net to client
1005 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
4 rows processed
我知道在相关子查询中,进程的顺序是 =>
1.执行内部查询
2.执行外查询并与内查询结果进行比较
所以我需要专家对语句中的流程顺序或如何从自动跟踪中检查的意见?
【问题讨论】:
-
答:顺序完全由执行计划决定。
-
对于删除的 where exists 内部查询是完全没有必要的。基本上它读作:“从该表中删除该表中存在键的表”,这将始终评估为真。
-
你的意思是外部查询只需要内部的一个键来删除所有行?但这是相关的,在此语句中仅删除了
2 - access("ID"="A"."ID")中的行,而不是表中的所有行。 -
@nop77svk 我无法理解执行计划中的顺序,顺序是从 4 开始到 0 吗?
-
@KamranAbbasov,“如何阅读执行计划”似乎与您提出的问题不同。