Chapter 48. DBMS_XPLAN

Table of Contents

48.1. Overview
48.2. Function
48.2.1. DISPLAY_CURSOR

This chapter briefly introduces the DBMS_XPLAN package, and describes how to use the procedures of the package.

48.1. Overview

DBMS_XPLAN provides the DISPLAY_CURSOR function to display plan information and plan executions using user specified items and in various formats.

DBMS_XPLAN uses a pipelined function to output query results. Each pipelined function uses TABLE() function to display the output. Since the output information can also be queried in V$SQL_PLAN and V$SQL_PLAN_STATISTICS, the GATHER_SQL_PLAN_STAT parameter must be enabled.

48.2. Function

This section describes the function provided by the DBMS_XPLAN package.

48.2.1. DISPLAY_CURSOR

Uses the SQL_ID value to display the execution plan registered in the physical plan cache. Since it is a pipelined function, the TABLE() function can be used to display the execution plan.

Details about the DISPLAY_CURSOR function are as follows:

  • Prototype

    DBMS_XPLAN.DISPLAY_CURSOR
    (
        in_sql_id       VARCHAR2 default NULL,
        in_child_number NUMBER default NULL,
        format          VARCHAR2 default 'BASIC LAST SQL'
    ) 
    RETURN dbms_xplan_type_table pipelined;
  • Parameter

    ParameterDescription
    in_sql_idSQL_ID of the plan to display. If unspecified, the SQL_ID of the last executed query for the session is used.
    in_child_numberCHILD_NUMBER of the plan to display. If unspecified, the CHILD_NUMBER of the last executed query for the session is used.
    formatItems to display. Two types of items are available: individual and group. An item with a prefix of '-' is excluded.
  • Individual Item

    ItemDescription
    CARDSNumber of rows of the plan node estimated by the optimizer.
    COSTCost information of the plan node estimated by the optimizer.
    PARTITIONPartition related information.
    PARALLELParallel execution related information.
    PREDICATEPredicate information of the plan node.
    REMOTEContents of the query executed on the database link of the plan node.
    ROWSNumber of rows executed on the plan node.
    ELAPTIMEAmount of time used by the plan node.
    USEDMEMAmount of memory used by the plan node.
    TEMPREADNumber of temporary reads used by the plan node.
    TEMPWRITENumber of temporary writes used by the plan node.
    BUFGETSNumber of buffer gets requested by the plan node.
    STARTSNumber of times the plan node has been restarted.
    LASTOption to display only the statistics of the last execution. If unspecified, the statistics of all executions on the cursor are displayed.
    PRECISEDisplays the actual values of CARDS and ROWS, instead of the rounded up value.
    HEADERBasic information about the plan. (sql id, hash value, total execution time, total patch time, and plan execution time)
    SQLQuery statement used to create the plan.
  • Group Item

    ItemDescription
    IOSTATS

    Displays all items related to IO.

    TEMPREAD + TEMPWRITE + BUFGETS
    MEMSTATS

    Displays all items related to memory.

    USEDMEM
    ALLSTATS

    Displays all items related to IO and memory.

    IOSTATS + MEMSTATS
    BASIC

    Basic output format. Includes the cardinality and cost estimated by the optimizer, and the last query execution time on each node.

    CARDS + COST + PART + ELAPTIME + LAST
    TYPICAL

    Includes information displayed at the BASIC level in addition to the number of rows, predicate, and remote SQL information used in the last query execution on each node.

    BASIC + PE + ROWS + STARTS + PRED + REMOTE + PRECISE
    ALL

    Includes information displayed at the TYPICAL level in addition to the ALLSTATS items.

    TYPICAL + ALLSTATS
  • Example

    The following is an example of displaying the plan information of the last executed query in the current session.

    SQL> select * from table(dbms_xplan.display_cursor);

    The following is an example of displaying the plan information of SQL_ID 11495 excluding the partition information.

    SQL> set pagesize 0
    SQL> set linesize 200
    SQL> select * from table
    (dbms_xplan.display_cursor(11495, 'BASIC LAST SQL -PARTITION'));
    
    COLUMN_VALUE
    --------------------------------------------------------------------------------
    
    SQL ID         : 11495
    PLAN HASH VALUE: 897223689
    EXECUTIONS     : 3
    FETCHES        : 18
    LOADED AT      : 2014/07/22 17:55:44
    SQL            : select p_name, p_mfgr, ps_supplycost, p_type,
           min (ps_supplycost) over (partition by ps_partkey) min_supplycost,
           p_comment, ps_comment
    from part, partsupp
    where p_partkey = ps_partkey
          and p_size = :v_size
          and p_brand = :v_brand
          and p_type like '%' || :v_type
    
     
    ---------------------------------------------------------------------------------
    | ID  | Operation             | Name     | Cost (%CPU)| Cards    | Elaeps. Time |
    ---------------------------------------------------------------------------------
    |   1 | COLUMN PROJECTION     |          |61069  (.02)|      94  |00:00:00.0001 |
    |   2 |  WINDOW               |          |61069  (.02)|      94  |00:00:00.0003 |
    |   3 |   GROUP BY            |          |61069  (.02)|      94  |00:00:00.0000 |
    |   4 |    ORDER BY (SORT)    |          |61069  (.02)|      94  |00:00:00.0009 |
    |   5 |     PARTITION HASH    |          |61069  (.02)|      94  |00:00:00.0039 |
    |     |     (ALL PART)        |          |            |          |              |
    |   6 |      HASH JOIN        |          |61069  (.02)|      94  |00:00:00.0905 |
    |   7 |       TABLE ACCESS    | PART     |12517  (.02)|       4  |00:00:00.2713 |   
    |     |       (FULL)          | 
    |   8 |       TABLE ACCESS    | PARTSUPP |48545    (0)|     706K |00:00:00.1580 |
    |     |       (FULL)          |          |            |          |              |
    ---------------------------------------------------------------------------------
     
    Note
    ---------------------------------------------------------------------------------
        7 - dynamic sampling used for this table (88 blocks)
        8 - dynamic sampling used for this table (88 blocks)

    The following is an example of displaying the execution time, number of affected rows, and buffer gets result of the last query execution.

    SQL> set pagesize 0
    SQL> set linesize 200
    SQL> select * from table
    (dbms_xplan.display_cursor(11495, 'ROWS ELAPTIME +BUFGETS'));
    
    COLUMN_VALUE
    ------------------------------------------------------------------------------
    SQL ID         : 11495
    PLAN HASH VALUE: 897223689
    EXECUTIONS     : 3
    FETCHES        : 18
    LOADED AT      : 2014/07/22 17:55:44
     
    ------------------------------------------------------------------------------
    | ID  | Operation             | Name     | Rows    | Elaps. Time  | CR Gets  |
    ------------------------------------------------------------------------------
    |   1 | COLUMN PROJECTION     |          |     156 |00:00:00.0001 |       0  |
    |   2 |  WINDOW               |          |     156 |00:00:00.0003 |       0  |
    |   3 |   GROUP BY            |          |     156 |00:00:00.0000 |       0  |
    |   4 |    ORDER BY (SORT)    |          |     156 |00:00:00.0009 |       0  |
    |   5 |     PARTITION HASH    |          |     156 |00:00:00.0039 |       0  |
    |     |     (ALL PART)        |          |         |              |          | 
    |   6 |      HASH JOIN        |          |     156 |00:00:00.0905 |       0  |
    |   7 |       TABLE ACCESS    | PART     |      39 |00:00:00.2713 |   28754  |
    |     |       (FULL)          |          |         |              |          | 
    |   8 |       TABLE ACCESS    | PARTSUPP |  212296 |00:00:00.1580 |   30377  |
    |     |       (FULL)          |          |         |              |          |
    ------------------------------------------------------------------------------
     
    Predicate Information
    --------------------------------------------------------------------------------
        6 - access: ("PART"."P_PARTKEY" = "PARTSUPP"."PS_PARTKEY") (0.000)
        7 - filter: ("PART"."P_SIZE" = :0) AND ("PART"."P_TYPE" LIKE CONCAT('%',:2))
                    AND ("PART"."P_BRAND" = :1) (0.018 * 0.025 * 0.062)
                    
     
    Note
    --------------------------------------------------------------------------------
        7 - dynamic sampling used for this table (88 blocks)
        8 - dynamic sampling used for this table (88 blocks)