All Products
Search
Document Center

ApsaraDB RDS:Query top N SQL statements

Last Updated:Mar 28, 2026

The TOP SQL tab in the autonomy service identifies which SQL statements consume the most database resources. Use it to pinpoint high-cost queries and prioritize optimization work—without waiting for a full workload analysis.

With TOP SQL, you can:

  • Rank SQL statements by CPU overhead, execution duration, logical reads, physical reads, logical writes, or returned rows

  • Switch between per-execution averages (to find inefficient queries) and cumulative totals (to find high-frequency queries)

  • Copy any SQL statement directly from the console for immediate inspection

  • Access historical query data through SQL Explorer and Audit

Prerequisites

Before you begin, ensure that:

  • Your RDS instance does not run SQL Server 2008 R2 with cloud disks

Query real-time top SQL statements

  1. Go to the Instances page. In the top navigation bar, select the region where the instance resides. Find the instance and click its ID.

  2. In the left-side navigation pane, choose Autonomy Services > Performance Optimization.

  3. Click the TOP SQL tab.

  4. Select the metric to rank SQL statements by, then turn on Automatic Refresh.

    Real-time statistics come from an in-memory cache that resets each time the instance starts. The cache updates instantly as SQL statements execute. Check the Last Executed At column to confirm when a statement last ran.

    To copy a SQL statement, click it in the Statement or SQL Block column. In the dialog box that appears, click Copy.

Query historical top SQL statements

Use SQL Explorer and Audit to view historical top SQL statements for the instance.

TOP SQL tab reference

The TOP SQL tab has four sections.

Top SQL statement overview

Displays the most recent time the SQL statement statistics were updated and lets you choose which statistics to view.

Real-time top SQL statements - Average overhead

Ranks SQL statements by resource consumption per execution. Use this section to identify inefficient queries—those that consume disproportionate resources each time they run, regardless of how often they run.

Sort metricDescription
Average CPU overheadAverage CPU overhead per execution. Unit: milliseconds.
Average execution durationAverage running time per execution. Unit: milliseconds.
Average returned rowsAverage number of rows returned per execution.
Average logical readsAverage number of logical read operations per execution.
Average physical readsAverage number of physical read operations per execution.
Average logical writesAverage number of logical write operations per execution.

Real-time top SQL statements - Total cost

Ranks SQL statements by cumulative resource consumption since the instance started. Use this section to identify high-frequency or long-running queries that generate the largest overall load—the best candidates for index optimization or query rewriting.

Sort metricDescription
Total CPU overheadTotal CPU overhead across all executions. Unit: milliseconds.
Execution durationTotal running time across all executions. Unit: milliseconds.
Total returned rowsTotal number of rows returned across all executions.
Total logical readsTotal number of logical read operations across all executions.
Total physical readsTotal number of physical read operations across all executions.
Total executionsTotal number of times the SQL statement was executed.

Real-time top SQL statements - List

Displays all tracked SQL statements with per-statement metrics. Click a statement in the Statement or SQL Block column to view its full text and copy it.

ParameterDescription
DatabaseThe database on which the SQL statement ran.
StatementThe SQL statement that was executed. Click to view details and copy.
SQL BlockThe full text of the SQL statement. Click to view and copy.
ExecutionsTotal number of executions.
Total CPU timeTotal CPU overhead across all executions.
Average CPU timeAverage CPU overhead per execution.
Execution durationTotal running time across all executions.
Average execution durationAverage running time per execution.
Total returned rowsTotal number of rows returned across all executions.
Average returned rowsAverage number of rows returned per execution.
Total logical readsTotal number of logical read operations across all executions.
Average logical readsAverage number of logical read operations per execution.
Total physical readsTotal number of physical read operations across all executions.
Average physical readsAverage number of physical read operations per execution.
Total logical writesTotal number of logical write operations across all executions.
Average logical writesAverage number of logical write operations per execution.
Last executed atThe most recent time the SQL statement ran.