From: | Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> |
---|---|
To: | Mike Summers <msummers57(at)gmail(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: View's plan not taking advantage of WHERE? |
Date: | 2013-06-05 12:08:22 |
Message-ID: | CAOR=d=0rt=8FZ0AM2gRqx1Sv7Mog4BSc5RMAO=a8DC6c3cCxsw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Jun 5, 2013 at 6:01 AM, Mike Summers <msummers57(at)gmail(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2013-06-05 12:09:37 | Re: View's plan not taking advantage of WHERE? |
Previous Message | Mike Summers | 2013-06-05 12:01:43 | Re: View's plan not taking advantage of WHERE? |