SQL pre-analysis is used to assess the risk of an SQL execution plan and can also provide tuning suggestions for existing SQL statements.
When to use
Assess whether the execution plan of a new SQL statement poses risks.
Improve the execution efficiency of an existing SQL statement by obtaining actionable index or rewrite suggestions.
Determine whether an SQL statement will trigger a full table scan.
Prerequisites
You have configured an OAS connection for the product of the target cluster.
You know the name of the database containing the SQL statement to be analyzed.
Procedure
Type
@in the session to select the target cluster (the tenant is optional; specifying a tenant narrows the analysis scope).Provide the SQL text to be analyzed and its corresponding database, for example:
Analyze the execution plan of the following SQL statement in the test database to check for risks: SELECT * FROM t_order WHERE create_time > '2026-01-01';Press Enter to send the request and wait for the Agent to complete the analysis.
The Agent performs an EXPLAIN pre-analysis on the SQL statement to obtain the execution plan and the structure and statistics of related tables.
View the analysis results.
The output from the Agent typically includes the following sections:
Execution Plan: The operator tree and access path of the SQL statement.
Risk Points: For example, full table scan, missing indexes, or non-pushdown filter conditions.
Tuning Suggestions: Directly actionable optimization steps, such as recommended new index definitions.
Note
Pre-analysis only executes an EXPLAIN and does not actually run the SQL statement. However, the tuning suggestions, such as index recommendations, provided by the Agent are change operations. You must evaluate them and follow your enterprise's change process to implement them.
Considerations
When providing SQL text, please include the name of the database to which it belongs. Otherwise, the Agent cannot locate the table schema and statistics.
If the SQL contains bind variables, it is recommended to replace them with representative actual values to obtain a more accurate cost estimate.
Before adopting index or rewrite suggestions, evaluate the maintenance cost based on the business write volume, and execute the changes within the change window according to your enterprise's change process.
What to do next
To understand the meaning of each operator in an execution plan, see Interpretation of execution plans.
If the estimated number of rows differs significantly from the actual number of rows, it usually indicates that the statistics are outdated. You can proceed with statistics diagnostics. For more information, see Statistics diagnostics.
To export the analysis results to a report, see Export a report.