pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Brian McCane <bmccane@mccons.net>
Cc: pg-admin <pgsql-admin@postgresql.org>
Subject: Re: Useless index
Date: Thu, 14 Feb 2002 10:06:09 -0500
Message-ID: <8617.1013699169@sss.pgh.pa.us> (raw)
In-Reply-To: <20020214074001.N83588-100000@fw.mccons.net>
References: <20020214074001.N83588-100000@fw.mccons.net>

Brian McCane <bmccane@mccons.net> writes:
> CREATE INDEX foo_index ON foo (bazid, score desc) ;

> Which would be exactly what I want, and would complete in a split second.
> Instead, this thing runs FOREVER (okay, it just seems that way to my
> client :).  Is there any way to get the equivalent index from PostgreSQL?

You don't need a funny index, you just need to get the planner to notice
that that index can serve to create the desired output ordering.  Try

create table foo(bazid int, score int);
CREATE INDEX foo_index ON foo (bazid, score) ;

explain select * from foo where bazid = 123456
order by bazid desc, score desc limit 100 ;

NOTICE:  QUERY PLAN:

Limit  (cost=0.00..17.07 rows=5 width=8)
  ->  Index Scan Backward using foo_index on foo  (cost=0.00..17.07 rows=5 width=8)

EXPLAIN


			regards, tom lane



view thread (11+ messages)  latest in thread

Message-ID: <8617.1013699169@sss.pgh.pa.us>
Permalink:  ../8617.1013699169@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/8617.1013699169@sss.pgh.pa.us

 · 

reply

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-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, bmccane@mccons.net
  Subject: Re: Useless index
  In-Reply-To: <8617.1013699169@sss.pgh.pa.us>
  References: <20020214074001.N83588-100000@fw.mccons.net> <8617.1013699169@sss.pgh.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