Re: [PERFORM] select max() much slower than select min()

2009-06-19 Thread David Rees
On Fri, Jun 19, 2009 at 2:05 PM, Brian Cox wrote: > David Rees [dree...@gmail.com] wrote: >> >> Along those lines, couldn't you just have the DB do the work? >> >> select max(ts_id), min(ts_id) from ... where ts_interval_start_time >= >> ... and ... >> >> Then you don't have to transfer 500k ids ac

Re: [PERFORM] select max() much slower than select min()

2009-06-19 Thread Brian Cox
David Rees [dree...@gmail.com] wrote: Along those lines, couldn't you just have the DB do the work? select max(ts_id), min(ts_id) from ... where ts_interval_start_time >= ... and ... Then you don't have to transfer 500k ids across the network... I guess you didn't read the entire thread: I star

Re: [PERFORM] select max() much slower than select min()

2009-06-19 Thread David Rees
On Fri, Jun 19, 2009 at 1:05 PM, Brian Cox wrote: > Thanks to all for the analysis and suggestions. Since the number of rows in > an hour < ~500,000, brute force looks to be a fast solution: > > select ts_id from ... where ts_interval_start_time >= ... and ... > > This query runs very fast as does

Re: [PERFORM] select max() much slower than select min()

2009-06-19 Thread Brian Cox
Tom Lane [...@sss.pgh.pa.us] wrote: Some experimentation suggests that it might help to provide a 2-column index on (ts_id, ts_interval_start_time). This is still going to be scanned in order by ts_id, but it will be possible to check the ts_interval_start_time condition in the index, eliminatin

Re: [PERFORM] select max() much slower than select min()

2009-06-19 Thread Greg Stark
On Fri, Jun 19, 2009 at 3:26 PM, Tom Lane wrote: > > That's the problem then.  Notice what the query plan is doing: it's > scanning the table in order by ts_id, looking for the first row that > falls within the ts_interval_start_time range.  Evidently this > particular range is associated with smal

Re: [PERFORM] select max() much slower than select min()

2009-06-19 Thread Tom Lane
Brian Cox writes: > Kevin Grittner [kevin.gritt...@wicourts.gov] wrote: >> Is there any correlation between ts_id and ts_interval_start_time? > only vaguely: increasing ts_interval_start_time implies increasing ts_id > but there may be many rows (100,000's) with the same ts_interval_start_time

Re: [PERFORM] select max() much slower than select min()

2009-06-19 Thread Dave Dutcher
> -Original Message- > From: Brian Cox > Subject: [PERFORM] select max() much slower than select min() > > seems like max() shouldn't take any longer than min() and > certainly not 10 times as long. Any ideas on how to determine > the max more quickly? That is odd. It seems like max

Re: [PERFORM] select max() much slower than select min()

2009-06-18 Thread Kevin Grittner
Brian Cox wrote: > Kevin Grittner [kevin.gritt...@wicourts.gov] wrote: >> Is there any correlation between ts_id and ts_interval_start_time? > only vaguely: increasing ts_interval_start_time implies increasing > ts_id but there may be many rows (100,000's) with the same > ts_interval_start_time >

Re: [PERFORM] select max() much slower than select min()

2009-06-18 Thread Brian Cox
Kevin Grittner [kevin.gritt...@wicourts.gov] wrote: Is there any correlation between ts_id and ts_interval_start_time? only vaguely: increasing ts_interval_start_time implies increasing ts_id but there may be many rows (100,000's) with the same ts_interval_start_time Perhaps if you tried min

Re: [PERFORM] select max() much slower than select min()

2009-06-18 Thread Kevin Grittner
Brian Cox wrote: > cemdb=# explain select min(ts_id) from > ts_stats_transet_user_interval a > where 0=0 and a.ts_interval_start_time >= '2009-6-16 01:00' and > a.ts_interval_start_time < '2009-6-16 02:00'; > seems like max() shouldn't take any longer than min() and certainly > not 10 times