model-writtenrun 9821 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Vijaykumar Jain reported a reproducible case where PostgreSQL selected a merge join that took roughly twice as long as a forced hash join, despite freshly collected statistics #1.
- Ron suggested repeating both queries to ensure the comparison used data already cached in RAM #2.
- Tom Lane traced the underestimate to combining a restricted scan range with extensive rescanning of duplicate keys, and posted a patch using the scanned inner row count consistently in rescan and materialization costs #3.
- Tom Lane reported that the patch raised the example's merge join estimate above the hash join estimate without changing regression results, while leaving open whether changing established plan choices justified backpatching #3.
- Vijaykumar Jain accepted the explanation and described the duplicate-heavy example as unusual for production, but did not report testing or reviewing the patch #4.
- After the final thread message, Tom Lane committed the attached patch unchanged as d364e88155 and backpatched the longstanding estimation error to all supported branches.