- Identify bottlenecks and expensive operations
- Spot suboptimal join strategies or missing indexes
- Understand how data is filtered, aggregated, and moved
- Troubleshoot and optimize resource usage
-
EXPLAIN statement:
UseEXPLAINto display the logical or physical execution plan for a query. You can add options to control the output:EXPLAIN LOGICAL <query>: Shows the simplified plan.EXPLAIN <query>: Shows the basic physical planEXPLAIN VERBOSE <query>: Shows the physical plan with detailed information.EXPLAIN COSTS <query>: Includes estimated costs for each operation, which is used to diagnose the statistics issue
-
EXPLAIN ANALYZE:
UseEXPLAIN ANALYZE <query>to execute the query and display the actual execution plan along with real runtime statistics. See the Explain Analyze documentation for details. Example: -
Query Profile:
After running a query, you can view its detailed execution profile, which includes timing, resource usage, and operator-level statistics. See the Query Profile documentation for how to access and interpret this information.- SQL commands:
SHOW PROFILELISTandANALYZE PROFILE FOR <query_id>: can be used to retrieve the execution profile for a specific query. - FE HTTP Service: Access query profiles via the database FE web UI by navigating to the Query or Profile section, where you can search for and inspect query execution details.
- Managed Version: In cloud or managed deployments, use the provided web console or monitoring dashboard to view query plans and profiles, often with enhanced visualization and filtering options.
- SQL commands:
Query execution flow
The lifecycle of a query in the database consists of three main phases:- Planning: The query undergoes parsing, analysis, and optimization, culminating in the generation of a query plan.
- Scheduling: The scheduler and coordinator distribute the plan to all participating backend nodes.
- Execution: The plan is executed using the pipeline execution engine.

- Fragment: Top-level slice of work; each fragment spawns multiple FragmentInstances that run on different backend nodes.
- Pipeline: Within an instance, a pipeline strings operators together; several PipelineDrivers run the same pipeline concurrently on separate CPU cores.
- Operator: The atomic step—scan, join, aggregate—that actually processes data.


- Fragment
- Pipeline
- Operator
pipeline_profile_level.
Example
How to read a query plan and profile
- Understand the structure: Query plans are split into fragments, each representing a stage of execution. Read from the bottom up: scan nodes first, then joins, aggregations, and finally the result.
-
Overall analysis:
- Check total runtime, memory usage, and CPU/wall time ratio.
- Find slow operators by sorting by operator time.
- Ensure filters are pushed down where possible.
- Look for data skew (uneven operator times or row counts).
- Monitor for high memory or disk spill; adjust join order or use rollup views if needed.
- Use materialized views and query hints (
BROADCAST,SHUFFLE,COLOCATE) to optimize as needed.
-
Scan operations: Look for
OlapScanNodeor similar. Note which tables are scanned, what filters are applied, and if pre-aggregation or materialized views are used. -
Join operations: Identify join types (
HASH JOIN,BROADCAST,SHUFFLE,COLOCATE,BUCKET SHUFFLE). The join method affects performance:- Broadcast: Small table sent to all nodes; good for small tables.
- Shuffle: Rows are partitioned and shuffled; good for large tables.
- Colocate: Tables partitioned the same way; enables local joins.
- Bucket Shuffle: Only one table is shuffled to reduce network cost.
-
Aggregation and sorting: Look for
AGGREGATE,TOP-N, orORDER BY. These can be expensive with large or high-cardinality data. -
Data movement:
EXCHANGEnodes show data transfer between fragments or nodes. Too much data movement can hurt performance. -
Predicate pushdown: Filters applied early (at scan) reduce downstream data. Check
PREDICATESorPushdownPredicatesto see which filters are pushed down.
Example query plan
Tip This is query 96 from the TPC-DS benchmark.-
Scan Operations (Bottom Level): The
SCANoperators at the bottom read data from the base tables:SCAN [store_sales]reads the main fact table with predicatess_hdemo_sk IS NOT NULLSCAN [time_dim]reads the time dimension table with predicatest_hour = 8 AND t_minute >= 30SCAN [household_demographics]reads the demographics table with predicatehd_dep_count = 5SCAN [store]reads the store table with predicates_store_name = 'ese'
- Estimates: Row count, CPU, memory, network, and cost estimates
- Partition and tablet ratios: How many partitions/tablets are scanned (e.g.,
partitionRatio: 1/1, tabletRatio: 192/192) - Predicates: Query conditions that are pushed down to the scan level, reducing the amount of data read
-
Data Exchange (Broadcast): The
EXCHANGE(BROADCAST)operations distribute smaller dimension tables to all nodes processing the larger fact table. This is efficient when dimension tables are small compared to the fact table, as seen withtime_dim,household_demographics, andstorebeing broadcast. -
Join Operations (Middle Level): Data flows upward through
HASH/INNER JOINoperations:- First,
store_salesis joined withtime_dimonss_sold_time_sk = t_time_sk - Then, the result is joined with
household_demographicsonss_hdemo_sk = hd_demo_sk - Finally, the result is joined with
storeonss_store_sk = s_store_sk
- First,
-
Aggregation (Upper Level):
AGGREGATE(LOCAL)performs local aggregation on each node, computingcount()EXCHANGE(GATHER)collects results from all nodesAGGREGATE(GLOBAL)merges the local results into the final count
-
Final Operations (Top Level):
TOP-100(PARTIAL)andTOP-100(FINAL)operations handle theORDER BY count(*) LIMIT 100clause, selecting the top 100 results after ordering
EXPLAIN or EXPLAIN VERBOSE) includes additional details about how operations are distributed across nodes and executed in parallel.