Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: BUG #2658: Query not using index


  • From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
  • To: Mark Lewis <mark(dot)lewis(at)mir3(dot)com>
  • Cc: gdavis(at)refractions(dot)net, Chris Browne <cbbrowne(at)acm(dot)org>, pgsql-performance(at)postgresql(dot)org
  • Subject: Re: BUG #2658: Query not using index
  • Date: Tue, 03 Oct 2006 18:39:32 -0400
  • Message-id: <25227(dot)1159915172(at)sss(dot)pgh(dot)pa(dot)us>

Mark Lewis <mark(dot)lewis(at)mir3(dot)com> writes:
> Have you considered creating one partial index per assetid?  Something
> along the lines of "CREATE INDEX asset_index_N ON asset_positions(ts)
> WHERE assetid=N"?  I'd guess that the planner probably wouldn't be smart
> enough to use the partial indexes unless you issued a separate query for
> each assetid, but each one of those queries should be really fast.

Actually, a single index on (assetid, ts) is sufficient to handle

	select max(ts) from asset_positions where assetid = constant

The problem is to know what values of "constant" to issue the query for,
and this idea doesn't seem to help with that.

If Graham is willing to assume that the set of assetids changes slowly,
perhaps he could keep a summary table that contains all the valid
assetids (or maybe there already is such a table?  is assetid a foreign
key?) and do

	select pk.assetid,
               (select max(ts) from asset_positions where assetid = pk.assetid)
	from other_table pk;

I'm pretty sure the subselect would be planned the way he wants.

			regards, tom lane



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group