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.

Attachment: pgpg6RoCjt5SA.pgp
Description: PGP signature

Reply via email to