Re: qsort again (was Re: [PERFORM] Strange Create Index - Mailing list pgsql-hackers

From Tom Lane
Subject Re: qsort again (was Re: [PERFORM] Strange Create Index
Date
Msg-id 29277.1140110108@sss.pgh.pa.us
Whole thread Raw
In response to Re: qsort again (was Re: [PERFORM] Strange Create Index  ("Craig A. James" <cjames@modgraph-usa.com>)
Responses Re: qsort again (was Re: [PERFORM] Strange Create Index
List pgsql-hackers
"Craig A. James" <cjames@modgraph-usa.com> writes:
> You can also use this trick when the optimizer is asked for "fastest first result."  Say you have a cursor on a
columnof numbers with good distribution.  If you do a bucket sort on the first two or three digits only, you know the
first"page" of results will be in the first bucket.  So you only need to apply qsort to that first bucket (which is
veryfast, since it's small), and you can deliver the first page of data to the application.  This can be particularly
effectivein interactive situations, where the user typically looks at a few pages of data and then abandons the search.
 

> I doubt this is very relevant to Postgres.  A relational database has to be general purpose, and it's hard to give it
"hints"that would tell it when to use this particular optimization. 

Actually, LIMIT does nicely for that hint; the PG planner has definitely
got a concept of preferring fast-start plans for limited queries.  The
real problem in applying bucket-sort ideas is the lack of any
datatype-independent way of setting up the buckets.

Once or twice we've kicked around the idea of having some
datatype-specific sorting code paths alongside the general-purpose one,
but I can't honestly see this as being workable from a code maintenance
standpoint.

            regards, tom lane

pgsql-hackers by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: qsort again (was Re: [PERFORM] Strange Create
Next
From: Scott Lamb
Date:
Subject: Re: qsort again (was Re: [PERFORM] Strange Create