OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.2.5

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.2.5
    iconOceanBase Database
    SQL - V 4.2.5
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Query SQL execution plans

    Last Updated:2026-04-09 09:38:52  Updated
    share
    What is on this page
    Format of the EXPLAIN statement
    Shape and operators of a plan

    folded

    share

    An execution plan describes the process of executing an SQL statement in a database.

    You can run the EXPLAIN command to view the logical execution plan generated by the optimizer for a given SQL statement. To analyze the performance of an SQL statement, you need to first check the SQL execution plan to see if any error exists. Therefore, understanding the execution plan is the first step for SQL tuning, and knowledge about operators of an execution plan is key to understanding the EXPLAIN command.

    Format of the EXPLAIN statement

    OceanBase Database supports three EXPLAIN command formats: EXPLAIN BASIC, EXPLAIN, and EXPLAIN EXTENDED. They demonstrate details of execution plans at different levels:

    • The EXPLAIN BASIC command shows the most basic framework of a plan.

    • The EXPLAIN EXTENDED command extends a plan to its full frame with the most details and is usually used in troubleshooting.

    • The EXPLAIN command shows information to the extent that helps users understand the entire execution process of a plan.

    The format of the EXPLAIN command is as follows:

    EXPLAIN [BASIC | EXTENDED | PARTITIONS | FORMAT = format_name] [PRETTY | PRETTY_COLOR] explainable_stmt
    format_name:
      { TRADITIONAL | JSON }
    explainable_stmt:
      { SELECT statement
     | DELETE statement
     | INSERT statement
     | REPLACE statement
     | UPDATE statement }
    

    The EXPLAIN command applies to the SELECT, DELETE, INSERT, REPLACE, and UPDATE statements. This command shows information about statement execution plans provided by the optimizer, including the method of processing the statement and the method and sequence of joining tables.

    You can run the EXPLAIN EXTENDED command to display the scan range of the table and run the EXPLAIN OUTLINE command to display the outline information.

    The FORMAT option is used to specify the output format. The TRADITIONAL value is the default value and specifies to display information in a table. The JSON value specifies to display information in a JSON file.

    You can use the EXPLAIN PARTITIONS statement to check queries related to partitioned tables. If you check queries for non-partitioned tables, no error is returned, but the values in the PARTITIONS column are always NULL.

    For complex execution plans, you can use the PRETTY or PRETTY_COLOR option to connect the parent and child nodes in the plan tree with tree lines or colored tree lines, so that the execution plan is easier to read. Here is an example:

    obclient> CREATE TABLE p1table(c1 INT ,c2 INT) PARTITION BY HASH(c1) PARTITIONS 2;
    Query OK, 0 rows affected
    
    obclient> CREATE TABLE p2table(c1 INT ,c2 INT) PARTITION BY HASH(c1) PARTITIONS 4;
    Query OK, 0 rows affected
    
    obclient> EXPLAIN EXTENDED PRETTY_COLOR SELECT  * FROM p1table p1 JOIN p2table p2 ON p1.c1=p2.c2\G
    *************************** 1. row ***************************
    Query Plan: ==========================================================
    |ID|OPERATOR                     |NAME    |EST. ROWS|COST|
    ----------------------------------------------------------
    |0 |PX COORDINATOR               |        |1        |278 |
    |1 | EXCHANGE OUT DISTR          |:EX10001|1        |277 |
    |2 |  HASH JOIN                  |        |1        |276 |
    |3 |  ├PX PARTITION ITERATOR     |        |1        |92  |
    |4 |  │ TABLE SCAN               |P1      |1        |92  |
    |5 |  └EXCHANGE IN DISTR         |        |1        |184 |
    |6 |    EXCHANGE OUT DISTR (PKEY)|:EX10000|1        |184 |
    |7 |     PX PARTITION ITERATOR   |        |1        |183 |
    |8 |      TABLE SCAN             |P2      |1        |183 |
    ==========================================================
    
    Outputs & filters:
    -------------------------------------
      0 - output([INTERNAL_FUNCTION(P1.C1, P1.C2, P2.C1, P2.C2)]), filter(nil)
      1 - output([INTERNAL_FUNCTION(P1.C1, P1.C2, P2.C1, P2.C2)]), filter(nil), dop=1
      2 - output([P1.C1], [P2.C2], [P1.C2], [P2.C1]), filter(nil),
          equal_conds([P1.C1 = P2.C2]), other_conds(nil)
      3 - output([P1.C1], [P1.C2]), filter(nil)
      4 - output([P1.C1], [P1.C2]), filter(nil),
          access([P1.C1], [P1.C2]), partitions(p[0-1])
      5 - output([P2.C2], [P2.C1]), filter(nil)
      6 - (#keys=1, [P2.C2]), output([P2.C2], [P2.C1]), filter(nil), dop=1
      7 - output([P2.C1], [P2.C2]), filter(nil)
      8 - output([P2.C1], [P2.C2]), filter(nil),
          access([P2.C1], [P2.C2]), partitions(p[0-3])
    
    1 row in set
    

    Shape and operators of a plan

    A sample execution plan in OceanBase Database is as follows:

    |ID|OPERATOR              |NAME       |EST. ROWS|COST |
    -------------------------------------------------------
    |0 |LIMIT                 |           |100      |81141|
    |1 | TOP-N SORT           |           |100      |81127|
    |2 |  HASH GROUP BY       |           |2924     |68551|
    |3 |   HASH JOIN          |           |2924     |65004|
    |4 |    SUBPLAN SCAN      |VIEW1      |2953     |19070|
    |5 |     HASH GROUP BY    |           |2953     |18662|
    |6 |      NESTED-LOOP JOIN|           |2953     |15080|
    |7 |       TABLE SCAN     |ITEM       |19       |11841|
    |8 |       TABLE SCAN     |STORE_SALES|161      |73   |
    |9 |    TABLE SCAN        |DT         |6088     |29401|
    =======================================================
    

    You may notice from the foregoing examples that a plan in OceanBase Database is similar to that in Oracle Database. The following table describes columns of an execution plan in OceanBase Database.

    Column
    Description
    ID The sequence number of the execution tree obtained by using preorder traversal, starting from 0.
    OPERATOR The name of the operator.
    NAME The name of the table or index corresponding to a table operation.
    EST. ROWS The estimated number of output rows of the operator.
    COST The execution cost of the operator, in microseconds.

    Note

    In a table operation, the NAME field displays names (alias) of tables involved in the operation. In the case of index access, the name of the index is displayed in parentheses after the table name. For example, t1(t1_c2) indicates that index t1_c2 is used. In the case of reverse scanning, the keyword RESERVE is added after the index name, with the index name and the keyword RESERVE separated with a comma (,), such as t1(t1_c2,RESERVE).

    In OceanBase Database, the first part of the output of the EXPLAIN command is the tree structure of the execution plan. The hierarchy of operations in the tree is represented by the indentation of the operators. Operators at the deepest level are executed first. Operators at the same level are executed in the specified execution order.

    The following figure shows the tree structure of the execution plan described in the preceding example:

    Constraint 6

    In OceanBase Database, the second part of the output of the EXPLAIN command contains the details of each operator, including the output expression, filter conditions, partition information, and unique information of each operator, such as the sort keys, join keys, and pushdown conditions. Here is an example:

    Outputs & filters:
    -------------------------------------
      0 - output([t1.c1], [t1.c2], [t2.c1], [t2.c2]), filter(nil), sort_keys([t1.c1, ASC], [t1.c2, ASC]), prefix_pos(1)
      1 - output([t1.c1], [t1.c2], [t2.c1], [t2.c2]), filter(nil),
          equal_conds([t1.c1 = t2.c2]), other_conds(nil)
      2 - output([t2.c1], [t2.c2]), filter(nil), sort_keys([t2.c2, ASC])
      3 - output([t2.c2], [t2.c1]), filter(nil),
          access([t2.c2], [t2.c1]), partitions(p0)
      4 - output([t1.c1], [t1.c2]), filter(nil),
          access([t1.c1], [t1.c2]), partitions(p0)
    

    Previous topic

    Execution process of SQL queries
    Last

    Next topic

    Perform distributed execution and parallel queries
    Next
    What is on this page
    Format of the EXPLAIN statement
    Shape and operators of a plan