Re: View's plan not taking advantage of WHERE? - Mailing list pgsql-general

From Scott Marlowe
Subject Re: View's plan not taking advantage of WHERE?
Date
Msg-id CAOR=d=0rt=8FZ0AM2gRqx1Sv7Mog4BSc5RMAO=a8DC6c3cCxsw@mail.gmail.com
Whole thread Raw
In response to Re: View's plan not taking advantage of WHERE?  (Mike Summers <msummers57@gmail.com>)
Responses Re: View's plan not taking advantage of WHERE?  (Scott Marlowe <scott.marlowe@gmail.com>)
List pgsql-general
On Wed, Jun 5, 2013 at 6:01 AM, Mike Summers <msummers57@gmail.com> wrote:
> From what I'm reading the View is frozen when it's created, including it's
> plan, and the usual solution is to use a set returning function... is this
> not true?

No it is not.  Here:

smarlowe=# create table a (id int);
CREATE TABLE
smarlowe=# create index a_id on a(id);
CREATE INDEX
smarlowe=# insert into a values (1),(2),(3);
INSERT 0 3
smarlowe=# create view x as select * from a;
CREATE VIEW

smarlowe=# analyze a;
ANALYZE
smarlowe=# show enable_seqscan;
 enable_seqscan
----------------
 on
(1 row)
smarlowe=# explain select * from x where id=1;
                   QUERY PLAN
-------------------------------------------------
 Seq Scan on a  (cost=0.00..1.04 rows=1 width=4)
   Filter: (id = 1)
(2 rows)

smarlowe=# set enable_seqscan =off;
SET
smarlowe=# explain select * from x where id=1;
                          QUERY PLAN
--------------------------------------------------------------
 Index Scan using a_id on a  (cost=0.00..8.27 rows=1 width=4)
   Index Cond: (id = 1)
(2 rows)

smarlowe=#

> I've double checked all schemas and the view is only defined once.

Well you're gonna have to come up with some kind of self-contained
test to show what's happening then.


pgsql-general by date:

Previous
From: Mike Summers
Date:
Subject: Re: View's plan not taking advantage of WHERE?
Next
From: Scott Marlowe
Date:
Subject: Re: View's plan not taking advantage of WHERE?