Explanation of NESTEDLOOPSSEMI (semi-nested loop) in oracle execution plan

Source: Internet
Author: User
NESTEDLOOPSSEMI (semi-nested loop) EXISTS in the execution plan of the SQL statements that exist in subqueries of in and related subqueries of EXISTS ). The so-called NESTEDLOOPSSEMI (semi-nested loop) is theoutquerystopsevaluating... Number of) theresultsetofthe

In the Execution Plan of the SQL statements with in subqueries and the SQL statements with EXISTS-related subqueries, there is NESTED LOOPS SEMI (SEMI-NESTED loop ). The so-called nested loops semi (SEMI-NESTED loop) is the out query stops evaluating... ) The result set of

InSubquerySQL statement and ExistenceEXISTSOfSQL statementThere is a nested loops semi (SEMI-NESTED loop) in the execution plan ).

The so-calledNested loops semi (SEMI-NESTED loop)That is

The out query stops evaluating... The result set of the inner query when the first value is found.

That is to say, once the first result of the subquery is displayed, the primary query (the current row of the table in) stops executing the subquery.


Nested loops semi (SEMI-NESTED loop)The pseudocode for executing the process is as follows:

  1. Open tab1 (Tables in the primary query)
  2. While tab1 still has records
  3. Fetch one record from tab1
  4. (And) result = false (about variableSet the result value to alse.)
  5. Open tab2
  6. While tab2 still has records
  7. Fetch one record from tab2
  8. If (the result set obtained by executing a subquery statement based on the values of tab1.record and tab2.record is not empty) then
  9. Result = true
  10. (And)Exit loop2
  11. End if
  12. End loop2
  13. Close tab2
  14. If (result = true) return tab1 record
  15. End loop1
  16. Close tab1
Note:

  • Fetch one record from tab1
  • Result = false (about variableSet the result value to alse.)
  • Open tab2
  • These three statements are in a parallel relationship.


  • Result = true
  • Exit loop2
  • These two statements are in a parallel relationship.


    SQL statement in an in statementNested loops semi (SEMI-NESTED loop) in the execution plan ):


    [Html] view plaincopy

    1. Gyj @ MYDB> set autot traceonly;
    2. Gyj @ MYDB> select * from t4 where id in (select id from t3 );
    3. 9 rows selected.
    4. Execution Plan
    5. ----------------------------------------------------------
    6. Plan hash value: 1092212754
    7. -----------------------------------------------------------------------------
    8. | Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time |
    9. -----------------------------------------------------------------------------
    10. | 0 | select statement | 9 | 99 | 21 (0) | 00:00:01 |
    11. | 1 | nested loops semi | 9 | 99 | 21 (0) | 00:00:01 |
    12. | 2 | table access full | T4 | 9 | 54 | 3 (0) | 00:00:01 |
    13. | * 3 | index range scan | IDX_T3 | 999K | 4882K | 2 (0) | 00:00:01 |
    14. -----------------------------------------------------------------------------
    15. Predicate Information (identified by operation id ):
    16. ---------------------------------------------------
    17. 3-access ("ID" = "ID ")
    18. Statistics
    19. ----------------------------------------------------------
    20. 1 recursive cballs
    21. 0 db block gets
    22. 20 consistent gets
    23. 0 physical reads
    24. 0 redo size
    25. 723 bytes sent via SQL * Net to client
    26. 520 bytes encoded ed via SQL * Net from client
    27. 2 SQL * Net roundtrips to/from client
    28. 0 sorts (memory)
    29. 0 sorts (disk)
    30. 9 rows processed



    ExistEXISTSOfSQL statementIn the Execution Plan):


    [Html] view plaincopy

    1. Open tab1
    2. While tab1 still has records
    3. Fetch record from tab1
    4. Result = false
    5. Open tab2
    6. While tab2 still has records
    7. Fetch record from tab2
    8. If (tab1.record matches tab2.record) then
    9. Result = true
    10. Exit loop
    11. End if
    12. End loop
    13. Close tab2
    14. If (result = true) return tab1 record
    15. End loop
    16. Close tab1

    Note:

    1 #

  • The EXISTS predicate is very simple. It is a test of a non-empty set. If any row exists in its subquery, TRUE is returned; otherwise, FALSE is returned. The UNKNOWN result is not returned. The EXIST () predicate syntax is as follows: : = [NOTEXISTS] <表子查询>

    2 #

  • In an execution plan, if a parent operation has two parallel sub-operations, one of the execution modes is:

    The first sub-operation is executed first, which affects the execution of the sub-operation in the next column. That is to say, the first sub-operation traverses table A and the parent operation ends, when this sub-operation traverses data in A row of table A, another sub-operation traverses table B. For example,

    1. |1 | nested loops semi | 9 | 99 | 21 (0) | 00:00:01 |
    2. | 2 | table access full | T4 | 9 | 54 | 3 (0) | 00:00:01 |
    3. | * 3 | index range scan | IDX_T3 | 999K | 4882K | 2 (0) | 00:00:01 |
    Source: in-depth understanding of nested query

    See:

    [One question per day] OCP1z0-047: use of EXISTS in the subquery ................................ ..... 28



  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.