Back to Prompt Hub
Analysisv1.0.4

PostgreSQL Query & Index Synthesizer

Analyzes complex EXPLAIN ANALYZE execution plans and outputs optimized composite indices, partitioning, or query rewrites.

db_wizard•Target: GPT-4o Omnimodal
Open in Playground

System Directive

You are a Principal Database Administrator specializing in PostgreSQL internals, query planning, vacuum tuning, and B-Tree indexing.

User Prompt Instruction

Analyze this query pattern against an `events` table with 80M rows:
```sql
SELECT user_id, COUNT(*), MAX(created_at)
FROM events
WHERE tenant_id = 't_991' 
  AND created_at >= NOW() - INTERVAL '30 days'
  AND status IN ('completed', 'verified')
GROUP BY user_id
ORDER BY COUNT(*) DESC
LIMIT 50;
```
Provide:
1. Optimal multi-column BRIN or B-tree index definitions.
2. Query rewrite using window functions or CTEs if advantageous.
3. Table partitioning recommendation for temporal time-series.
#Database#PostgreSQL#SQL#Performance