From: | Mark Lewis <mark(dot)lewis(at)mir3(dot)com> |
---|---|
To: | gdavis(at)refractions(dot)net |
Cc: | Chris Browne <cbbrowne(at)acm(dot)org>, pgsql-performance(at)postgresql(dot)org |
Subject: | Re: BUG #2658: Query not using index |
Date: | 2006-10-03 21:06:52 |
Message-ID: | 1159909612.18640.80.camel@archimedes |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-performance |
Have you looked into a materialized view sort of approach? You could
create a table which had assetid as a primary key, and max_ts as a
column. Then use triggers to keep that table up to date as rows are
added/updated/removed from the main table.
This approach would only make sense if there were far fewer distinct
assetid values than rows in the main table, and would get slow if you
commonly delete rows from the main table or decrease the value for ts in
the row with the highest ts for a given assetid.
-- Mark Lewis
On Tue, 2006-10-03 at 13:52 -0700, Graham Davis wrote:
> Thanks Tom, that explains it and makes sense. I guess I will have to
> accept this query taking 40 seconds, unless I can figure out another way
> to write it so it can use indexes. If there are any more syntax
> suggestions, please pass them on. Thanks for the help everyone.
>
> Graham.
>
>
> Tom Lane wrote:
>
> >Graham Davis <gdavis(at)refractions(dot)net> writes:
> >
> >
> >>How come an aggreate like that has to use a sequential scan? I know
> >>that PostgreSQL use to have to do a sequential scan for all aggregates,
> >>but there was support added to version 8 so that aggregates would take
> >>advantage of indexes.
> >>
> >>
> >
> >Not in a GROUP BY context, only for the simple case. Per the comment in
> >planagg.c:
> >
> > * We don't handle GROUP BY, because our current implementations of
> > * grouping require looking at all the rows anyway, and so there's not
> > * much point in optimizing MIN/MAX.
> >
> >The problem is that using an index to obtain the maximum value of ts for
> >a given value of assetid is not the same thing as finding out what all
> >the distinct values of assetid are.
> >
> >This could possibly be improved but it would take a considerable amount
> >more work. It's definitely not in the category of "bug fix".
> >
> > regards, tom lane
> >
> >
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Graham Davis | 2006-10-03 21:23:26 | Re: BUG #2658: Query not using index |
Previous Message | Graham Davis | 2006-10-03 20:52:28 | Re: BUG #2658: Query not using index |
From | Date | Subject | |
---|---|---|---|
Next Message | Graham Davis | 2006-10-03 21:23:26 | Re: BUG #2658: Query not using index |
Previous Message | Graham Davis | 2006-10-03 20:52:28 | Re: BUG #2658: Query not using index |