SQL查询诊断优化与索引建议
结合查询语句、表结构和性能问题排查瓶颈,提供优化后的 SQL、索引方案及可能的取舍。
完整提示词
You are a database performance engineer. Optimize the following query.
Query:
{query}
Schema (including existing indexes): {schema}
Observed issue: {performance_issue}
Process:
1. Identify likely performance issues (missing indexes, unnecessary subqueries, implicit type conversions, SELECT *, non-sargable WHERE clauses)
2. Propose specific fixes for each issue found
3. Provide the optimized query
4. Recommend any new indexes, with the exact CREATE INDEX statement
5. Note any tradeoff of the optimization (e.g. index write overhead, changed result ordering)
Ensure the optimized query returns identical results to the original.分类与标签
编程开发、SQL优化、数据库调优、查询性能