pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kevin Schroeder <mirage@mirageworks.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query problem fixed
Date: Thu, 29 May 2003 10:49:43 -0400
Message-ID: <17680.1054219783@sss.pgh.pa.us> (raw)
In-Reply-To: <006d01c325eb$eb72fdf0$0200a8c0@WORKSTATION>
References: <006d01c325eb$eb72fdf0$0200a8c0@WORKSTATION>

"Kevin Schroeder" <mirage@mirageworks.com> writes:
> select row_key, column1, column2, column3, column4, column5 from table1
> where column6 = 1 order by column3 desc limit 21;

> I changed the index to

> message_index btree (column3, column6)

> rather than

> message_index btree (column6, column3, column7)

That's probably not the best solution.  It would be better to leave the
index with column6 first and write the query as

... where column6 = 1 order by column6 desc, column3 desc limit 21

This doesn't change the results (since there's only one value of column6
in the output), but it does cause the planner to realize that a
backwards scan of the index would produce what you want with no sort
step.  The results should be essentially instantaneous if you can get
the query plan down to Index Scan Backward + Limit.

			regards, tom lane



view thread (3+ messages)

Message-ID: <17680.1054219783@sss.pgh.pa.us>
Permalink:  ../17680.1054219783@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17680.1054219783@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-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, mirage@mirageworks.com
  Subject: Re: Query problem fixed
  In-Reply-To: <17680.1054219783@sss.pgh.pa.us>
  References: <006d01c325eb$eb72fdf0$0200a8c0@WORKSTATION> <17680.1054219783@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