By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,176 Members | 984 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,176 IT Pros & Developers. It's quick & easy.

query should use an index?

P: n/a
hello,

i've got a table that looks like this (irrelevant data removed);

create table test (
id serial primary key,
t_end timestamp);

there's an index:
create index test_t_end on test(t_end);

can or should a query like:

select login,t_end from test order by t_end desc;

use the index? explain says it does a sequential scan
and sort. but it seems to me that if it's possible for the
postgresql to use the index to seek to the last record and
then step backward, then it could use the index. but of
course i don't know anything about postgresql internals
so i'm really just guessing or going with what seems likely,
but from a position of ignorance.

tiger

--
Gerald Timothy Quimpo gquimpo*hotmail.com tiger*sni*ph
http://bopolissimus.sni.ph
Public Key: "gpg --keyserver pgp.mit.edu --recv-keys 672F4C78"

The best way to get rid of worries is to let them die of
neglect.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Bopolissimus Platypus wrote:
create table test (
id serial primary key,
t_end timestamp);

there's an index:
create index test_t_end on test(t_end);

can or should a query like:

select login,t_end from test order by t_end desc;

use the index?


It can, but that does not mean that it is unconditionally the best
choice. The planner will make the decision.
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.