Re: Re: Which qsort is used

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Re: Which qsort is used
Дата
Msg-id 20051222070057.GA21783@svana.org
обсуждение исходный текст
Ответ на Re: Re: Which qsort is used  (Manfred Koizar <mkoi-pg@aon.at>)
Ответы Re: Re: Which qsort is used  (Manfred Koizar <mkoi-pg@aon.at>)
Список pgsql-hackers
On Thu, Dec 22, 2005 at 01:43:34AM +0100, Manfred Koizar wrote:
> Qsorting N elements costs O(N*lnN), so excluding H elements from the
> sort reduces the cost by at least O(H*lnN).  The merge step costs O(N)
> plus some (<=50%) more memory, unless someone knows a fast in-place
> merge.  So depending on the constant factors involved there might be a
> usable solution.

But where are you including the cost to check how many cells are
already sorted? That would be O(H), right? This is where we come back
to the issue that comparisons in PostgreSQL are expensive. The cpu_cost
in the tests I saw so far is unrealistically low.

> I've been playing with some numbers and assuming the constant factors
> to be equal for all the O()'s this method starts to pay off at
>       H      for N
>       20       100      20%
>      130      1000      13%
>     8000    100000       8%

Hmm, what are the chances you have 100000 unordered items to sort and
that the first 8% will already be in order. ISTM that that probability
will be close enough to zero to not matter...

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

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

Предыдущее
От: Manuel Sugawara
Дата:
Сообщение: Re: to_char and i18n
Следующее
От: Karel Zak
Дата:
Сообщение: Re: to_char and i18n