Skip to main content
This topic introduces how to obtain and analyze query trace profiles. A query trace profile records the debug information for a specified query statement, including time costs, variables & values, and logs. Such information is categorized into several modules, allowing you to debug and identify the performance bottlenecks from different aspects. This feature is supported from v3.2.0 onwards.

Syntax

You can use the following syntax to obtain the trace profile of a query:
  • TIMES: Traces the time costs of events in each stage of the specified query.
  • VALUES: Traces the variables and their values of the specified query.
  • LOGS: Traces the log records of the specified query.
  • ALL: Lists all the TIMES, VALUES, and LOGS information in chronological order.
  • <module>: The module you want to trace information from. Valid values:
    • BASE: The base module.
    • MV: The materialized view module.
    • OPTIMIZER: The optimizer module.
    • SCHEDULER: The schedule module.
    • EXTERNAL: The external table-related module.
    If no module is specified, BASE is used.
  • <query_statement>: The query statement whose query trace profile you want to obtain.

Use cases

Trace the time costs of a query

The following example traces the time costs of a query’s optimizer module.
In the Explain String returned by the TRACE TIMES statement, each row (except the last row) corresponds to an event in the specified module (stage) of the query. The last row Tracer Cost records the time cost of the tracing process. Take | 4ms| -- Transformer[1] 1ms as an example:
  • The left column records the time point, in the lifecycle of the query, when the event was first executed.
  • In the right column, following the consecutive hyphens is the name of the event, for example, Transformer.
  • Following the event name, the number in the brackets ([1]) indicates the number of times the event was executed.
  • The last part of this column is the overall time cost of the event, for example, 1ms.
  • The records of events are indented based on the depth of the method stack. That is to say, in this example, the first execution of Transformer always happens within Total.

Trace the variables of a query

The following example traces the variables & values of a query’s MV module.
The structure of the Explain String returned by the TRACE VALUES statement is similar to that of the TRACE TIMES statement, except that the right column records the variables and settings of the event in the specified module. The above example records that the materialized view is successfully used to rewrite the query.

Trace the logs of a query

The following example traces the logs of a query’s MV module.
Alternatively, you can print these logs in the FE log file fe.log by setting the variable trace_log_mode as follows:
The default value of trace_log_mode is command, indicating that the logs are returned as the Explain String as shown above. If you set its value to file, the logs are printed in the FE log file fe.log with the class name being FileLogTracer. After you set trace_log_mode to file, no logs will be returned when you execute the TRACE LOGS statement. Example:
The log will be printed in fe.log. img