Skip to content

Query Analysis


Query Analysis is a standalone analysis entry point in the Database module. It supports cross-instance aggregated query views. When you manage multiple database instances, you can identify system-level slow query bottlenecks from a global perspective without opening each instance detail page.

Supported Database Types

Query Analysis currently supports MySQL, PostgreSQL, Oracle, SQL Server, and MongoDB. After you switch the database type, the list reloads the query data of the corresponding instances for that type.


Purpose

Unlike the Explorer, which analyzes queries at the single-instance level, Query Analysis provides the following core capabilities:

  • Cross-instance aggregation: When the same business SQL is executed on multiple instances, it is automatically aggregated into global cumulative data, avoiding the need to troubleshoot instance by instance.
  • Similar query merging: The system automatically identifies similar SQL statements with different parameter values (such as WHERE id = 1 and WHERE id = 2) and merges them into the same query template for statistics, preventing the same statement from being scattered due to parameter differences.
  • Global performance ranking: Supports sorting by total duration, execution count, average duration, and other dimensions, so you can quickly identify global performance bottlenecks.

Page Layout

The Query Analysis page consists of a top action bar, left quick filters, a query list, and a details side panel.

Top Action Bar

Element Description
Database type selector Dropdown to switch between MySQL / PostgreSQL / Oracle / SQL Server / MongoDB. After switching, the list reloads for that type.
SQL template search Supports keyword search in SQL templates. Input limit: 512 bytes.
Total queries Shows the number of query templates under the current filter conditions.
Export Exports the current list page as a CSV file, a TXT file, or to a dashboard.
Display options Supports customizing which list columns are shown or hidden.

Left Quick Filters

Filter Dimension Description
Instance Name Multi-select; shows all instances of the database type.
Database Address Multi-select; filters by database connection address.
Total Duration Range filter.
Execution Count Range filter.
Time Range Linkage

The Query Analysis time range is linked to the global Time Widget. Both the list data and the trend charts in the details side panel are aggregated in real time based on the selected time window.


Query List

The list displays all aggregated query templates for the current time range and database type. Each record represents a class of SQL (with parameters replaced by ?) and aggregates execution data for that SQL class across all selected instances.

List Fields

Field Description
SQL Template SQL text after parameters are replaced by ?. The list displays at most 2 lines. Click to open the details side panel on the right.
Execution Count Cumulative execution count of this query type across all instances within the time range.
Average Duration Average execution time per execution of this query type.
Total Duration Cumulative execution time of this query type across all instances within the time range.
Performance Cost Share Percentage of the cumulative total time of this query type relative to the cumulative total time of all queries, visualized with a progress bar. The higher the percentage, the greater the impact of this query type on overall system performance.
Average Rows Scanned Average number of rows scanned/returned by this query type across all instances, used to evaluate the data scanning scope of the query.
Trend Mini line chart (Sparkline) of execution counts within the current time range, linked to the list page time range.
SQL Template vs. Raw SQL

SQL templates in the list have specific parameter values replaced by ?, so that you can focus on the statement structure. In the details side panel, you can view the most recent raw SQL sample for the template and copy the complete text with one click.


Query Details Side Panel

Click any row in the list. The query details side panel slides out from the right and displays global performance data for this query type. The side panel includes the following tabs:

Full SQL

The complete SQL template for this query type is fixed at the top of the side panel (parameters replaced by ?) and supports one-click copy.

Linked to the list page time range. Displays three core metrics of this query type as time series charts:

Chart Description
Execution Count executions/min; reflects the concurrency pressure trend of this query type.
Average Duration milliseconds (ms); reflects the per-execution efficiency trend of this query type.
Total Duration milliseconds (ms); reflects the time consumption trend of this query type in the overall system.

Each metric is displayed as an independent time series chart. You can select a time interval for filtering or export the chart.

Instances

Shows the execution distribution of this query type across instances, helping you identify where the bottleneck is concentrated.

Field Description
Database Address Connection address of the instance.
Instance Name Database instance identifier.
Execution Count Execution count of this query type on the instance, visualized with a progress bar.
Average Duration Average execution time of this query type on the instance.
Total Duration Cumulative execution time of this query type on the instance, visualized with a progress bar.
Average Rows Sent Average number of rows returned by this query type on the instance.
Error Count Number of failed executions of this query type on the instance.
  • Instance names are clickable and open the single-instance query details page for that instance in a new page (reusing the existing Explorer detail page).
  • You can filter by instance name or database address in the search box.

Users

Shows the execution distribution of this query type across database accounts.

Field Description
User Database account name.
Sample Count Number of executions of this query type by the user.
Average Duration Average execution time of this query type by the user.
  • You can filter by username in the search box.

Query Samples

Shows actual sampled records for this query type. Fields vary by database type.

MySQL Sample Fields:

Field Description
Time Timestamp when the sample occurred.
Database Target database (schema).
Execution Duration Actual execution time of the sample.
User Database account that executed the sample.
Wait Group Wait event group of the sample.
Sample Field Differences Across Databases

Sample display fields depend on the database type. For example, SQL Server shows fields such as Session ID, Wait Type, and CPU Time, while Oracle and PostgreSQL also show their native performance fields. The exact fields are determined by the actual page display.

Execution Plan

In the query list, open the details side panel of the target query and go to Execution Plan. The execution plan describes the execution approach chosen by the database optimizer for the query. Use it to identify issues such as full table scans, collection scans, improper index usage, or high join costs.

Supported Database Types

Execution Plan currently supports collection and display for MySQL, PostgreSQL, Oracle, SQL Server, and MongoDB. The execution plan is displayed only when execution plan collection is enabled in the current environment and the corresponding plan data has been collected.

To view a MongoDB execution plan, select MongoDB in the database type selector at the top, then open the target query details and go to Execution Plan.

Selecting an Execution Plan

The same query may use different execution plans on different database instances, and it may also have multiple plans on the same instance. Use the selector at the top of the page to switch between them. The options consist of instance name and plan identifier, for example, prod-sql-01 · 0x72AE91F3.

For SQL Server, the plan identifier is displayed as Plan Hash. When the Plan Hash of the same query changes, it usually means the database adopted a different execution strategy.

After selecting a plan, the page shows the database instance, database name, and plan identifier to which the plan belongs.

Usage Tips

We recommend first locating abnormal duration with Performance Trends and Instances, then opening the Execution Plan to inspect node dependencies and high-cost operations. The topology diagram is suitable for understanding the overall execution path, the node list is suitable for comparing node data, and the XML / JSON view is suitable for viewing the complete raw information returned by the database.

Topology Diagram

The topology diagram shows the database execution steps according to the node hierarchy in the execution plan. Lines between nodes represent node dependencies, not the actual execution timeline of the query.

Based on the data returned by the database, each node displays the following information:

  • Execution operation name.
  • Logical operation (displayed only when the original plan includes this field and it differs from the execution operation).
  • Table, collection, or index accessed.
  • Rows: number of rows the database optimizer expects the node to output.
  • Cost: relative cost of the current node and its child nodes.

You can zoom in, zoom out, drag, or fit the entire topology diagram into view. Hover over a node to view additional details such as execution operation, logical operation, accessed object, estimated rows read, filter conditions, Join conditions, or native database warnings. The page displays only fields that actually exist in the original plan.

Understanding Rows and Cost

Estimated Rows is the number of rows the database optimizer expects the node to output, not the actual number of rows processed. Node Cost is used to compare the relative costs of nodes within the same execution plan. It does not represent actual execution time and is not suitable for direct comparison across different databases.

Node List

The node list displays the node hierarchy of the execution plan in an indented format, making it easy to quickly compare accessed objects, estimated rows, and node cost across nodes. The order of the list expresses the hierarchy between nodes and does not represent the actual execution time order.

Field Description
Execution Step Execution operation name and node level returned by the database.
Accessed Object / Index Table, view, collection, or index accessed by the current node.
Estimated Rows Number of rows the database optimizer expects the node to output. When the original plan also includes rows read, output and read data are shown separately.
Node Cost Relative cost of the current node and its child nodes.

XML / JSON

The Raw View displays the complete execution plan captured by the collector and supports formatting, searching, copying, and downloading.

Database Raw Format Download Format
SQL Server XML Downloaded as .sqlplan when it conforms to ShowPlan XML format; other XML is downloaded as .xml.
MySQL JSON .json
PostgreSQL JSON .json
Oracle JSON .json
MongoDB JSON .json

The raw MongoDB execution plan is organized by stages. A common COLLSCAN indicates a collection scan, and IXSCAN indicates an index scan. Raw fields vary with the MongoDB version and query engine; the exact fields depend on the captured plan. For more field details, refer to MongoDB Explain Results.

Execution Plan Data Notes

Execution plans come from data already captured by the collector. Viewing a plan does not re-execute your query, and the page does not proactively run EXPLAIN or EXPLAIN ANALYZE. An execution plan may not have been generated within the time range currently selected on the page and may not correspond to a specific execution. Whether actual row counts and actual durations are included depends on the original plan returned by the database.


Metric Calculation

Aggregated metrics in Query Analysis are calculated as follows:

Metric Calculation
Execution Count Sum of execution counts of this query type across all instances.
Average Duration Total duration across all instances ÷ cumulative execution count across all instances.
Total Duration Sum of the duration of this query type across all instances.
Performance Cost Share Cumulative total duration of this query type ÷ cumulative total duration of all queries × 100%.
Average Rows Scanned Average of the average rows scanned for this query type across all instances.
Data Timeliness Notes

Query Analysis data is aggregated in real time based on the time range you select. If an instance has no data reported within the selected time range, it is not included in the aggregated results.