Question about maxTapes & selectnewtape & dumptuples

Поиск
Список
Период
Сортировка
От Andy Fan
Тема Question about maxTapes & selectnewtape & dumptuples
Дата
Msg-id 874j9ayd4z.fsf@163.com
обсуждение исходный текст
Ответы Re: Question about maxTapes & selectnewtape & dumptuples  (Heikki Linnakangas <hlinnaka@iki.fi>)
Список pgsql-hackers
Hi,

merge sorts requires all the tuples in each input are pre-sorted (1),
and in tuplesort.c, when the workmem is full, we dumptuples into
destTape. (2).  it looks to me that we need a unlimited number of Tapes
if the number of input tuples is big enough. However we set a maxTapes
in 'inittapes' and we may use a pre-used tapes for storing new tuples in
'selectnewtape'. Wouldn't this break the prerequisite (1)? 

selectnewtape(Tuplesortstate *state)
{
    if (state->nOutputTapes < state->maxTapes)
    {..}
    else
    {
        /*
         * We have reached the max number of tapes.  Append to an existing
         * tape.
         */
        state->destTape = state->outputTapes[state->nOutputRuns % state->nOutputTapes];
        state->nOutputRuns++;
    }
}


for example, at the first use of outputTapes[x], it stores (1, 3, 5, 7),
and later (2, 4, 6, 8) are put into it.  so the overall of (1, 3, 5, 7,
2, 4, 6, 8) are not sorted? Where did I go wrong?

-- 
Best Regards
Andy Fan




В списке pgsql-hackers по дате отправления:

Предыдущее
От: Dean Rasheed
Дата:
Сообщение: Re: Optimize numeric.c mul_var() using the Karatsuba algorithm
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Question about maxTapes & selectnewtape & dumptuples