【问题标题】:Exists operator in delete statement batch process?删除语句批处理中是否存在操作员?
【发布时间】: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,“如何阅读执行计划”似乎与您提出的问题不同。

标签: oracle exists


【解决方案1】:

如何阅读执行计划?

答案很简单。阅读它就像阅读命令式语言中的多层嵌套函数调用一样。

例如,你的执行计划

------------------------------------------------------------------------------
| 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")

可以简单地阅读(以命令式伪代码的形式)

delete(
    from: "TAB001",
    data_set_to_be_deleted: semi_join(
        join_algorithm: "hash join",
        leading_data_set: table_access(
            read_access_method: "full",
            table_name: "TAB001"
        ),
        trailing_data_set: table_access(
            read_access_method: "full",
            table_name: "TAB001",
            aliased_as: "A"
        ),
        join_condition: "ID = A.ID"
    )
)

【讨论】:

    猜你喜欢
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多