From 64bc26f90d342ca343f5ba383a97691a58991204 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 8 Dec 2016 23:05:21 +0200 Subject: [PATCH] Fix thinko in safeguard for negative availMem. Also, use pass read_buffer_size * numInputTapes rather than just availMem to USEMEM, to be neat. Peter Geoghegan. --- src/backend/utils/sort/tuplesort.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index 46eecbf942..baf87b3cdf 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -2669,8 +2669,8 @@ mergeruns(Tuplesortstate *state) (state->availMem) / 1024, numInputTapes); #endif - state->read_buffer_size = Min(state->availMem / numInputTapes, 0); - USEMEM(state, state->availMem); + state->read_buffer_size = Max(state->availMem / numInputTapes, 0); + USEMEM(state, state->read_buffer_size * numInputTapes); /* End of step D2: rewind all output tapes to prepare for merging */ for (tapenum = 0; tapenum < state->tapeRange; tapenum++) -- 2.40.0