Which indexes does a query use?

From: "Chris Velevitch" <chris(dot)velevitch(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Which indexes does a query use?
Date: 2006-02-27 00:09:23
Message-ID: b0a3bf780602261609p52bf47bay92b3b27c270a6043@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In pg v7.4.5, I have this query:-

select *
from activities
where activity_user_id = 2 and activity_type = 1 and activity_ts < now()
order by activity_ts desc
limit 1;

where activity_user_id is a non-unique index and activity_ts is a
non-unique index.

When I explain it, I get:-

Limit (cost=46.33..46.34 rows=1 width=58)
-> Sort (cost=46.33..46.34 rows=1 width=58)
Sort Key: activity_ts
-> Seq Scan on activities (cost=0.00..46.32 rows=1 width=58)
Filter: ((activity_user_id = 2) AND (activity_type = 1)
AND ((activity_ts)::timestamp with time zone < now()))

If I'm reading this right, it's telling me that is NOT using any indexes.

Clearly, this is wrong. I would have expected that index on
activity_user_id would have been used to help find all the records
efficiently.

Chris
--
Chris Velevitch
Manager - Sydney Flash Platform Developers Group
www.flashdev.org.au

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Russell Smith 2006-02-27 00:19:32 Re: Which indexes does a query use?
Previous Message Chris 2006-02-26 23:58:15 Re: Wish: remove ancient constructs from Postgres