On Fri, 2007-11-23 at 12:36 +0000, Gregory Stark wrote: > I also did an optimization similar to the bounded-sort case where we check if > the next tuple from the same input which last contributed the result record > comes before the top element of the heap. That avoids having to do an insert > and siftup only to pull out the same record you just inserted. In theory this > is not an optimization but in practice I think partitioned tables will often > contain contiguous blocks of key values and queries will often be joining > against that key and therefore often want to order by it.
If it is an option, you could also do this by a new method on the heap which adds a new entry and removes the resulting new head in one atomic operation. That would work with one single comparison for the less than current head situation, and it would not need to repeat that comparison if that fails. Also it could directly remove the head and balance the tree in one go. Cheers, Csaba. ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings