All Products
Search
Document Center

PolarDB:TRACE

Last Updated:Mar 28, 2026

TRACE executes an SQL statement across distributed nodes and records per-node timing, row counts, and connection costs. Run SHOW TRACE after TRACE <SQL> to retrieve the results.

Unlike EXPLAIN, which analyzes the execution plan without running the statement, TRACE executes the SQL and captures real runtime metrics.

Syntax

TRACE <SQL>;
SHOW TRACE;

Trace a query

The following example traces SELECT 1.

  1. Run the TRACE statement:

    mysql> TRACE SELECT 1;
    +---+
    | 1 |
    +---+
    | 1 |
    +---+
    1 row in set (0.03 sec)

    The query executes and returns results normally.

  2. Retrieve the trace data:

    mysql> SHOW TRACE;
    +------+----------+----------------+-----------------------------------+---------------+--------------------------+------+-----------+--------+
    | ID   | TYPE     | GROUP_NAME     | DBKEY_NAME                        | TIME_COST(MS) | CONNECTION_TIME_COST(MS) | ROWS | STATEMENT | PARAMS |
    +------+----------+----------------+-----------------------------------+---------------+--------------------------+------+-----------+--------+
    |    0 | Optimize | DRDS           | DRDS                              | 3             | 0.00                     |    0 | select 1  | NULL   |
    |    1 | Query    | TDDL5_00_GROUP | db218249098_sqa_zmf_tddl5_00_3309 | 7             | 0.15                     |    1 | select 1  | NULL   |
    +------+----------+----------------+-----------------------------------+---------------+--------------------------+------+-----------+--------+
    2 rows in set (0.01 sec)

SHOW TRACE output fields

FieldDescription
IDSequential identifier for each trace entry.
TYPEPhase of processing: Optimize (query planning by the DRDS layer) or Query (physical execution on a data node).
GROUP_NAMEName of the shard group where this phase ran. DRDS indicates the distributed middleware layer; other values identify physical shard groups.
DBKEY_NAMEIdentifier of the specific database instance or node within the group.
TIME_COST(MS)Total time spent in this phase, in milliseconds.
CONNECTION_TIME_COST(MS)Time spent establishing the connection to the node, in milliseconds.
ROWSNumber of rows processed or returned in this phase.
STATEMENTThe SQL statement sent to this node.
PARAMSBound parameter values for the statement, if any. NULL when no parameters are bound.

What's next

To analyze a query's execution plan without running it, use EXPLAIN.