-- create a materialized view with no data, and confirm correct behavior
EXPLAIN (costs off)
CREATE MATERIALIZED VIEW tm AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type WITH NO DATA;
- QUERY PLAN
----------------------
+ QUERY PLAN
+-----------------------------------------------------------
HashAggregate
Group Key: type
- -> Seq Scan on t
-(3 rows)
+ -> Remote Subquery Scan on all (datanode_1,datanode_2)
+ -> HashAggregate
+ Group Key: type
+ -> Seq Scan on t
+(6 rows)
CREATE MATERIALIZED VIEW tm AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type WITH NO DATA;
SELECT relispopulated FROM pg_class WHERE oid = 'tm'::regclass;
-- create various views
EXPLAIN (costs off)
CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv ORDER BY type;
- QUERY PLAN
----------------------------
+ QUERY PLAN
+-----------------------------------------------------------------
Sort
Sort Key: t.type
-> HashAggregate
Group Key: t.type
- -> Seq Scan on t
-(5 rows)
+ -> Remote Subquery Scan on all (datanode_1,datanode_2)
+ -> HashAggregate
+ Group Key: t.type
+ -> Seq Scan on t
+(8 rows)
CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv ORDER BY type;
SELECT * FROM tvm;
CREATE VIEW tvv AS SELECT sum(totamt) AS grandtot FROM tv;
EXPLAIN (costs off)
CREATE MATERIALIZED VIEW tvvm AS SELECT * FROM tvv;
- QUERY PLAN
----------------------------
+ QUERY PLAN
+-----------------------------------------------------------------
Aggregate
-> HashAggregate
Group Key: t.type
- -> Seq Scan on t
-(4 rows)
+ -> Remote Subquery Scan on all (datanode_1,datanode_2)
+ -> HashAggregate
+ Group Key: t.type
+ -> Seq Scan on t
+(7 rows)
CREATE MATERIALIZED VIEW tvvm AS SELECT * FROM tvv;
CREATE VIEW tvvmv AS SELECT * FROM tvvm;