Re: Determining which index to create

From: Eric Cholet <cholet(at)logilune(dot)com>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Determining which index to create
Date: 2001-11-21 11:53:09
Message-ID: 699688866.1006347189@[192.168.1.14]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--On mercredi 21 novembre 2001 22:48 +1100 Martijn van Oosterhout
<kleptog(at)svana(dot)org> wrote:

> On Wed, Nov 21, 2001 at 12:23:07PM +0100, Eric Cholet wrote:
>> I would like to optimize the following query:
>>
>> => select * from dico_frs where motid=4742 order by date desc limit 10;
>>
>> But it's still quite slow. I'm thinking an index on (motid, date desc)
>> would be best
>> but that doesn't seem to be possible. How can I optimize this query?
>
> Indexes (at least btree ones) can be scanned in either forward or backward
> directions. So an index on (motid,date) should be fine.

I should have mentionned I tried that, but it isn't being used:

=> \d dico_frs_motid_date
Index "dico_frs_motid_date"
Attribute | Type
-----------+--------------------------
motid | integer
date | timestamp with time zone
btree

=> explain select * from dico_frs where motid=4742 order by date desc limit
10;
NOTICE: QUERY PLAN:

Limit (cost=0.00..17591.91 rows=10 width=16)
-> Index Scan Backward using dico_frs_date on dico_frs
(cost=0.00..20023641.63 rows=11382 width=16)

--
Eric Cholet

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message PostgreSQL List User 2001-11-21 12:06:07 ODBC with SSL...
Previous Message Martijn van Oosterhout 2001-11-21 11:48:22 Re: Determining which index to create