Re: How to speed up min/max(id) in 50M rows table?

From: henk de wit <henk53602(at)hotmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: How to speed up min/max(id) in 50M rows table?
Date: 2007-10-12 23:13:38
Message-ID: BAY124-W29CDC818248B126A5DD81F5A00@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> It's possible to combine independent indexes for resolving AND-type
> queries, but the combination process does not preserve ordering, so
> it's useless for this type of situation.

Ok, I'm going to try the double column index. Your suggestion about the index with nulls left out worked great btw. Min/Max is instantly now.

I figure though that the double column index would not work for queries like:

select min(time) from transactions where payment_id is null

So for that situation I tried whether a specific index helped, i.e. :

create index transactions__time_payment_id__null__idx on transactions(time) where payment_id is null;

But this does not really seem to help. It might be better to see if I can refactor the DB design though to not use nulls.

Regards

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message henk de wit 2007-10-12 23:48:23 Re: How to speed up min/max(id) in 50M rows table?
Previous Message Tom Lane 2007-10-12 22:51:03 Re: How to speed up min/max(id) in 50M rows table?