From: jwieck@debis.com
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 16:34:47 +0200 (MET DST)
Message-ID: <m0zTS0m-000EBRC@orion.SAPserv.Hamburg.dsh.de> (raw)
In-Reply-To: <3624AE5C.752E4E7F@alumni.caltech.edu>
>
> > SELECT * FROM tab WHERE key > 'G' ORDER BY key;
> > results in a sort->indexscan - hmmm.
> > The last one is the query we would need in the web
> > environment used over a cursor as in the example above. But
> > due to the sort, the backend selects until the end of the
> > table, sorts them and then returns only the first 20 rows
> > (out of sorts result).
>
> So you are saying that for this last case the sort was unnecessary? Does
> the backend traverse the index in the correct order to guarantee that
> the tuples are coming out already sorted? Does a hash index give the
> same plan (I would expect a sort->seqscan for a hash index)?
Good point! As far as I can see, the planner chooses index
usage only depending on the WHERE clause. A hash index is
only usable when the given qualification uses = on the
indexed attribute(s).
If the sortClause exactly matches the indexed attributes of
the ONE used btree index and all operators request ascending
order I think the index scan already returns the correct
order. Who know's definitely?
Addition to my last posting: ... and if the index scan is
using a btree index ...
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #
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: jwieck@debis.com, lockhart@alumni.caltech.edu, eric@linux-hw.com, jeff@remapcorp.com, hackers@postgreSQL.org
Subject: Re: [HACKERS] What about LIMIT in SELECT ?
In-Reply-To: <m0zTS0m-000EBRC@orion.SAPserv.Hamburg.dsh.de>
References: <3624AE5C.752E4E7F@alumni.caltech.edu> <m0zTS0m-000EBRC@orion.SAPserv.Hamburg.dsh.de>
* 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