Re: huge disparities in =/IN/BETWEEN performance

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joe <dev(at)freedomcircle(dot)net>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, George Pavlov <gpavlov(at)mynewplace(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: huge disparities in =/IN/BETWEEN performance
Date: 2007-02-09 14:26:52
Message-ID: 24132.1171031212@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Joe <dev(at)freedomcircle(dot)net> writes:
> George didn't provide the inside of his view, but it's
> possible that my earlier example could be rephrased as follows:
> create view v_foo as select * from tab where x < 5;
> select * from v_foo where x = 10;

So try it:

regression=# create table tab (x int);
CREATE TABLE
regression=# create view v_foo as select * from tab where x < 5;
CREATE VIEW
regression=# explain select * from v_foo where x = 10;
QUERY PLAN
----------------------------------------------------
Seq Scan on tab (cost=0.00..46.00 rows=4 width=4)
Filter: ((x < 5) AND (x = 10))
(2 rows)

regression=# set constraint_exclusion to 1;
SET
regression=# explain select * from v_foo where x = 10;
QUERY PLAN
------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0)
One-Time Filter: false
(2 rows)

(This is with HEAD, but I think 8.2 can do it too.)

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2007-02-09 15:24:37 Re: dynamic sql
Previous Message Gabriel Adolfo Sirni 2007-02-09 14:15:03 dynamic sql