pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleus Mantzios <achill@matrix.gatewaynet.com>
To: Bruno Wolff III <bruno@wolff.to>
Cc: email lists <lists@darrenmackay.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: query not using index for descending records?
Date: Thu, 29 Jan 2004 15:29:11 +0200 (EET)
Message-ID: <Pine.LNX.4.44.0401291525350.9854-100000@matrix.gatewaynet.com> (raw)
In-Reply-To: <20040129131847.GE17068@wolff.to>

O kyrios Bruno Wolff III egrapse stis Jan 29, 2004 :

As i see there was a thread
http://archives.postgresql.org/pgsql-hackers/2003-05/msg00762.php
dealing with this issue, assuming the "correct" order by
should be "order by datetime ASC, id DESC".

Do you know of any progress for declaring the direction of each
column in a multicolumn index?

> On Thu, Jan 29, 2004 at 22:18:08 +1000,
>   email lists <lists@darrenmackay.com> wrote:
> >  Limit  (cost=0.00..2.31 rows=20 width=12)
> >    ->  Index Scan using idx_trafficlogs_datetime_id on trafficlogs
> > (cost=0.00..1057.89 rows=9172 width=12)
> > (2 rows)
> > 
> > however, I am wanting to return the last 20 records. I have been using:
> > 
> > explain select datetime,id from trafficlogs order by datetime,id desc
> > limit 20;
> 
> You probably don't want to do that. The DESC only applies to the one
> expression it follows. What you want is probably:
> explain select datetime,id from trafficlogs order by datetime desc,id desc
> limit 20;
> 
> The index won't get used because with id and datetime being checked in
> different orders, only the first part of the index is usable. And probably
> that wasn't selective enough for an index scan to be used.
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>       joining column's datatypes do not match
> 

-- 
-Achilleus




view thread (10+ messages)  latest in thread

Message-ID: <Pine.LNX.4.44.0401291525350.9854-100000@matrix.gatewaynet.com>
Permalink:  ../Pine.LNX.4.44.0401291525350.9854-100000@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.44.0401291525350.9854-100000@matrix.gatewaynet.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: achill@matrix.gatewaynet.com, bruno@wolff.to, lists@darrenmackay.com
  Subject: Re: query not using index for descending records?
  In-Reply-To: <Pine.LNX.4.44.0401291525350.9854-100000@matrix.gatewaynet.com>

* 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