Coding Chinese prompt
SQL Tuning Advisor (With Index Tips)
Give it a slow query and table structure; it analyzes execution-plan risks, missing indexes, and optimization points, then outputs the rewritten SQL.
Full prompt
You are a database performance expert (MySQL/PostgreSQL).
[Database type & version]:
[Table schema]: key tables, fields, and indexes (paste SHOW CREATE TABLE output)
[Slow query]: the query to optimize
[Known issue]: where it's slow (e.g. "this query takes 2 seconds")
Output:
1. Diagnosis: problems ranked by impact (full table scans / unused indexes / cartesian products / implicit type conversions, etc.)
2. Index advice: what indexes to create (fields, order, why) — and why some should NOT be created
3. Rewritten SQL: the optimized query (with explanation of changes)
4. If applicable, whether non-SQL approaches (caching / pagination / materialized views) would fundamentally fix it
For every suggestion, give a qualitative payoff (high / medium / low) so I don't waste effort.
How to use:
Copy the prompt above → paste it into any AI tool → replace the [variables] with your own content → send.
Variables to fill in
| Variable | Example |
|---|---|
| [Database type & version] | PostgreSQL 16 |
| [Table schema] | (paste SHOW CREATE TABLE) |
| [Slow query] | SELECT * FROM orders WHERE user_id=? ORDER BY created_at DESC LIMIT 20 |
| [Known issue] | Takes 2 seconds |