Re: [PERFORM] Bad Query Plan with Range Query

2011-04-15 Thread Mark Williams
Whoops, I meant this query (ordering my messageid): SELECT messageID FROM Message WHERE modificationDate>= 1302627793988 ORDER BY messageID LIMIT 1; Sometimes this gives the better plan. But not always. On 04/15/2011 11:13 AM, Kevin Grittner wrote: Mark Williams wrote: If I re-write th

Re: [PERFORM] Bad Query Plan with Range Query

2011-04-15 Thread Kevin Grittner
Mark Williams wrote: > If I re-write the query like this: > > explain SELECT messageID FROM Message WHERE modificationDate >= > 1302627793988 ORDER BY modificationDate LIMIT 1; > I also get a better plan. Yeah, but it's not necessarily the same value. Do you want the minimum messageID whe

Re: [PERFORM] Bad Query Plan with Range Query

2011-04-15 Thread Mark Williams
Thanks for the response guys. There is something else which confuses me. If I re-write the query like this: explain SELECT messageID FROM Message WHERE modificationDate >= 1302627793988 ORDER BY modificationDate LIMIT 1; QUERY PLAN ---

Re: [PERFORM] Bad Query Plan with Range Query

2011-04-15 Thread Kevin Grittner
Mark Williams wrote: > explain SELECT min(messageID) FROM Message > WHERE modificationDate >= 1302627793988; > For some reason it is deciding to scan the primary key column of > the table. This results in scanning the entire table No, it scans until it finds the first row where modificatio

Re: [PERFORM] Bad Query Plan with Range Query

2011-04-15 Thread Kenneth Marshall
On Fri, Apr 15, 2011 at 10:17:32AM -0700, Mark Williams wrote: > We are experiencing a problem with our query plans when using a range query > in Postgresql 8.3. The query we are executing attempts to select the > minimum primary key id after a certain date. Our date columns are bigint's > holdi