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 ...
This commit is contained in:
parent
b3d0442ab3
commit
80cadb303c
@ -91,7 +91,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.60 2006/02/26 22:58:12 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.61 2006/03/04 19:05:06 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -741,6 +741,13 @@ grow_memtuples(Tuplesortstate *state)
|
||||
*/
|
||||
if (state->availMem <= (long) (state->memtupsize * sizeof(SortTuple)))
|
||||
return false;
|
||||
/*
|
||||
* On a 64-bit machine, allowedMem could be high enough to get us into
|
||||
* trouble with MaxAllocSize, too.
|
||||
*/
|
||||
if ((Size) (state->memtupsize * 2) >= MaxAllocSize / sizeof(SortTuple))
|
||||
return false;
|
||||
|
||||
FREEMEM(state, GetMemoryChunkSpace(state->memtuples));
|
||||
state->memtupsize *= 2;
|
||||
state->memtuples = (SortTuple *)
|
||||
|
Loading…
x
Reference in New Issue
Block a user