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

Commit1a7c03e

Browse files
committed
Fix oversized memory allocation in Parallel Hash Join
During the calculations of the maximum for the number of buckets, take intoaccount that later we round that to the next power of 2.Reported-by: Karen TalaricoBug: #16925Discussion:https://postgr.es/m/16925-ec96d83529d0d629%40postgresql.orgAuthor: Thomas Munro, Andrei Lepikhov, Alexander KorotkovReviewed-by: Alena RybakinaBackpatch-through: 12
1 parent596eeb1 commit1a7c03e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎src/backend/executor/nodeHash.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,7 @@ ExecParallelHashIncreaseNumBatches(HashJoinTable hashtable)
11621162
doubledtuples;
11631163
doubledbuckets;
11641164
intnew_nbuckets;
1165+
uint32max_buckets;
11651166

11661167
/*
11671168
* We probably also need a smaller bucket array. How many
@@ -1174,9 +1175,16 @@ ExecParallelHashIncreaseNumBatches(HashJoinTable hashtable)
11741175
* array.
11751176
*/
11761177
dtuples= (old_batch0->ntuples*2.0) /new_nbatch;
1178+
/*
1179+
* We need to calculate the maximum number of buckets to
1180+
* stay within the MaxAllocSize boundary. Round the
1181+
* maximum number to the previous power of 2 given that
1182+
* later we round the number to the next power of 2.
1183+
*/
1184+
max_buckets=pg_prevpower2_32((uint32)
1185+
(MaxAllocSize /sizeof(dsa_pointer_atomic)));
11771186
dbuckets=ceil(dtuples /NTUP_PER_BUCKET);
1178-
dbuckets=Min(dbuckets,
1179-
MaxAllocSize /sizeof(dsa_pointer_atomic));
1187+
dbuckets=Min(dbuckets,max_buckets);
11801188
new_nbuckets= (int)dbuckets;
11811189
new_nbuckets=Max(new_nbuckets,1024);
11821190
new_nbuckets=pg_nextpower2_32(new_nbuckets);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp