Skip site navigation (1) Skip section navigation (2)

Re: qsort again (was Re: [PERFORM] Strange Create Index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Craig A(dot) James" <cjames(at)modgraph-usa(dot)com>
Cc: Markus Schaber <schabi(at)logix-tt(dot)com>, pgsql-performance(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: qsort again (was Re: [PERFORM] Strange Create Index
Date: 2006-02-16 17:15:08
Message-ID: 29277.1140110108@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-performance
"Craig A. James" <cjames(at)modgraph-usa(dot)com> writes:
> You can also use this trick when the optimizer is asked for "fastest first result."  Say you have a cursor on a column of 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 very fast, since it's small), and you can deliver the first page of data to the application.  This can be particularly effective in 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

In response to

Responses

pgsql-performance by date

Next:From: Scott LambDate: 2006-02-16 17:19:24
Subject: Re: qsort again (was Re: [PERFORM] Strange Create
Previous:From: Adam AlkinsDate: 2006-02-16 17:03:29
Subject: Index Choice Problem

pgsql-hackers by date

Next:From: Scott LambDate: 2006-02-16 17:19:24
Subject: Re: qsort again (was Re: [PERFORM] Strange Create
Previous:From: Martijn van OosterhoutDate: 2006-02-16 16:59:59
Subject: Re: qsort again (was Re: [PERFORM] Strange Create

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group