Search Postgresql Archives

Re: View's plan not taking advantage of WHERE?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jun 5, 2013 at 6:01 AM, Mike Summers <msummers57@xxxxxxxxx> 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.


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux