model-writtenrun 8627 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Alvaro Herrera reported implausible EXPLAIN ANALYZE hash bucket, batch, and memory statistics while examining a pg_dump query, and Tom Lane reproduced the problem #1 #2.
- Thomas Munro recognized freed-memory patterns and traced the failure to a rescan destroying a hash table without clearing the child HashState pointer, followed by an empty outer relation preventing reconstruction; simply clearing the pointer would lose the displayed statistics #3 #4.
- Justin Pryzby reproduced the problem on older releases, and Richard Guo confirmed the diagnosis with gdb and supplied a smaller reproducer showing that the dangling pointer also existed in PostgreSQL 8.4, before hash statistics were displayed #5 #6 #7.
- Konstantin Knizhnik proposed saving statistics before destroying the hash table, clearing the pointer, and displaying the saved values when no replacement table exists #8.
- Tom Lane reworked the patch to accumulate maximum statistics across all hash table instances and parallel workers, while offering a separate minimal pointer-clearing alternative for backpatching to avoid the broader change's risk #9.
- The minimal alternative from #9 landed unchanged as 5c27bce7f3 and was backpatched, allowing the unusual corner case to omit hash statistics instead of accessing freed memory.
- The broader alternative from #9 then landed on the development branch as 969f9d0b4b, layered over the pointer cleanup with comment refinements explaining why each statistic uses its own maximum.
- After both commits, Richard Guo examined the broader patch's instrumentation allocation and Tom Lane explained that allocating zeroed statistics is harmless even with a null hash table; this exchange produced no further patch and occurred too late for suggested review credit #10 #11 #12.
- The thread closed when Justin Pryzby asked about backpatching, Tom Lane pointed to the already committed minimal fix, and Justin acknowledged it and updated the PostgreSQL 13 open-items wiki #13 #14 #15.