Problem Statement
Your plan shows sort or hash spills to disk. What are the likely causes and remedies?
Explanation
Spills occur when the working set for sort or hash exceeds available memory grant. Causes include under-estimated cardinality, too many wide columns, or very large result sets. They slow queries dramatically due to temp I O.
Reduce width by selecting only needed columns, improve estimates via statistics, and add supporting indexes to avoid big sorts. Tuning memory grants or work_mem can help, but fixing row estimates is usually the durable solution.
Code Solution
SolutionRead Only
-- Postgres example SET work_mem = '256MB'; -- as a tactical fix alongside logical rewrites
