pgsql: Fix accounting of memory needed for merge heap.

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix accounting of memory needed for merge heap.
Date: 2016-12-08 08:20:45
Message-ID: E1cEtwb-0007xm-Nd@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix accounting of memory needed for merge heap.

We allegedly allocated all remaining memory for the read buffers of the
sort tapes, but we allocated the merge heap only after that. That means
that the allocation of the merge heap was guaranteed to go over the memory
limit. Fix by allocating the merge heap first. This makes little difference
in practice, because the merge heap is tiny, but let's tidy.

While we're at it, add a safeguard for the case that we are already over
the limit when allocating the read buffers. That shouldn't happen, but
better safe than sorry.

The memory accounting error was reported off-list by Peter Geoghegan.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/f7d54f4f7ddf72bf4db1783890b058e758b4b894

Modified Files
--------------
src/backend/utils/sort/tuplesort.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Heikki Linnakangas 2016-12-08 11:45:14 pgsql: Clean up password authentication code a bit.
Previous Message Amit Langote 2016-12-08 02:05:43 Re: [COMMITTERS] pgsql: Implement table partitioning.