Re: Bad Query Plan with Range Query

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Mark Williams" <mark(dot)williams(at)jivesoftware(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Bad Query Plan with Range Query
Date: 2011-04-15 18:13:26
Message-ID: 4DA84476020000250003C8A2@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Mark Williams <mark(dot)williams(at)jivesoftware(dot)com> 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 where modificationDate >= 1302627793988 or do you
want the messageID of some row (possibly of many) with the minimum
modificationDate where modificationDate >= 1302627793988?

Since you're asking for a logically different value with that query,
it's not surprising it uses a different plan.

-Kevin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Mark Williams 2011-04-15 22:29:10 Re: Bad Query Plan with Range Query
Previous Message Mark Williams 2011-04-15 18:06:51 Re: Bad Query Plan with Range Query