Re: Re agregates

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de>
Cc: david(at)matraex(dot)com, pgsql-general(at)postgresql(dot)org
Subject: Re: Re agregates
Date: 2003-01-22 22:37:53
Message-ID: 24906.1043275073@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Christoph Dalitz <christoph(dot)dalitz(at)hs-niederrhein(dot)de> writes:
> You can directly get the "max - 1" with "order by desc" and "limit"
> and "offset". It's worth a try whether that is faster (I would
> suspect that it is O(n*log(n)) compared to O(n^2) in your "max from
> max" query).

Given an index on the thing(s) being ordered by, it should be more like
O(log(n)) time: the system will only have to go to the right place in the
index (taking O(log(n)) for a btree search) and then step two index
entries (constant time).

It may not be practical to index this query, but if it is, the LIMIT
method will blow the doors off anything that involves MAX().

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Björn Metzdorf 2003-01-22 22:43:22 tsearch comments
Previous Message Medi Montaseri 2003-01-22 22:20:43 When to Vacuum