Re: Difference in query plan when using = or > in where clause

From: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
To: Radhika S <radhika(dot)sambamurti(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Difference in query plan when using = or > in where clause
Date: 2007-09-27 12:39:07
Message-ID: 46FBA46B.2080903@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Radhika S wrote:
> I am curious as to why this occurs. Why does an = change the query plan so
> drastically?
>
> When my query is:
> Select count(*) from View_A WHERE tradedate = '20070801';
> The query plan is as below:
> ...
> But when my query is:
> Select count(*) from View_A WHERE tradedate BETWEEN '20070801' and
> '20070901';
> The query plan is:
> ...

In short, the planner estimates that "tradedate BETWEEN '20070801' and
'20070901'" matches more rows than "tradatedate = '20070801'"

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2007-09-27 14:40:25 Re: Searching for the cause of a bad plan
Previous Message Csaba Nagy 2007-09-27 11:53:24 Re: Searching for the cause of a bad plan