Read 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:
text
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:
PatternTime-SeriesRelationalActionPartition Filter: tsGoodN/ATime pruning workingTag Filter: tag_colGoodN/AHash index hitSeq Scan in partitionNormalCheck sizeNormal for smallIndex ScanN/AGoodIndex being usedDistribute: ShuffleWarningVariesCross-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):
ParameterConfig GroupTrigger Conditionts.compress.stageCompression GroupUser wants compression optimization or smaller disk space usagets.compress.algorithmCompression GroupUser wants compression optimization or smaller disk space usagets.compress.levelCompression GroupUser wants compression optimization or smaller disk space usagets.rows_per_block.min_limitRows Per Block GroupUser reports excessive small blocks from flushing, long write visibility delay, or high per-device data volume with low compression ratiots.rows_per_block.max_limitRows Per Block GroupUser reports excessive small blocks from flushing, long write visibility delay, or high per-device data volume with low compression ratiots.compress.last_segment.enabledIndependentUser wants compression optimization or smaller disk space usage, or needs to optimize write performancets.block.lru_cache.max_limitIndependentUser wants to optimize overall query performance, or memory usage is too hights.last_cache_size.max_limitIndependentUser wants to optimize last-related SQL query performance, or memory usage is too hights.mem_segment_size.max_limitIndependentWrite 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_limitIndependentFrequent compaction triggers or disk space is tightts.compact.max_limitIndependentUser reports compaction backlog with significant CPU idle, or CPU usage is too hights.auto_vacuum.enabledIndependentUser wants to clean up datats.block_filter.sampling_ratioIndependentUser 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 automaticallymarkdown
## 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]
sql
[rewritten query]
[What should change in EXPLAIN]
sql
EXPLAIN (ANALYZE) [optimized query];
text
For configuration optimization output format, see `assets/config-output-template.md`.