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.6.0

    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.6.0
    iconOceanBase Database
    SQL - V 4.6.0
    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

    Locate and analyze slow queries I

    Last Updated:2026-05-07 11:26:24  Updated
    share
    What is on this page
    Sample scenario
    Locate a slow SQL query
    Obtain the execution plan for a slow query

    folded

    share

    The efficiency of a running database system can downgrade when a batch of queries are concurrently executed or when a type of queries are executed for a long time. This topic describes how to locate a slow query and obtain its execution plan by using gv$ob_processlist, gv$plan_cache_plan_stat, and gv$plan_cache_plan_explain.

    Sample scenario

    The following example initiates a slow query. You can locate the slow query and obtain its execution plan by taking the following steps.

    CREATE TABLE T1 (C1 INT, C2 INT);
    INSERT INTO T1 VALUES (1, 1);
    
    SELECT SLEEP(1000) FROM T1;
    

    Locate a slow SQL query

    Log in to the sys tenant and execute the following statement to accurately locate the slow SQL query with detailed filter conditions. For example, you can specify user or tenant.

    SELECT USER,
        tenant,
        sql_id,
        concat(time, 's') as time,
        info,
        svr_ip,
        svr_port,
        trace_id
    FROM gv$ob_processlist
    WHERE STATE = 'ACTIVE'
    ORDER BY time DESC LIMIT 1;
    

    The following result is returned, which displays information about the slow SQL query, including the username, tenant name, SQL ID, execution time, SQL text, IP address and port of the OBServer node where the query is executed, and trace ID of the query.

    +------+----------+----------------------------------+------+-----------------------------------------------------------------------------------------------------------------+----------------+----------+------------------------------------+
    | USER | tenant   | sql_id                           | time | info                                                                                                            | svr_ip         | svr_port | trace_id                           |
    +------+----------+----------------------------------+------+-----------------------------------------------------------------------------------------------------------------+----------------+----------+------------------------------------+
    | root | mysql001 | A585F887331EF7267F0C87B343C69D99 | 0s   | SELECT USER,
    tenant,
    sql_id,
    concat(time, 's') as time,
    info,
    svr_ip,
    svr_port,
    trace_id
    FROM gv$ob_processlist | 11.xxx.x.xx |    28824 | Y70980BA1CCFB-0006062A332767A6-0-0 |
    +------+----------+----------------------------------+------+-----------------------------------------------------------------------------------------------------------------+----------------+----------+------------------------------------+
    

    Obtain the execution plan for a slow query

    You can obtain information about the execution plan for the preceding slow SQL query based on the query information returned.

    1. Execute the following statement to obtain information about the execution plan for the slow SQL query.

      Use the actual tenant ID for tenant_id and specify svr_ip, svr_port, and sql_id based on the previously returned information about the slow SQL query.

      SELECT tenant_id,
         svr_ip,
         svr_port,
         sql_id,
         plan_id,
         last_active_time,
         first_load_time,
         outline_data
      FROM GV$PLAN_CACHE_PLAN_STAT
      WHERE TENANT_ID = 1002
      AND SQL_ID = '3310A1D1D81D4BA92CEEF42538136DD1'
      AND SVR_IP = '11.xxx.x.xx'
      AND SVR_PORT = 35046;
      

      The following result is returned, which displays information about the execution plan for the query, including the plan ID (plan_id), time when the plan was first generated (first_load_time), and time when the plan was last used (last_active_time). For batch processing, last_active_time is very likely the time when the slow query was initiated.

      Here, outline_data is the hint description of the execution plan.

      *************************** 1. row ***************************
          tenant_id: 1002
              svr_ip: 11.xxx.x.xx
              svr_port: 35046
              sql_id: 3310A1D1D81D4BA92CEEF42538136DD1
              plan_id: 741
      last_active_time: 2022-08-04 11:00:34.466037
      first_load_time: 2022-08-04 11:00:34.466037
          outline_data: /*+ BEGIN_OUTLINE_DATA FULL(@"SEL$1" "test.t1"@"SEL$1") END_OUTLINE_DATA*/
      
    2. Obtain the tree-shaped execution plan for the slow SQL query.

      Execute the following statement:

      SELECT OPERATOR, NAME, ROWS, COST FROM GV$PLAN_CACHE_PLAN_EXPLAIN
      WHERE TENANT_ID = 1002 AND
          SVR_IP = '11.xxx.x.xx' AND
          SVR_PORT = 35046 AND
          PLAN_ID = 741 ;
      

      The physical plan for the query is as follows:

      +----------------+------+------+------+
      | OPERATOR       | NAME | ROWS | COST |
      +----------------+------+------+------+
      | PHY_TABLE_SCAN | t1   |    1 |   45 |
      +----------------+------+------+------+
      

      You can also try to obtain the logical plan by using the EXPLAIN statement.

      explain select sleep(1000), rand() from t1;
      
      *************************** 1. row ***************************
      Query Plan: ===================================
      |ID|OPERATOR  |NAME|EST. ROWS|COST|
      -----------------------------------
      |0 |TABLE SCAN|t1  |1        |46  |
      ===================================
      
      Outputs & filters:
      -------------------------------------
      0 - output([sleep(?)], [rand()]), filter(nil),
          access([t1.__pk_increment]), partitions(p0)
      

    Previous topic

    Schema specifications
    Last

    Next topic

    Locate and analyze slow queries II
    Next
    What is on this page
    Sample scenario
    Locate a slow SQL query
    Obtain the execution plan for a slow query