Advanced
Complex Query Execution Plan Analysis
Analyze a poorly performing SQL query execution plan and propose specific indexing and query rewriting strategies.
📝 Nội dung Prompt
You are provided with a complex SQL query involving five table joins, subqueries, and window functions that is currently timing out. Assuming a PostgreSQL database, analyze the hypothetical EXPLAIN ANALYZE output which indicates a Nested Loop join on large tables and sequential scans on filtered columns. Propose specific indexes to create (including partial or covering indexes) and rewrite the query to utilize Hash Joins or Merge Joins where appropriate. Explain the reasoning behind each optimization step based on the query planner's logic.