[CDBI] Make CDBI go fast

Brad Bowman list at bereft.net
Mon May 7 07:12:53 BST 2007

Brad Bowman wrote:
> Perrin Harkins wrote:
>> On 3/21/07, Brad Bowman <list at bereft.net> wrote:
>>> That's what I was thinking, do one table scan keeping a sorted set of
>>> the top $N, comparing each scanned row with the last of the current
>>> row set.  Then the set is then kept in an index and maintained during
>>> insertions (easy) and deletions (if one of the set is deleted a scan
>>> may be needed) and updates.
> That said, I can't think of a situation where I have needed
> this.  Also, without database support, the administration pain
> probably sinks the idea.

Postgres just added support, at least from what I can tell:

== PostgreSQL Weekly News - May 06 2007 ==

== Applied Patches ==

- Mark TODO as done: "Allow ORDER BY ... LIMIT # to select high/low
   value without sort"

Tom Lane committed:

- Teach tuplesort.c about "top N" sorting, in which only the first N
   tuples need be returned.  We keep a heap of the current best N
   tuples and sift-up new tuples into it as we scan the input.  For M
   input tuples this means only about M*log(N) comparisons instead of
   M*log(M), not to mention a lot less workspace when N is small ---
   avoiding spill-to-disk for large M is actually the most attractive
   thing about it.  Patch includes planner and executor support for
   invoking this facility in ORDER BY ... LIMIT queries.  Greg Stark,
   with some editorialization by moi.


  ... But in the end, the details of a matter are important. The right
  or wrong of one's way of doing thing is found are trivial matters.
                               -- Hagakure http://bereft.net/hagakure/

More information about the ClassDBI mailing list