EXPLAIN statement in TDSQL Boundless read-only analysis instances and how to interpret the returned execution plan, helping you evaluate query performance, identify execution bottlenecks, and guide optimization.EXPLAIN statement is used to view the execution plan of a query. The read-only analysis instance is compatible with the MySQL protocol. You can connect to the read-only analysis instance using any MySQL client and then execute the EXPLAIN statement. The returned plan describes the operator combination selected by the optimizer for the SQL, the data flow method, and the cost estimation. It can be used for:Syntax | Description | Whether SQL Is Actually Executed |
EXPLAIN <SQL> | View the execution plan in the default (BRIEF) format. | No |
EXPLAIN FORMAT='<format>' <SQL> | No | |
EXPLAIN ANALYZE <SQL> | Executes the SQL statement and includes the actual number of rows, actual cost, and time consumption for each operator in the plan. | Yes |
EXPLAIN ANALYZE statement actually executes the query. When the query is executed on a large table, estimate the resource consumption to avoid impacting online services.EXPLAIN statement is primarily used to view the execution plan of SELECT statements.FORMAT clause specifies the output format of the EXPLAIN statement. Common values are listed in the table below. For daily use, brief is recommended. Other values are typically used for diagnostics or tool integration scenarios.FORMAT Value | Output Format | Applicable Scenarios |
brief (Default) | Table, columns: ID, OPERATOR, NAME, EST.ROWS, DETAILS | Suitable for daily viewing of execution plans with concise column widths for readability. |
row | Table, columns: id, operator, rows estimate, cost estimate, task type, tables visited, details | A traditional output equivalent to brief, with all column names in lowercase. |
verbose | Table, with the same columns as row | Shares the same structure as row and is used when cost estimation is focused on. |
tree | Tree indentation format | Intuitively view the hierarchical relationships of operators. |
detail | Table, with the same columns as row | Contains more complete field details. |
hint | Hint text | Outputs applicable Hint suggestions for the current query. |
dot, json, traditional, true_card_cost, binary, and detail_no_idsuffix, which are primarily used for toolchain integration or internal debugging. For daily use, it is recommended to prioritize using brief.EXPLAIN ANALYZE outputs an additional row of stage time statistics above the plan and expands the operator column to eight columns. The stage time format is as follows:TotalTime (ns): <Total Time> ParseTime (ns): <Parse Time> CompileTime (ns): <Compile Time> OptimizationTime (ns): <Optimization Time> WaitTimestampTime (ns): <Wait Timestamp Time>
Column Name | Description |
ID | Sequence number of the operator in the plan. |
OPERATOR | Operator type. |
NAME | The object on which the operator acts, such as table name, Join type, and so on. |
EST.ROWS | Estimated number of output rows by the optimizer. |
ACT.ROWS | Actual number of output rows. |
ACT.OUTPUTSIZE | Actual output size in bytes. |
EST.COST | Estimated cost by the optimizer. |
ACT.COST | Actual cost (including the proportion of execution time). |
EST.ROWS with ACT.ROWS, you can quickly identify execution plan issues caused by statistical information deviation or selectivity estimation errors.Column Name | Description |
ID | Sequence number of the operator in the plan, numbered in depth-first order from root to leaf. |
OPERATOR | Operator type, such as HASH JOIN, TABLE FULL SCAN, EXCHANGE SENDER, and so on. |
NAME | The object on which the operator acts, such as table name ( TABLE FULL SCAN displays the table name), Join type abbreviation, and so on. |
EST.ROWS | Estimated number of output rows by the optimizer based on statistics. |
DETAILS | Detailed information of the operator, such as filter conditions, grouping keys, Join equality conditions, sorting keys, Runtime Filter, and so on. The fields vary for each operator. For details, see the Operator Details section. |
HASH JOIN operator, the ID column is appended with a suffix to identify the role that child node plays in the Hash Join.Suffix | Description |
(B) | The Build side. Hash Join first scans the data from the Build side and builds a hash table. |
(P) | The Probe side. Hash Join uses each row from the Probe side to probe the hash table and obtain matching results. |
HASH_JOIN_BUILD and HASH_JOIN_PROBE hints. For details, see the Optimizer Hint section.Category | Operator | Description |
Scan | TABLE FULL SCAN | Performs a full table scan on columnar data. It is the most common scan operator in Libr. |
Scan | COLUMN READ | Reads columnar data on demand. It is a columnar read operator that fetches only the columns required for computation. |
Scan | REMOTE READER* | A remote read operator. It appears when SQL involves TDSQL row-based data, pushes down the sub-plan to TDSQL row-based storage for execution, and then returns the result. |
Scan | INDEX FULL SCAN* | Performs a full index scan. It usually appears in the REMOTE READER subtree. |
Scan | INDEX RANGE SCAN* | Performs an index range scan. It usually appears in the REMOTE READER subtree. |
Join | HASH JOIN | Performs a hash join. Depending on the join type, it can be displayed as HASH JOIN, HASH OUTER JOIN, HASH RIGHT OUTER JOIN, HASH SEMI JOIN, or HASH NA-SEMI JOIN (NA stands for Null-Aware). |
Join | MERGE JOIN* | Performs a merge join. It requires that inputs from both sides be ordered by the join key. |
Aggregation | HASH GROUP BY | Performs grouping and aggregation based on a hash table. |
Aggregation | MERGE GROUP BY* | Performs streaming aggregation on ordered input. |
Sorting and throttling | SORT | Sorting operator. |
Sorting and throttling | TOPN | Retrieves the top N rows. It is equivalent to a sorting operation with LIMIT and is generally more efficient than SORT + LIMIT. |
Sorting and throttling | LIMIT | Limits the number of rows returned. |
Projection and filtering | PROJECTION | Projection operator. It outputs a list of expressions. |
Projection and filtering | FILTER | Filter operator. It corresponds to conditions in SQL such as WHERE and HAVING. |
Set and window | UNION | Merges multiple input streams. |
Set and window | WINDOW FUNCTION | Window function operator. |
Distributed exchange | EXCHANGE SENDER | The MPP data exchange sender sends data to upstream nodes. |
Distributed exchange | EXCHANGE RECEIVER | The MPP data exchange receiver receives data from downstream nodes. |
Distributed exchange | LOCAL SHUFFLE* | Redistributes data within a node using multiple threads. |
Materialization and CTE | MATERIAL* | Materializes intermediate results. |
Materialization and CTE | RECURSIVE UNION* | Recursive CTE. |
Materialization and CTE | CTE MATERIAL* | CTE materialization result. |
Materialization and CTE | CTE FULL SCAN* | Reads materialized CTE results. |
DETAILS column. Which specific fields appear depends on the actual configuration of that operator.Field | Description |
STORAGE | The storage engine type. Its value is LIBRASTORE (columnar analytics engine) or TDSQL (TDSQL row store). |
TABLE NAME | The name of the table being scanned. |
TABLE ALIAS | The alias specified for the table in the SQL statement, if any. |
ACCESS COLUMN | The list of column names actually read. Libra is a columnar store and reads only the columns required for computation. |
BLOCK OFFSET | The offset information of columnar data blocks is automatically managed by the system, and users do not need to be concerned about it. |
Partitions | The list of partitions actually hit, if any. |
KEEP ORDER | Whether to keep ordered output. |
DESC | Whether to scan in reverse order. |
COMPLETE PIPELINE | Whether to perform a complete pipeline scan. |
PROBE RUNTIME FILTERS | The list of Runtime Filters on the Probe side. A Runtime Filter is a filter constructed by Hash Join on the Build side and pushed down to the scan or upper-level operators on the Probe side to filter data in advance, thereby reducing subsequent computational load. |
Field | Description |
EQUAL | A list of equality join conditions, for example, [eq(t1.a, t2.a)]. |
OTHER COND | Other join/filter conditions. |
BUILD RUNTIME FILTERS | A list of Runtime Filters constructed on the Build side, which is pushed down to the scan or Filter operators on the Probe side. |
PROBE RUNTIME FILTERS | A list of Runtime Filters from the upstream Probe side (if any). |
JOIN TYPE field. The join type is directly reflected in the operator name, such as HASH JOIN, HASH OUTER JOIN, HASH SEMI JOIN, or HASH NA-SEMI JOIN. The NON EQUAL/JOIN TYPE fields are output only in the DETAILS section of the Apply (correlated subquery) operator.Field | Description |
EXCHANGE TYPE | Data exchange type. For its values and meanings, refer to the following table. |
HASH COLS | The list of columns used for hash distribution when EXCHANGE TYPE is HASH. |
PARTITION DISTRIBUTION | Distribution information based on partition distribution when EXCHANGE TYPE is HASH (BY PARTITION). |
EXCHANGE TYPE are as follows.Value | Full Name | Meaning |
PASS | PassThrough | Directly passes through data without redistributing it. |
BCJ | Broadcast | Broadcast mode, which replicates data to all upstream nodes and is commonly used for small-table Broadcast Join. |
HASH | HashPartition | Distributes data after data is hashed based on specified columns, commonly used for data redistribution in large-table Hash Join. |
HASH (BY PARTITION) | Partition Key(HASH) | Distributes data based on the hash value of the partition key, causing data from the same partition to be gathered on the same node. |
KEEP ORDER field is additionally output.Field | Description |
group by | List of grouping columns. |
funcs | List of aggregate functions, for example, count(*), sum(t.a). |
Field | Description |
Sort Key List | List items in order of sorting priority, each of which can be accompanied by asc or desc. |
OFFSET | The offset for TOPN. |
COUNT | The number of records retrieved by TOPN. |
Field | Description |
offset | Number of rows to skip. |
count | Number of rows returned. |
[gt(t.a, 10)].WINDOW FUNC DESCS (window function description), PARTITION BY columns, ORDER BY columns, window Frame definition, and more./*+ ... */ comment block that follows the SELECT keyword.Hint | Feature |
HASH_JOIN(t1, t2) | Forces t1 and t2 to use Hash Join. |
HASH_JOIN_BUILD(t) | Specifies t as the Build side of Hash Join. |
HASH_JOIN_PROBE(t) | Specifies t as the Probe side of Hash Join. |
MERGE_JOIN(t1, t2) | Forces the use of Merge Join. |
INL_JOIN(t1, t2) | Forces the use of Index Nested Loop Join. |
INL_HASH_JOIN(t1, t2) | Forces the use of Index Hash Join. |
INL_MERGE_JOIN(t1, t2) | Forces the use of Index Merge Join. |
USE_HASH(t1, t2) | Prompts the optimizer to prioritize Hash Join. |
NO_USE_HASH(t1, t2) | Prompts the optimizer not to select Hash Join for t1 and t2. |
PX_JOIN_FILTER(id [, type]) | Forces the generation of a Runtime Filter for the specified Join (that is, a pre-filter constructed on the Build side). |
NO_PX_JOIN_FILTER(id [, type]) | Prohibits the generation of a Runtime Filter for the specified Join. |
SEMI_JOIN_REWRITE() | Enables Semi Join rewrite optimization. |
INL_JOIN, INL_HASH_JOIN, INL_MERGE_JOIN, and MERGE_JOIN, may not be adopted under the columnar execution path. Please refer to the actual output of EXPLAIN.t2 table as the Probe side of a Hash Join:SELECT /*+ HASH_JOIN_PROBE(t2) */ *FROM t1 JOIN t2 ON t1.id = t2.id;
EXPLAIN, you can observe in the ID column of the plan that the t2 subtree has the (P) suffix and the t1 subtree has the (B) suffix, thereby verifying that the Hint has taken effect.EXPLAINSELECT t1.name, COUNT(*)FROM t1 JOIN t2 ON t1.id = t2.idWHERE t2.region = 'cn'GROUP BY t1.nameORDER BY COUNT(*) DESCLIMIT 10;
TOPN: It is equivalent to ORDER BY ... LIMIT 10, retaining only the top 10 rows while performing sorting operations.PROJECTION: It projects the grouped results into the final output columns.HASH GROUP BY: It groups the data by t1.name and performs COUNT(*).EXCHANGE RECEIVER / EXCHANGE SENDER: It redistributes data by hashing t1.name to facilitate parallel grouping and aggregation.HASH JOIN: It performs a join based on t1.id = t2.id. The ID columns of its child nodes are appended with the (B) and (P) suffixes, respectively.TABLE FULL SCAN: It scans the t1 and t2 tables respectively. The STORAGE column displays LIBRASTORE, and the ACCESS COLUMN contains only the columns that actually participate in the computation. The t2 table may have the PROBE RUNTIME FILTERS field attached, indicating that the Runtime Filter built by the Hash Join on the Build side has been pushed down to this Probe side for pre-filtering.EXPLAIN ANALYZE, you can compare whether EST.ROWS and ACT.ROWS are close, thereby determining the accuracy of the statistics. If a significant deviation exists, execute ANALYZE TABLE to collect the latest statistical information.Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários