Skip to content

Commit 80cadb3

Browse files
committed
Prevent sorting from requesting a SortTuple array that exceeds MaxAllocSize;
we'll go over to disk-based sort if we reach that limit. This fixes Stefan Kaltenbrunner's observation that sorting can suffer an 'invalid memory alloc request size' failure when sort_mem is set large enough. It's unfortunately not so easy to fix in 8.1 ...
1 parent b3d0442 commit 80cadb3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/backend/utils/sort/tuplesort.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
* Portions Copyright (c) 1994, Regents of the University of California
9292
*
9393
* IDENTIFICATION
94-
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.60 2006/02/26 22:58:12 tgl Exp $
94+
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.61 2006/03/04 19:05:06 tgl Exp $
9595
*
9696
*-------------------------------------------------------------------------
9797
*/
@@ -741,6 +741,13 @@ grow_memtuples(Tuplesortstate *state)
741741
*/
742742
if (state->availMem <= (long) (state->memtupsize * sizeof(SortTuple)))
743743
return false;
744+
/*
745+
* On a 64-bit machine, allowedMem could be high enough to get us into
746+
* trouble with MaxAllocSize, too.
747+
*/
748+
if ((Size) (state->memtupsize * 2) >= MaxAllocSize / sizeof(SortTuple))
749+
return false;
750+
744751
FREEMEM(state, GetMemoryChunkSpace(state->memtuples));
745752
state->memtupsize *= 2;
746753
state->memtuples = (SortTuple *)

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