• Heikki Linnakangas's avatar
    Fix accounting of memory needed for merge heap. · f7d54f4f
    Heikki Linnakangas authored
    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.
    f7d54f4f
tuplesort.c 135 KB