Install
openclaw skills install @kwdb/kwdb-performance-reviewOptimize SQL query performance for KaiwuDB time-series and relational engines. Covers: EXPLAIN analysis, time-series optimization, pagination, cross-model queries. Trigger keywords: optimize query, slow query, explain, execution plan, performance, 性能, 查询优化. NOT for: DDL, schema design, deployment, DML writes.
openclaw skills install @kwdb/kwdb-performance-reviewRead the required reference files first.
Tier 1 (Always Read)
references/key-rules.md - Core engine differences and anti-patternsreferences/query-analysis.md - EXPLAIN output interpretationTier 2 (High-Frequency Optimization)
references/timeseries-optimization.md - Time-series query patternsreferences/pagination-optimization.md - Cursor-based paginationTier 3 (Medium-Frequency)
references/relational-optimization.md - B-tree indexes, join optimizationreferences/cross-model-optimization.md - Hybrid query optimizationTier 4 (Low-Frequency)
references/schema-tuning.md - Partition interval, TTL, encodingreferences/index-analysis.md - Index review for relational tablesreferences/config-optimization.md - Storage configuration parameter optimizationShould trigger:
Should NOT trigger:
Before optimizing, determine which engine the query targets:
TIME SERIES TABLE:
- Has ts_column, primary_tags in CREATE TABLE
- Cannot have secondary indexes
- Query must include time range filter
- Primary tag filter uses hash index
RELATIONAL TABLE:
- Standard SQL table
- Can have B-tree, inverted indexes
- Standard SQL optimization applies
Ask user if unclear.
Key indicators to look for:
| Pattern | Time-Series | Relational | Action |
|---|---|---|---|
| Partition Filter: ts | Good | N/A | Time pruning working |
| Tag Filter: tag_col | Good | N/A | Hash index hit |
| Seq Scan in partition | Normal | Check size | Normal for small |
| Index Scan | N/A | Good | Index being used |
| Distribute: Shuffle | Warning | Varies | Cross-node traffic |
Time-Series Critical Issues:
Relational Issues:
Always provide:
Include EXPLAIN (ANALYZE) to verify the optimization works.
Only activate when:
Per-Parameter Trigger (review on demand, not full scan):
| Parameter | Config Group | Trigger Condition |
|---|---|---|
| ts.compress.stage | Compression Group | User wants compression optimization or smaller disk space usage |
| ts.compress.algorithm | Compression Group | User wants compression optimization or smaller disk space usage |
| ts.compress.level | Compression Group | User wants compression optimization or smaller disk space usage |
| ts.rows_per_block.min_limit | Rows Per Block Group | User reports excessive small blocks from flushing, long write visibility delay, or high per-device data volume with low compression ratio |
| ts.rows_per_block.max_limit | Rows Per Block Group | User reports excessive small blocks from flushing, long write visibility delay, or high per-device data volume with low compression ratio |
| ts.compress.last_segment.enabled | Independent | User wants compression optimization or smaller disk space usage, or needs to optimize write performance |
| ts.block.lru_cache.max_limit | Independent | User wants to optimize overall query performance, or memory usage is too high |
| ts.last_cache_size.max_limit | Independent | User wants to optimize last-related SQL query performance, or memory usage is too high |
| ts.mem_segment_size.max_limit | Independent | Write performance optimization (after ts.compress.last_segment.enabled reviewed), or memory usage is too high (after ts.block.lru_cache.max_limit and ts.last_cache_size.max_limit reviewed) |
| ts.reserved_last_segment.max_limit | Independent | Frequent compaction triggers or disk space is tight |
| ts.compact.max_limit | Independent | User reports compaction backlog with significant CPU idle, or CPU usage is too high |
| ts.auto_vacuum.enabled | Independent | User wants to clean up data |
| ts.block_filter.sampling_ratio | Independent | User reports poor query performance with range conditions or null checks, suspects inefficient filter pushdown |
Decision Tree:
Pre-conditions (confirm relevant resources before suggesting):
Read references/config-optimization.md for detailed parameter guidance.
See assets/example-configs.md for configuration tuning examples.
Config query approach:
mcp__kwdb__read-query("SHOW CLUSTER SETTING ts.xxx")SHOW CLUSTER SETTING ts.xxx;SHOW CLUSTER SETTINGSImportant:
SET CLUSTER SETTING automatically## Intent
[Brief description of the optimization goal]
## Engine Type
[time-series / relational / mixed]
## Anti-Pattern Detected
[What was causing the slowness]
## Original Query
```sql
[query before optimization]
[rewritten query]
[What should change in EXPLAIN]
EXPLAIN (ANALYZE) [optimized query];
For configuration optimization output format, see `assets/config-output-template.md`.