• Heikki Linnakangas's avatar
    Change the way pre-reading in external sort's merge phase works. · e94568ec
    Heikki Linnakangas authored
    Don't pre-read tuples into SortTuple slots during merge. Instead, use the
    memory for larger read buffers in logtape.c. We're doing the same number
    of READTUP() calls either way, but managing the pre-read SortTuple slots
    is much more complicated. Also, the on-tape representation is more compact
    than SortTuples, so we can fit more pre-read tuples into the same amount
    of memory this way. And we have better cache-locality, when we use just a
    small number of SortTuple slots.
    
    Now that we only hold one tuple from each tape in the SortTuple slots, we
    can greatly simplify the "batch memory" management. We now maintain a
    small set of fixed-sized slots, to hold the tuples, and fall back to
    palloc() for larger tuples. We use this method during all merge phases,
    not just the final merge, and also when randomAccess is requested, and
    also in the TSS_SORTEDONTAPE case. In other words, it's used whenever we
    do an external sort.
    
    Reviewed by Peter Geoghegan and Claudio Freire.
    
    Discussion: <CAM3SWZTpaORV=yQGVCG8Q4axcZ3MvF-05xe39ZvORdU9JcD6hQ@mail.gmail.com>
    e94568ec
tuplesort.c 135 KB