model-writtenrun 1761 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Vaibhav Jain reported integer overflow in hash-join buffer-memory calculations and proposed changing nbatch to size_t in #1; David Rowley recommended local casts to preserve the existing integer interfaces in #2, and Tomas Vondra agreed in #3.
- Tomas identified the same overflow in ExecHashIncreaseBatchSize and suspected a separate failure to update hash_table_bytes in #7; Vaibhav's revised patch added casts at all three calculation sites in #10.
- Tomas confirmed that balancing used a stale memory limit and lacked bucket-growth protection in #12, raising the possibility of reverting the feature; Tom Lane and Nathan Bossart instead supported taking time to fix it properly after the PostgreSQL 18 release in #13 and #14.
- Konstantin Knizhnik pointed to related work in #15, and Tomas explained in #16 that bucket growth should be limited by allocation capacity rather than the original work_mem-derived limit, while the separate max_batches issue remained outside this fix.
- Tomas posted four patches covering casts, memory-limit updates, bucket-growth protection, and comments in #17; his four-billion-row experiment showed that the original balancing failed to reduce total estimated memory, while the patches substantially reduced it.
- Melanie Plageman proposed a simpler alternative in #18, replacing multiplication with division, stopping when bucket allocation would become too large, and preventing the loop from reducing a single batch to zero; Tomas accepted stopping instead of clamping but identified algebra and limit-check errors in #19.
- Melanie corrected the comparison and allocation checks in #20 and reported matching Tomas's experimental results; further discussion distinguished the bucket array's MaxAllocSize limit from the whole hash table's SIZE_MAX limit, leading to a runtime space_allowed guard in #24.
- Tomas and Melanie established that balancing must include skew-table memory in #23 and #26; Tomas incorporated this in #27 by using space_allowed throughout and doubling num_skew_mcvs, and reported successful testing with twenty billion rows.
- Melanie supplied final comment refinements and replaced a redundant skew-count overflow check with an assertion in #28, then requested consistent parentheses in #29; Tomas folded these into #30 and judged skew-count rounding errors negligible.
- Tomas committed b85c4700fc from #30 with comment-only edits, including removal of the low-work_mem edge-case explanation, and announced the PostgreSQL 18 backpatch and completion in #31.
- At the thread's close, Tomas left the separate behavior where increasing low work_mem can increase initial batch counts unchanged, explaining in #31 that it was unlikely to matter in practice and runtime balancing would correct an initially low batch count.