Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf2fc98f

Browse files
committed
Further twiddling of nodeHash.c hashtable sizing calculation.
On reflection, the submitted patch didn't really work to prevent therequest size from exceeding MaxAllocSize, because of the fact that we'dhappily round nbuckets up to the next power of 2 after we'd limited it tomax_pointers. The simplest way to enforce the limit correctly is toround max_pointers down to a power of 2 when it isn't one already.(Note that the constraint to INT_MAX / 2, if it were doing anything usefulat all, is properly applied after that.)
1 parenta31e64d commitf2fc98f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

‎src/backend/executor/nodeHash.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ ExecChooseHashTableSize(double ntuples, int tupwidth, bool useskew,
415415
longhash_table_bytes;
416416
longskew_table_bytes;
417417
longmax_pointers;
418+
longmppow2;
418419
intnbatch=1;
419420
intnbuckets;
420421
doubledbuckets;
@@ -485,14 +486,20 @@ ExecChooseHashTableSize(double ntuples, int tupwidth, bool useskew,
485486
*/
486487
max_pointers= (work_mem*1024L) /sizeof(HashJoinTuple);
487488
max_pointers=Min(max_pointers,MaxAllocSize /sizeof(HashJoinTuple));
488-
/* also ensure we avoid integer overflow in nbatch and nbuckets */
489+
/* If max_pointers isn't a power of 2, must round it down to one */
490+
mppow2=1L <<my_log2(max_pointers);
491+
if (max_pointers!=mppow2)
492+
max_pointers=mppow2 /2;
493+
494+
/* Also ensure we avoid integer overflow in nbatch and nbuckets */
489495
/* (this step is redundant given the current value of MaxAllocSize) */
490496
max_pointers=Min(max_pointers,INT_MAX /2);
491497

492498
dbuckets=ceil(ntuples /NTUP_PER_BUCKET);
493499
dbuckets=Min(dbuckets,max_pointers);
500+
nbuckets= (int)dbuckets;
494501
/* don't let nbuckets be really small, though ... */
495-
nbuckets=Max((int)dbuckets,1024);
502+
nbuckets=Max(nbuckets,1024);
496503
/* ... and force it to be a power of 2. */
497504
nbuckets=1 <<my_log2(nbuckets);
498505

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp