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 - V3.2.4Enterprise Edition

    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. V3.2.4
    iconOceanBase Database
    SQL - V 3.2.4Enterprise Edition
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    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

    Find the TOP N SQL queries

    Last Updated:2023-10-24 09:23:03  Updated
    Share
    What is on this page
    Find the TOP N SQL queries with the most requests within a certain period
    Find the TOP N SQL queries with the longest average response time within a certain period
    Find the TOP N SQL queries with the longest average execution time among all SQL queries

    folded

    Share

    Find the TOP N SQL queries with the most requests within a certain period

    You can execute the following statement to find the TOP N SQL queries with the most requests within a certain period:

    obclient> SELECT/*+ PARALLEL(15)*/ SQL_ID, COUNT(*) AS QPS, AVG(t1.elapsed_time) RT
                    FROM oceanbase.gv$sql_audit t1 WHERE tenant_id = 1001 AND
                    IS_EXECUTOR_RPC = 0 AND request_time > (time_to_usec(now()) - 10000000)  AND
                    request_time < time_to_usec (now())
                    GROUP BY t1.sql_id ORDER BY QPS DESC LIMIT 10;
    
    +----------------------------------+------+------------+
    | SQL_ID                           | QPS  | RT         |
    +----------------------------------+------+------------+
    | BF7AA13A28DF50BA5C33FF19F1DBD8A9 | 2523 |  4233.2085 |
    | CE7208ADDE365D0AB5E68EE24E5FD730 | 1268 |  5935.8683 |
    | E5C7494018989226E69AE7D08B3D0F15 | 1028 |  7275.7490 |
    | D0E8D8C937E44BC3BB9A5379AE1064C5 | 1000 | 12999.1640 |
    | 2D45D7BE4E459CFBEAE4803971F0C6F9 | 1000 |  8050.6360 |
    | C81CE9AA555BE59B088B379CC7AE5B40 | 1000 |  6865.4940 |
    | BDC4FE903B414203A04E41C7DDA6627D | 1000 | 12751.8960 |
    | B1B136047D7C3B6B9125F095363A9D23 |  885 | 13293.2237 |
    | 47993DD69888868E92A7CAB2FDE65380 |  880 |  7282.0557 |
    | 05C6279D767C7F212619BF4B659D3BAB |  844 | 11474.5438 |
    +----------------------------------+------+------------+
    

    Find the TOP N SQL queries with the longest average response time within a certain period

    You can execute the following statement to find the TOP N SQL queries with the longest average response time within a certain period:

    obclient> SELECT/*+ PARALLEL(15)*/ SQL_ID, COUNT(*) AS QPS, AVG(t1.elapsed_time) RT   
                    FROM oceanbase.gv$sql_audit t1   
                    WHERE tenant_id = 1001 AND IS_EXECUTOR_RPC = 0    
                    AND request_time > (time_to_usec(now()) - 10000000)       
                    AND request_time < time_to_usec(now())
                    GROUP BY t1.sql_id ORDER BY RT DESC LIMIT 10;
    
    
    +----------------------------------+------+------------+
    | SQL_ID                           | QPS  | RT         |
    +----------------------------------+------+------------+
    | 0A3D3DCB3343BBBB10E4B4B9777B77FC |    1 | 53618.0000 |
    | A3831961C337545AF5BD1219BE29867A |    1 | 50764.0000 |
    | F3DC5EF627DA63AE52044FCE7732267C |    1 | 48497.0000 |
    | 39C63F143FDDACAEC090F480789DBCA5 |    1 | 47035.0000 |
    | A3BF306B02FF86E76C96C9CEFADBDB7E |    1 | 45553.0000 |
    | 7942E8D29BAFBF23EF3E3D29D55F428A |    1 | 45285.0000 |
    | 20989A74CC1703664BDE9D6EA7830C24 |    1 | 39143.0000 |
    | 80F40791E76C79D3DCD46FEEFFAB338E |    1 | 37654.0000 |
    | 07E2FE351E3DD82843E81930B84D3DDE |    1 | 37231.0000 |
    | 11B19DB5A1393590ABBE08005C155B2E |    1 | 37139.0000 |
    +----------------------------------+------+------------+
    

    Find the TOP N SQL queries with the longest average execution time among all SQL queries

    You can execute the following statement to find the TOP N SQL queries with the longest average execution time among all SQL queries:

    obclient> SELECT/*+ PARALLEL(15)*/avg_exe_usec, svr_ip, svr_port, sql_id, plan_id
                    FROM oceanbase.gv$plan_cache_plan_stat
                    WHERE tenant_id = 1001
                    ORDER BY avg_exe_usec DESC LIMIT 3\G
    
    *************************** 1. row ***************************
    avg_exe_usec: 9795912
          svr_ip: 10.x.x.x
        svr_port: 2882
          sql_id: C5D91E6C772D1B87C32BB3C9ED1435E1
         plan_id: 4668689
    *************************** 2. row ***************************
    avg_exe_usec: 9435052
          svr_ip: 10.x.x.x
        svr_port: 2882
          sql_id: 3B6EFEEC8332EB2A0822A3EA7B769500
         plan_id: 4692858
    *************************** 3. row ***************************
    avg_exe_usec: 9335002
          svr_ip: 10.x.x.x
        svr_port: 2882
          sql_id: 3B6EFEEC8332EB2A0822A3EA7B769500
         plan_id: 4683085
    

    Previous topic

    Check whether SQL queries are balanced across servers in a cluster
    Last

    Next topic

    Analyze whether an unusually large number of remote execution requests exist in the system or the execution of an SQL statement
    Next
    What is on this page
    Find the TOP N SQL queries with the most requests within a certain period
    Find the TOP N SQL queries with the longest average response time within a certain period
    Find the TOP N SQL queries with the longest average execution time among all SQL queries