Part of #85 (Self-optimizing index system)
Depends on #87 (Phase 2: Semi-automatic)
Goal
Fully automatic cycle: analyze slow queries, create indexes, evaluate, rollback — without human intervention.
Design
Automatic cycle
Background worker (daemon thread or cron-like via startup handler):
- Check
pgcatalog_slow_queries every N minutes (configurable)
- For each pattern with count >= min_occurrence (default 10):
- Skip if already has a managed index (verified or blocked)
- Generate suggestion via Phase 1 smart suggestions
- Check index budget (max N auto-indexes, default 10)
- Create index via
CREATE INDEX CONCURRENTLY
- Evaluate pending indexes after evaluation period
- Rollback failures, verify successes
Leader election
Multiple pods must not create the same index simultaneously:
- PG advisory lock before auto-index creation
- Only one pod wins the lock and creates
- Others skip that cycle
Index budget
Total auto-created indexes is bounded:
- Default max 10 (configurable via
PGCATALOG_AUTO_INDEX_BUDGET)
- When budget is full, only create if new suggestion has higher estimated impact than lowest-impact existing auto-index
- Consider: swap lowest-impact verified index for higher-impact new one
Re-evaluation triggers
- After GenericSetup catalog.xml import (new/removed indexes)
- After pack (table statistics change)
- Manual "Re-evaluate all" button in ZMI
- Configurable periodic re-evaluation (monthly?)
Audit trail
All actions logged to pgcatalog_managed_indexes with timestamps:
- Created, evaluated, verified, rolled_back, blocked, unblocked
- Before/after performance metrics
- Human-readable notes
Migration of hardcoded composites
- Import existing hardcoded composites as "locked" managed indexes
- Status=verified, blocked=true (auto-system doesn't touch them)
- Over time, admin can unlock individual ones for re-evaluation
Deliverables
- Background worker with configurable interval
- Leader election via PG advisory lock
- Index budget with impact-based eviction
- Re-evaluation triggers (GenericSetup, pack, manual)
- Full audit trail
- Migration of hardcoded composites to managed indexes
- Documentation
Part of #85 (Self-optimizing index system)
Depends on #87 (Phase 2: Semi-automatic)
Goal
Fully automatic cycle: analyze slow queries, create indexes, evaluate, rollback — without human intervention.
Design
Automatic cycle
Background worker (daemon thread or cron-like via startup handler):
pgcatalog_slow_queriesevery N minutes (configurable)CREATE INDEX CONCURRENTLYLeader election
Multiple pods must not create the same index simultaneously:
Index budget
Total auto-created indexes is bounded:
PGCATALOG_AUTO_INDEX_BUDGET)Re-evaluation triggers
Audit trail
All actions logged to
pgcatalog_managed_indexeswith timestamps:Migration of hardcoded composites
Deliverables