forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit37450f2
committed
Fix incorrect hash table resizing code in simplehash.h
This fixes a bug in simplehash.h which caused an incorrect size mask to beused when the hash table grew to SH_MAX_SIZE (2^32). The code wasincorrectly setting the size mask to 0 when the hash tables reached themaximum possible number of buckets. This would result always trying touse the 0th bucket causing an infinite loop of trying to grow the hashtable due to there being too many collisions.Seemingly it's not that common for simplehash tables to ever grow this bigas this bug dates back to v10 and nobody seems to have noticed it before.However, probably the most likely place that people would notice it wouldbe doing a large in-memory Hash Aggregate with something close to at least2^31 groups.After this fix, the code now works correctly with up to within 98% of 2^32groups and will fail with the following error when trying to insert anymore items into the hash table:ERROR: hash table size exceededHowever, the work_mem (or hash_mem_multiplier in newer versions) settingswill generally cause Hash Aggregates to spill to disk long before reachingthat many groups. The minimal test case I did took a work_mem setting ofover 192GB to hit the bug.simplehash hash tables are used in a few other places such as Bitmap IndexScans, however, again the size that the hash table can become there isalso limited to work_mem and it would take a relation of around 16TB(2^31) pages and a very large work_mem setting to hit this. With smallerwork_mem values the table would become lossy and never grow large enoughto hit the problem.Author: Yura SokolovReviewed-by: David Rowley, Ranier VilelaDiscussion:https://postgr.es/m/b1f7f32737c3438136f64b26f4852b96@postgrespro.ruBackpatch-through: 10, where simplehash.h was added1 parent88cbbbf commit37450f2
1 file changed
+5
-9
lines changedLines changed: 5 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
198 | 198 |
| |
199 | 199 |
| |
200 | 200 |
| |
201 |
| - | |
202 |
| - | |
| 201 | + | |
| 202 | + | |
203 | 203 |
| |
204 | 204 |
| |
205 | 205 |
| |
| |||
302 | 302 |
| |
303 | 303 |
| |
304 | 304 |
| |
305 |
| - | |
| 305 | + | |
306 | 306 |
| |
307 | 307 |
| |
308 | 308 |
| |
| |||
322 | 322 |
| |
323 | 323 |
| |
324 | 324 |
| |
325 |
| - | |
326 |
| - | |
327 |
| - | |
328 |
| - | |
329 |
| - | |
| 325 | + | |
330 | 326 |
| |
331 | 327 |
| |
332 | 328 |
| |
| |||
476 | 472 |
| |
477 | 473 |
| |
478 | 474 |
| |
479 |
| - | |
| 475 | + | |
480 | 476 |
| |
481 | 477 |
| |
482 | 478 |
| |
|
0 commit comments
Comments
(0)