← 返回 Skills 市场
wenbingyu

Hologres Query Optimizer

作者 francis · GitHub ↗ · v0.2.0 · MIT-0
cross-platform ✓ 安全检测通过
36
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install hologres-query-optimizer
功能描述
Hologres Query Execution Plan Analyzer and Optimizer. Use for analyzing SQL performance issues, understanding EXPLAIN/EXPLAIN ANALYZE output, interpreting qu...
使用说明 (SKILL.md)

Prerequisites

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).

Hologres Query Execution Plan Analyzer

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.

Overview

Command Description
EXPLAIN \x3Csql> Shows estimated execution plan from Query Optimizer (QO). Reference only.
EXPLAIN ANALYZE \x3Csql> Shows actual execution plan with real runtime metrics. Use for optimization.

Quick Start

-- 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;

Reading EXPLAIN Output

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 \x3Ctable>.
width Estimated average output width (bytes).

Reading EXPLAIN ANALYZE Output

EXPLAIN ANALYZE includes four sections: Query Plan, ADVICE, Cost, and Resource.

Query Plan Metrics

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: time is cumulative. Current operator time = current time - child time.

ADVICE Section

System-generated suggestions:

  • Missing indexes: Table xxx misses bitmap index
  • Missing statistics: Table xxx Miss Stats! please run 'analyze xxx';
  • Data skew: shuffle data skew! max rows is X, min rows is Y

Cost Breakdown

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

Resource Consumption

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)

Common Operators

For detailed operator reference, see references/operators.md.

Scan Operators

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

Filter Operators

Operator Description
Filter No index hit — add indexes
Segment Filter Segment key hit
Cluster Filter Clustering key hit
Bitmap Filter Bitmap index hit

Data Movement

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

Join Operators

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+)

Aggregation

Operator Description
HashAggregate Hash-based aggregation
Partial/Final HashAggregate Multi-stage aggregation

Other

Operator Description
Sort ORDER BY
Limit Row limit (check if pushed to scan)
ExecuteExternalSQL PQE execution — rewrite for HQE

Optimization Workflow

  1. Run EXPLAIN ANALYZE on slow query
  2. Check ADVICE section for immediate fixes
  3. Identify bottleneck operators (highest time)
  4. Apply targeted optimizations:
Issue Symptom Solution
Missing stats rows=1000 ANALYZE \x3Ctable>
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

Key GUC Parameters

-- 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

Best Practices

  1. Always use EXPLAIN ANALYZE for production analysis
  2. Run ANALYZE after significant data changes
  3. Design distribution_key based on JOIN/GROUP BY patterns
  4. Set clustering_key for range query columns
  5. Use bitmap indexes for low-cardinality filters
  6. Ensure small table is hash table in joins
  7. Avoid non-equi joins when possible
  8. Rewrite PQE functions to HQE alternatives

Reference Links

Reference Description
references/operators.md Detailed operator descriptions
references/optimization-patterns.md Common optimization patterns
references/guc-parameters.md Query tuning parameters
安全使用建议
This skill looks safe as documentation, but treat its commands as real database operations. Verify hologres-cli before installing it, use limited database credentials, and approve any EXPLAIN ANALYZE, ANALYZE, table-property, or persistent GUC command before it runs—especially in production.
功能分析
Type: OpenClaw Skill Name: hologres-query-optimizer Version: 0.2.0 The skill bundle is a legitimate tool for analyzing and optimizing Hologres SQL queries. It provides educational content, SQL examples, and instructions for using the 'hologres-cli' to tune database parameters. No evidence of malicious intent, data exfiltration, or harmful prompt injection was found; all files (SKILL.md and the reference documents) are strictly aligned with the stated purpose of query performance optimization.
能力评估
Purpose & Capability
The skill’s SQL analysis and optimization guidance is coherent with its stated purpose, but some recommendations involve executing queries and changing database tuning or table properties.
Instruction Scope
The instructions disclose that EXPLAIN ANALYZE executes the query and include reset examples for some persistent settings, but users should still explicitly approve any SQL execution or persistent database change.
Install Mechanism
The skill is instruction-only, but SKILL.md asks users to install and use hologres-cli even though the registry requirements list no required binaries or install spec.
Credentials
Using a Hologres CLI and database connection is proportionate for a query optimizer skill; users should run it with appropriately scoped database privileges.
Persistence & Privilege
Some documented GUC commands are explicitly database-level and persistent, which is expected for tuning but can affect future queries until reset.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install hologres-query-optimizer
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /hologres-query-optimizer 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.2.0
- Added comprehensive documentation covering Hologres query plan analysis, operator interpretation, and optimization strategies. - Introduced step-by-step workflow for reading EXPLAIN/EXPLAIN ANALYZE output with detailed metric and operator explanations. - Included recommendations and best practices for identifying and resolving common performance issues. - Provided guidance on key GUC parameters and their usage for SQL tuning. - Linked to in-depth operator and optimization references for further learning.
元数据
Slug hologres-query-optimizer
版本 0.2.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Hologres Query Optimizer 是什么?

Hologres Query Execution Plan Analyzer and Optimizer. Use for analyzing SQL performance issues, understanding EXPLAIN/EXPLAIN ANALYZE output, interpreting qu... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 36 次。

如何安装 Hologres Query Optimizer?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install hologres-query-optimizer」即可一键安装,无需额外配置。

Hologres Query Optimizer 是免费的吗?

是的,Hologres Query Optimizer 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Hologres Query Optimizer 支持哪些平台?

Hologres Query Optimizer 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Hologres Query Optimizer?

由 francis(@wenbingyu)开发并维护,当前版本 v0.2.0。

💬 留言讨论