Skip to content

Commit 7af16b2

Browse files
committed
Avoid running out of memory during hash_create, by not passing a
number-of-buckets that exceeds the size we actually plan to allow the hash table to grow to. Per trouble report from Sean Shanny.
1 parent e8aa10e commit 7af16b2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/backend/executor/nodeIndexscan.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.87 2003/11/29 19:51:48 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.88 2003/12/30 20:05:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -953,22 +953,28 @@ static void
953953
create_duphash(IndexScanState *node)
954954
{
955955
HASHCTL hash_ctl;
956+
long nbuckets;
956957

958+
node->iss_MaxHash = (SortMem * 1024L) /
959+
(MAXALIGN(sizeof(HASHELEMENT)) + MAXALIGN(sizeof(DupHashTabEntry)));
957960
MemSet(&hash_ctl, 0, sizeof(hash_ctl));
958961
hash_ctl.keysize = SizeOfIptrData;
959962
hash_ctl.entrysize = sizeof(DupHashTabEntry);
960963
hash_ctl.hash = tag_hash;
961964
hash_ctl.hcxt = CurrentMemoryContext;
965+
nbuckets = (long) ceil(node->ss.ps.plan->plan_rows);
966+
if (nbuckets < 1)
967+
nbuckets = 1;
968+
if (nbuckets > node->iss_MaxHash)
969+
nbuckets = node->iss_MaxHash;
962970
node->iss_DupHash = hash_create("DupHashTable",
963-
(long) ceil(node->ss.ps.plan->plan_rows),
971+
nbuckets,
964972
&hash_ctl,
965973
HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT);
966974
if (node->iss_DupHash == NULL)
967975
ereport(ERROR,
968976
(errcode(ERRCODE_OUT_OF_MEMORY),
969977
errmsg("out of memory")));
970-
node->iss_MaxHash = (SortMem * 1024L) /
971-
(MAXALIGN(sizeof(HASHELEMENT)) + MAXALIGN(sizeof(DupHashTabEntry)));
972978
}
973979

974980
int

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy