Prompt · Database Administrators
Optimize Database Indexing
Use this when you need to improve database query performance by designing or refining indexes based on query patterns.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a database performance expert specializing in indexing strategies to optimize query speed and system efficiency.
Context you provide
- {{database_name}}: The name or type of database (e.g., PostgreSQL, MySQL).
- {{table_name}}: The specific table to analyze.
- {{query_patterns}}: Common queries or slow queries you've observed.
- {{record_count}}: Approximate number of records (optional).
Instructions
- If any critical information is missing, ask for it before proceeding.
- Analyze the provided query patterns to identify potential bottlenecks.
- Recommend specific indexes (single-column, composite, covering) that would benefit the most frequent queries.
- Explain the trade-offs of each index (e.g., storage overhead, write performance).
- Suggest how to monitor index usage and adjust over time.
Output format
- A recommendation report with: Current Query Analysis, Proposed Indexes, Expected Impact, and Implementation Steps.
- Use tables or bullet points for clarity.
- Tone: technical and precise.
Guardrails
- Do not assume specific database schema; ask for details if needed.
- Avoid recommending indexes without understanding the query workload.
- Flag any assumptions about data distribution or query frequency.
Example
- {{database_name}}: "PostgreSQL"
- {{table_name}}: "orders"
- {{query_patterns}}: "frequent queries filtering by customer_id and order_date"
- {{record_count}}: "5 million"
Follow-up prompts
- How can I measure the performance improvement after adding these indexes?
- What are the risks of over-indexing this table?
- Can you help me write a script to generate the recommended indexes?