agent-skills/skills/hologres-query-optimizer/SKILL.md
Hologres Query Execution Plan Analyzer and Optimizer. Use for analyzing SQL performance issues, understanding EXPLAIN/EXPLAIN ANALYZE output, interpreting query operators, and providing optimization recommendations for Hologres queries. Triggers: "hologres explain", "query plan", "execution plan", "sql optimization", "query performance", "hologres performance", "slow query", "query optimizer", "explain analyze"
npx skillsauth add aliyun/hologres-ai-plugins hologres-query-optimizerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill requires hologres-cli to be installed first:
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.
| Command | Description |
|---------|-------------|
| EXPLAIN <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. |
-- 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.
| Parameter | Description |
|-----------|-------------|
| cost | Estimated cost: startup_cost..total_cost. Parent includes child costs. |
| rows | Estimated output rows. rows=1000 indicates missing statistics — run ANALYZE <table>. |
| width | Estimated 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]
| Metric | Description |
|--------|-------------|
| dop_in:dop_out | Parallelism ratio (e.g., 21:1 for gather, 21:21 for shuffle) |
| dop | Actual parallelism degree (matches shard count) |
| time | Total time = open + get_next (ms). Cumulative from children. |
| rows | Output rows: total(max/avg/min). Large variance = data skew. |
| mem | Memory: max/avg/min |
| open | Initialization time. Hash operators build tables here. |
| get_next | Data 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 Y| Metric | Description | |--------|-------------| | Total cost | Query total time (ms) | | Optimizer cost | QO plan generation time | | Start query cost | Pre-execution init (schema sync, locking) | | Get the first block cost | Time to first record batch | | Get result cost | Time to all results |
Format: total(max_worker/avg_worker/min_worker)
| Metric | Description | |--------|-------------| | Memory | Total and per-worker memory | | CPU time | Cumulative CPU time across cores | | Physical read bytes | Disk reads (cache miss) | | Read bytes | Total reads (disk + cache) |
For detailed operator reference, see references/operators.md.
| Operator | Description | |----------|-------------| | Seq Scan | Full table scan | | Index Scan using Clustering_index | Column-store index scan | | Index Seek (pk_index) | Row-store primary key scan |
| Operator | Description | |----------|-------------| | Filter | No index hit — add indexes | | Segment Filter | Segment key hit | | Cluster Filter | Clustering key hit | | Bitmap Filter | Bitmap index hit |
| Operator | Description | |----------|-------------| | Local Gather | Merge files within shard | | Gather | Merge shards to final result | | Redistribution | Data shuffle — check distribution_key | | Broadcast | Small table broadcast to all shards |
| Operator | Description | |----------|-------------| | Hash Join | Hash-based join (ensure small table is hash table) | | Nested Loop | Nested loop join (avoid for large data) | | Cross Join | Optimized non-equi join (V3.0+) |
| Operator | Description | |----------|-------------| | HashAggregate | Hash-based aggregation | | Partial/Final HashAggregate | Multi-stage aggregation |
| Operator | Description | |----------|-------------| | Sort | ORDER BY | | Limit | Row limit (check if pushed to scan) | | ExecuteExternalSQL | PQE execution — rewrite for HQE |
EXPLAIN ANALYZE on slow query| Issue | Symptom | Solution |
|-------|---------|----------|
| Missing stats | rows=1000 | ANALYZE <table> |
| Data shuffle | Redistribution | Fix distribution_key |
| Wrong hash table | Large table as hash | Update statistics |
| No index | Filter only | Add clustering/bitmap index |
| PQE execution | ExecuteExternalSQL | Rewrite to HQE functions |
| Data skew | Large max/min variance | Review distribution |
-- 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:
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 columns| Reference | Description | |-----------|-------------| | references/operators.md | Detailed operator descriptions | | references/optimization-patterns.md | Common optimization patterns | | references/guc-parameters.md | Query tuning parameters |
development
Hologres Knowledge Base Management: Build search & RAG knowledge bases on Hologres using full-text inverted index (Tantivy + BM25), HGraph vector index, and holo-search-sdk. Covers create knowledge base → ingest documents (with embeddings) → vector / full-text / hybrid search → Q&A with LLM. Triggers: "知识库", "knowledge base", "RAG", "向量检索", "vector search", "全文检索", "fulltext search", "倒排索引", "BM25", "HGraph", "holo-search-sdk", "embedding", "混合检索", "hybrid search", "Hologres 搜索", "Hologres search", "tantivy", "jieba", "ik 分词", "向量索引"
tools
Hologres 实例内存使用率异常诊断技能。当用户提到内存打满、OOM、内存持续高位、Worker 内存不均、内存泄漏、内存倾斜、内存归因分析等场景时使用。 以 instance_id + 时间窗口为输入,自动完成内存水位形态判定(全局高 / 局部倾斜 / 持续不回落)、业务指标对齐、内存分类初筛(Query vs System/Cache)、 并沿 Query 主线、倾斜主线、Write/后台主线、System/元数据主线四大归因维度自动下钻,输出结构化的 Markdown 诊断报告与治理行动清单。 云监控数据通过 `hologres metric query` / `hologres metric latest` 获取;元仓与 PG 系统表数据通过 `hologres sql run` 获取; 内部工具数据(OOM/Jeprof/Coredump)通过 `holo oncall common` 获取,全程享有 hologres-cli 的安全护栏、JSON 结构化输出与自动错误重试能力。
tools
Hologres 实例 CPU 使用率异常诊断技能。当用户提到 CPU 打满、CPU 持续高位、Worker CPU 不均、负载诊断、CPU 归因分析、后台 Compaction 干扰等场景时使用。 以 instance_id + 时间窗口为输入,自动完成 CPU 状态分级(持续打满 / 持续高位 / 安全平稳)、四象限归因诊断(宏观定性 / 分布定位 / 查询归因 / 后台任务干扰),并输出结构化的 Markdown 诊断报告与治理行动清单。 云监控数据通过 `hologres metric query` / `hologres metric latest` 获取;元仓与 PG 系统表数据通过 `hologres sql run` 获取,全程享有 hologres-cli 的安全护栏、JSON 结构化输出与自动错误重试能力。
data-ai
Hologres 运维诊断日报生成技能。生成一份包含"诊断结论 + 根因解释 + 行动建议"的每日巡检报告, 覆盖实例健康、可用性、计算资源、SQL性能、成本治理、容量预测六大维度。 触发词:日报、每日巡检、daily report、运维日报、诊断日报、实例巡检报告、每日健康报告。