Re: Memory usage during sorting

Поиск
Список
Период
Сортировка
От Jeff Janes
Тема Re: Memory usage during sorting
Дата
Msg-id CAMkU=1zsojpLmpz=md4-J2g7S44ZTaHoOqPkx4G16KKYWq67ww@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Memory usage during sorting  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Tue, Mar 20, 2012 at 6:31 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Greg Stark <stark@mit.edu> writes:
>> Offhand I wonder if this is all because we don't have the O(n) heapify
>> implemented.

I think we do already have it implemented.  1/2 the time the tuple
stays where it is after one comparison, 1/4 it moves up one level with
two comparisons, 1/8 it moves up two levels with 3 comparisons, etc.
That series sums up to a constant.  Maybe there is a worst-case that
makes this fall apart, though.  Heapifying something which is already
reverse sorted, maybe?

> Robert muttered something about that before, but is it real?  If you
> could do that, I'd think you'd have a less-than-n-log-n sorting
> solution.

Turning random tuples into heap can be linear.  Extracting them while
maintaining the heap is NlogN, though.  You can't sort without the
extraction step, so the law is preserved.

Cheers,

Jeff


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

Предыдущее
От: Greg Stark
Дата:
Сообщение: Re: Memory usage during sorting
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Postgres 8.4 planner question - bad plan, good plan for almost same queries.