Determining which index to create

From: Eric Cholet <cholet(at)logilune(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Determining which index to create
Date: 2001-11-21 11:23:07
Message-ID: 697886661.1006345387@[192.168.1.14]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have the following table :

Attribute | Type | Modifier
-----------+--------------------------+----------
motid | integer | not null
objid | integer | not null
date | timestamp with time zone | not null

...with 140 million rows. For each distinct value of
motid there are many rows (with different objid/dates).
I would like to optimize the following query:

=> select * from dico_frs where motid=4742 order by date desc limit 10;

Creating an index on 'date' makes the query use that index:

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)

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?

--
Eric Cholet

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Roman Havrylyak 2001-11-21 11:37:45 What size of block should I choose?
Previous Message kucol 2001-11-21 11:06:11 Localization problems