This skill requires hologres-cli to be installed first:
bash
pip install hologres-cli
export HOLOGRES_SKILL=hologres-query-optimizer
All SQL execution and GUC parameter operations depend on hologres-cli commands ( hologres sql run, hologres guc show/set).
This skill helps analyze and optimize Hologres SQL query execution plans using EXPLAIN and EXPLAIN ANALYZE commands.
Version Note: This documentation is based on Hologres V1.3.4x+. Upgrade your instance for better execution plan readability.
CommandDescriptionEXPLAIN <sql>Shows estimated execution plan from Query Optimizer (QO). Reference only.EXPLAIN ANALYZE <sql>Shows actual execution plan with real runtime metrics. Use for optimization.
sql
-- Estimated plan (no execution)
EXPLAIN SELECT * FROM my_table WHERE id > 100;
-- Actual plan with runtime metrics (executes query)
EXPLAIN ANALYZE SELECT * FROM my_table WHERE id > 100;
Read execution plans bottom-up. Each arrow ( ->) represents a node/operator.
ParameterDescriptioncostEstimated cost: startup_cost..total_cost. Parent includes child costs.rowsEstimated output rows. rows=1000 indicates missing statistics — run ANALYZE <table>.widthEstimated average output width (bytes).
EXPLAIN ANALYZE includes four sections: Query Plan, ADVICE, Cost, and Resource.
Format: [dop_in:dop_out id=X dop=N time=max/avg/min rows=total(max/avg/min) mem=max/avg/min open=X get_next=Y]
MetricDescriptiondop_in:dop_outParallelism ratio (e.g., 21:1 for gather, 21:21 for shuffle)dopActual parallelism degree (matches shard count)timeTotal time = open + get_next (ms). Cumulative from children.rowsOutput rows: total(max/avg/min). Large variance = data skew.memMemory: max/avg/min``openInitialization time. Hash operators build tables here.get_nextData fetch time. Called repeatedly until complete.
Important:
timeis cumulative. Current operator time = current time - child time.
System-generated suggestions:
Table xxx misses bitmap indexTable xxx Miss Stats! please run 'analyze xxx';shuffle data skew! max rows is X, min rows is YMetricDescriptionTotal costQuery total time (ms)Optimizer costQO plan generation timeStart query costPre-execution init (schema sync, locking)Get the first block costTime to first record batchGet result costTime to all results
Format: total(max_worker/avg_worker/min_worker)
MetricDescriptionMemoryTotal and per-worker memoryCPU timeCumulative CPU time across coresPhysical read bytesDisk reads (cache miss)Read bytesTotal reads (disk + cache)
For detailed operator reference, see references/operators.md.
OperatorDescriptionSeq ScanFull table scanIndex Scan using Clustering_indexColumn-store index scanIndex Seek (pk_index)Row-store primary key scan
OperatorDescriptionFilterNo index hit — add indexesSegment FilterSegment key hitCluster FilterClustering key hitBitmap FilterBitmap index hit
OperatorDescriptionLocal GatherMerge files within shardGatherMerge shards to final resultRedistributionData shuffle — check distribution_keyBroadcastSmall table broadcast to all shards
OperatorDescriptionHash JoinHash-based join (ensure small table is hash table)Nested LoopNested loop join ( avoid for large data)Cross JoinOptimized non-equi join (V3.0+)
OperatorDescriptionHashAggregateHash-based aggregationPartial/Final HashAggregateMulti-stage aggregation
OperatorDescriptionSortORDER BYLimitRow limit (check if pushed to scan)ExecuteExternalSQLPQE execution — rewrite for HQE
EXPLAIN ANALYZE on slow queryIssueSymptomSolutionMissing statsrows=1000``ANALYZE <table>Data shuffleRedistributionFix distribution_keyWrong hash tableLarge table as hashUpdate statisticsNo indexFilter onlyAdd clustering/bitmap indexPQE executionExecuteExternalSQLRewrite to HQE functionsData skewLarge max/min varianceReview distribution
sql
-- Multi-stage aggregation
SET optimizer_force_multistage_agg = on;
-- Join order control (for complex multi-table joins)
SET optimizer_join_order = 'query'; -- Follow SQL order
SET optimizer_join_order = 'greedy'; -- Greedy algorithm
-- Disable Cross Join
SET hg_experimental_enable_cross_join_rewrite = off;
To persist these settings at database level, use the CLI:
bash
hologres guc set optimizer_force_multistage_agg on
hologres guc set optimizer_join_order query
EXPLAIN ANALYZE for production analysisANALYZE after significant data changesdistribution_key based on JOIN/GROUP BY patternsclustering_key for range query columnsReferenceDescriptionreferences/operators.mdDetailed operator descriptionsreferences/optimization-patterns.mdCommon optimization patternsreferences/guc-parameters.mdQuery tuning parameters