From: Bruce Momjian <maillist@candle.pha.pa.us>
To: lockhart@alumni.caltech.edu
Cc: jwieck@debis.com
Cc: eric@linux-hw.com
Cc: jeff@remapcorp.com
Cc: hackers@postgreSQL.org
Subject: Re: [HACKERS] What about LIMIT in SELECT ?
Date: Wed, 14 Oct 1998 13:21:15 -0400 (EDT)
Message-ID: <199810141721.NAA28746@candle.pha.pa.us> (raw)
In-Reply-To: <3624AE5C.752E4E7F@alumni.caltech.edu>
> > I've done some tests and what I found out might be a bug in
> > PostgreSQL's query optimizer.
> > SELECT * FROM tab ORDER BY key;
> > results in a sort->seqscan - I would have
> > expected an indexscan!
>
> Given that a table _could_ be completely unsorted on disk, it is
> probably reasonable to suck the data in for a possible in-memory sort
> rather than skipping around the disk to pick up individual tuples via
> the index. Don't know if vacuum has a statistic on "orderness"...
Thomas is correct on this. Vadim has run some tests, and with our
optimized psort() code, the in-memory sort is often faster than using
the index to get the tuple, because you are jumping all over the drive.
I don't remember, but obviously there is a break-even point where
getting X rows using the index on a table of Y rows is faster , but
getting X+1 rows on a table of Y rows is faster getting all the rows
sequentailly, and doing the sort.
You would have to pick only certain queries(no joins, index matches
ORDER BY), take the number of rows requested, and the number of rows
selected, and figure out if it is faster to use the index, or a
sequential scan and do the ORDER BY yourself.
Add to this the OFFSET capability. I am not sure how you are going to
get into the index and start at the n-th entry, unless perhaps you just
sequential scan the index.
In fact, many queries just get column already indexed, and we could just
pull the data right out of the index.
I have added this to the TODO list:
* Pull requested data directly from indexes, bypassing heap data
I think this has to be post-6.4 work, but I think we need to work in
this direction. I am holding off any cnfify fixes for post-6.4, but a
6.4.1 performance release certainly is possible.
But, you are correct that certain cases where in index is already being
used on a query, you could just skip the sort IF you used the index to
get the rows from the base table.
--
Bruce Momjian | http://www.op.net/~candle
maillist@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: maillist@candle.pha.pa.us, lockhart@alumni.caltech.edu, jwieck@debis.com, eric@linux-hw.com, jeff@remapcorp.com, hackers@postgreSQL.org
Subject: Re: [HACKERS] What about LIMIT in SELECT ?
In-Reply-To: <199810141721.NAA28746@candle.pha.pa.us>
References: <3624AE5C.752E4E7F@alumni.caltech.edu> <199810141721.NAA28746@candle.pha.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox