Re: BUG #2658: Query not using index

From: Graham Davis <gdavis(at)refractions(dot)net>
To: Chris Browne <cbbrowne(at)acm(dot)org>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: BUG #2658: Query not using index
Date: 2006-10-03 19:13:43
Message-ID: 4522B667.3060002@refractions.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-performance

Also, the multikey index of (assetid, ts) would already be sorted and
that is why using such an index in this case is
faster than doing a sequential scan that does the sorting afterwards.

Graham.

Chris Browne wrote:

>gdavis(at)refractions(dot)net (Graham Davis) writes:
>
>
>>Adding DESC to both columns in the SORT BY did not make the query use
>>the multikey index. So both
>>
>>SELECT DISTINCT ON (assetid) assetid, ts
>>FROM asset_positions ORDER BY assetid, ts DESC;
>>
>>and
>>
>>SELECT DISTINCT ON (assetid) assetid, ts
>>FROM asset_positions ORDER BY assetid DESC, ts DESC;
>>
>>use the same query plans and both do sequential scans without using
>>either the (assetid, ts) or (ts) indexes. Any other ideas on how to
>>make this query use an index? Thanks,
>>
>>
>
>Why do you want to worsen performance by forcing the use of an index?
>
>You are reading through the entire table, after all, and doing so via
>a sequential scan is normally the fastest way to do that. An index
>scan would only be more efficient if you don't have enough space in
>memory to store all assetid values.
>
>

--
Graham Davis
Refractions Research Inc.
gdavis(at)refractions(dot)net

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2006-10-03 19:17:12 Re: drop view stalled during pg_dump
Previous Message Graham Davis 2006-10-03 19:10:49 Re: BUG #2658: Query not using index

Browse pgsql-performance by date

  From Date Subject
Next Message Chris Browne 2006-10-03 19:18:36 Re: BUG #2658: Query not using index
Previous Message Graham Davis 2006-10-03 19:10:49 Re: BUG #2658: Query not using index