Commit 4447f0bc authored by Tom Lane's avatar Tom Lane

Use less-generic names in matview.sql.

The original coding of this test used table and view names like "t",
"tv", "foo", etc.  This tended to interfere with doing simple manual
tests in the regression database; not to mention that it posed a
considerable risk of conflict with other regression test scripts.
Prefix these names with "mvtest_" to avoid such conflicts.

Also, change transiently-created role name to be "regress_xxx" per
discussions about being careful with regression-test role creation.
parent 8f1911d5
-- create a table to use as a basis for views and materialized views in various combinations -- create a table to use as a basis for views and materialized views in various combinations
CREATE TABLE t (id int NOT NULL PRIMARY KEY, type text NOT NULL, amt numeric NOT NULL); CREATE TABLE mvtest_t (id int NOT NULL PRIMARY KEY, type text NOT NULL, amt numeric NOT NULL);
INSERT INTO t VALUES INSERT INTO mvtest_t VALUES
(1, 'x', 2), (1, 'x', 2),
(2, 'x', 3), (2, 'x', 3),
(3, 'y', 5), (3, 'y', 5),
(4, 'y', 7), (4, 'y', 7),
(5, 'z', 11); (5, 'z', 11);
-- we want a view based on the table, too, since views present additional challenges -- we want a view based on the table, too, since views present additional challenges
CREATE VIEW tv AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type; CREATE VIEW mvtest_tv AS SELECT type, sum(amt) AS totamt FROM mvtest_t GROUP BY type;
SELECT * FROM tv ORDER BY type; SELECT * FROM mvtest_tv ORDER BY type;
type | totamt type | totamt
------+-------- ------+--------
x | 5 x | 5
...@@ -18,33 +18,33 @@ SELECT * FROM tv ORDER BY type; ...@@ -18,33 +18,33 @@ SELECT * FROM tv ORDER BY type;
-- create a materialized view with no data, and confirm correct behavior -- create a materialized view with no data, and confirm correct behavior
EXPLAIN (costs off) EXPLAIN (costs off)
CREATE MATERIALIZED VIEW tm AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type WITH NO DATA; CREATE MATERIALIZED VIEW mvtest_tm AS SELECT type, sum(amt) AS totamt FROM mvtest_t GROUP BY type WITH NO DATA;
QUERY PLAN QUERY PLAN
--------------------- ----------------------------
HashAggregate HashAggregate
Group Key: type Group Key: type
-> Seq Scan on t -> Seq Scan on mvtest_t
(3 rows) (3 rows)
CREATE MATERIALIZED VIEW tm AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type WITH NO DATA; CREATE MATERIALIZED VIEW mvtest_tm AS SELECT type, sum(amt) AS totamt FROM mvtest_t GROUP BY type WITH NO DATA;
SELECT relispopulated FROM pg_class WHERE oid = 'tm'::regclass; SELECT relispopulated FROM pg_class WHERE oid = 'mvtest_tm'::regclass;
relispopulated relispopulated
---------------- ----------------
f f
(1 row) (1 row)
SELECT * FROM tm; SELECT * FROM mvtest_tm;
ERROR: materialized view "tm" has not been populated ERROR: materialized view "mvtest_tm" has not been populated
HINT: Use the REFRESH MATERIALIZED VIEW command. HINT: Use the REFRESH MATERIALIZED VIEW command.
REFRESH MATERIALIZED VIEW tm; REFRESH MATERIALIZED VIEW mvtest_tm;
SELECT relispopulated FROM pg_class WHERE oid = 'tm'::regclass; SELECT relispopulated FROM pg_class WHERE oid = 'mvtest_tm'::regclass;
relispopulated relispopulated
---------------- ----------------
t t
(1 row) (1 row)
CREATE UNIQUE INDEX tm_type ON tm (type); CREATE UNIQUE INDEX mvtest_tm_type ON mvtest_tm (type);
SELECT * FROM tm; SELECT * FROM mvtest_tm;
type | totamt type | totamt
------+-------- ------+--------
y | 12 y | 12
...@@ -54,18 +54,18 @@ SELECT * FROM tm; ...@@ -54,18 +54,18 @@ SELECT * FROM tm;
-- create various views -- create various views
EXPLAIN (costs off) EXPLAIN (costs off)
CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv ORDER BY type; CREATE MATERIALIZED VIEW mvtest_tvm AS SELECT * FROM mvtest_tv ORDER BY type;
QUERY PLAN QUERY PLAN
--------------------------- ----------------------------------
Sort Sort
Sort Key: t.type Sort Key: mvtest_t.type
-> HashAggregate -> HashAggregate
Group Key: t.type Group Key: mvtest_t.type
-> Seq Scan on t -> Seq Scan on mvtest_t
(5 rows) (5 rows)
CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv ORDER BY type; CREATE MATERIALIZED VIEW mvtest_tvm AS SELECT * FROM mvtest_tv ORDER BY type;
SELECT * FROM tvm; SELECT * FROM mvtest_tvm;
type | totamt type | totamt
------+-------- ------+--------
x | 5 x | 5
...@@ -73,103 +73,103 @@ SELECT * FROM tvm; ...@@ -73,103 +73,103 @@ SELECT * FROM tvm;
z | 11 z | 11
(3 rows) (3 rows)
CREATE MATERIALIZED VIEW tmm AS SELECT sum(totamt) AS grandtot FROM tm; CREATE MATERIALIZED VIEW mvtest_tmm AS SELECT sum(totamt) AS grandtot FROM mvtest_tm;
CREATE MATERIALIZED VIEW tvmm AS SELECT sum(totamt) AS grandtot FROM tvm; CREATE MATERIALIZED VIEW mvtest_tvmm AS SELECT sum(totamt) AS grandtot FROM mvtest_tvm;
CREATE UNIQUE INDEX tvmm_expr ON tvmm ((grandtot > 0)); CREATE UNIQUE INDEX mvtest_tvmm_expr ON mvtest_tvmm ((grandtot > 0));
CREATE UNIQUE INDEX tvmm_pred ON tvmm (grandtot) WHERE grandtot < 0; CREATE UNIQUE INDEX mvtest_tvmm_pred ON mvtest_tvmm (grandtot) WHERE grandtot < 0;
CREATE VIEW tvv AS SELECT sum(totamt) AS grandtot FROM tv; CREATE VIEW mvtest_tvv AS SELECT sum(totamt) AS grandtot FROM mvtest_tv;
EXPLAIN (costs off) EXPLAIN (costs off)
CREATE MATERIALIZED VIEW tvvm AS SELECT * FROM tvv; CREATE MATERIALIZED VIEW mvtest_tvvm AS SELECT * FROM mvtest_tvv;
QUERY PLAN QUERY PLAN
--------------------------- ----------------------------------
Aggregate Aggregate
-> HashAggregate -> HashAggregate
Group Key: t.type Group Key: mvtest_t.type
-> Seq Scan on t -> Seq Scan on mvtest_t
(4 rows) (4 rows)
CREATE MATERIALIZED VIEW tvvm AS SELECT * FROM tvv; CREATE MATERIALIZED VIEW mvtest_tvvm AS SELECT * FROM mvtest_tvv;
CREATE VIEW tvvmv AS SELECT * FROM tvvm; CREATE VIEW mvtest_tvvmv AS SELECT * FROM mvtest_tvvm;
CREATE MATERIALIZED VIEW bb AS SELECT * FROM tvvmv; CREATE MATERIALIZED VIEW mvtest_bb AS SELECT * FROM mvtest_tvvmv;
CREATE INDEX aa ON bb (grandtot); CREATE INDEX mvtest_aa ON mvtest_bb (grandtot);
-- check that plans seem reasonable -- check that plans seem reasonable
\d+ tvm \d+ mvtest_tvm
Materialized view "public.tvm" Materialized view "public.mvtest_tvm"
Column | Type | Modifiers | Storage | Stats target | Description Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+----------+--------------+------------- --------+---------+-----------+----------+--------------+-------------
type | text | | extended | | type | text | | extended | |
totamt | numeric | | main | | totamt | numeric | | main | |
View definition: View definition:
SELECT tv.type, SELECT mvtest_tv.type,
tv.totamt mvtest_tv.totamt
FROM tv FROM mvtest_tv
ORDER BY tv.type; ORDER BY mvtest_tv.type;
\d+ tvm \d+ mvtest_tvm
Materialized view "public.tvm" Materialized view "public.mvtest_tvm"
Column | Type | Modifiers | Storage | Stats target | Description Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+----------+--------------+------------- --------+---------+-----------+----------+--------------+-------------
type | text | | extended | | type | text | | extended | |
totamt | numeric | | main | | totamt | numeric | | main | |
View definition: View definition:
SELECT tv.type, SELECT mvtest_tv.type,
tv.totamt mvtest_tv.totamt
FROM tv FROM mvtest_tv
ORDER BY tv.type; ORDER BY mvtest_tv.type;
\d+ tvvm \d+ mvtest_tvvm
Materialized view "public.tvvm" Materialized view "public.mvtest_tvvm"
Column | Type | Modifiers | Storage | Stats target | Description Column | Type | Modifiers | Storage | Stats target | Description
----------+---------+-----------+---------+--------------+------------- ----------+---------+-----------+---------+--------------+-------------
grandtot | numeric | | main | | grandtot | numeric | | main | |
View definition: View definition:
SELECT tvv.grandtot SELECT mvtest_tvv.grandtot
FROM tvv; FROM mvtest_tvv;
\d+ bb \d+ mvtest_bb
Materialized view "public.bb" Materialized view "public.mvtest_bb"
Column | Type | Modifiers | Storage | Stats target | Description Column | Type | Modifiers | Storage | Stats target | Description
----------+---------+-----------+---------+--------------+------------- ----------+---------+-----------+---------+--------------+-------------
grandtot | numeric | | main | | grandtot | numeric | | main | |
Indexes: Indexes:
"aa" btree (grandtot) "mvtest_aa" btree (grandtot)
View definition: View definition:
SELECT tvvmv.grandtot SELECT mvtest_tvvmv.grandtot
FROM tvvmv; FROM mvtest_tvvmv;
-- test schema behavior -- test schema behavior
CREATE SCHEMA mvschema; CREATE SCHEMA mvtest_mvschema;
ALTER MATERIALIZED VIEW tvm SET SCHEMA mvschema; ALTER MATERIALIZED VIEW mvtest_tvm SET SCHEMA mvtest_mvschema;
\d+ tvm \d+ mvtest_tvm
\d+ tvmm \d+ mvtest_tvmm
Materialized view "public.tvmm" Materialized view "public.mvtest_tvmm"
Column | Type | Modifiers | Storage | Stats target | Description Column | Type | Modifiers | Storage | Stats target | Description
----------+---------+-----------+---------+--------------+------------- ----------+---------+-----------+---------+--------------+-------------
grandtot | numeric | | main | | grandtot | numeric | | main | |
Indexes: Indexes:
"tvmm_expr" UNIQUE, btree ((grandtot > 0::numeric)) "mvtest_tvmm_expr" UNIQUE, btree ((grandtot > 0::numeric))
"tvmm_pred" UNIQUE, btree (grandtot) WHERE grandtot < 0::numeric "mvtest_tvmm_pred" UNIQUE, btree (grandtot) WHERE grandtot < 0::numeric
View definition: View definition:
SELECT sum(tvm.totamt) AS grandtot SELECT sum(mvtest_tvm.totamt) AS grandtot
FROM mvschema.tvm; FROM mvtest_mvschema.mvtest_tvm;
SET search_path = mvschema, public; SET search_path = mvtest_mvschema, public;
\d+ tvm \d+ mvtest_tvm
Materialized view "mvschema.tvm" Materialized view "mvtest_mvschema.mvtest_tvm"
Column | Type | Modifiers | Storage | Stats target | Description Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+----------+--------------+------------- --------+---------+-----------+----------+--------------+-------------
type | text | | extended | | type | text | | extended | |
totamt | numeric | | main | | totamt | numeric | | main | |
View definition: View definition:
SELECT tv.type, SELECT mvtest_tv.type,
tv.totamt mvtest_tv.totamt
FROM tv FROM mvtest_tv
ORDER BY tv.type; ORDER BY mvtest_tv.type;
-- modify the underlying table data -- modify the underlying table data
INSERT INTO t VALUES (6, 'z', 13); INSERT INTO mvtest_t VALUES (6, 'z', 13);
-- confirm pre- and post-refresh contents of fairly simple materialized views -- confirm pre- and post-refresh contents of fairly simple materialized views
SELECT * FROM tm ORDER BY type; SELECT * FROM mvtest_tm ORDER BY type;
type | totamt type | totamt
------+-------- ------+--------
x | 5 x | 5
...@@ -177,7 +177,7 @@ SELECT * FROM tm ORDER BY type; ...@@ -177,7 +177,7 @@ SELECT * FROM tm ORDER BY type;
z | 11 z | 11
(3 rows) (3 rows)
SELECT * FROM tvm ORDER BY type; SELECT * FROM mvtest_tvm ORDER BY type;
type | totamt type | totamt
------+-------- ------+--------
x | 5 x | 5
...@@ -185,9 +185,9 @@ SELECT * FROM tvm ORDER BY type; ...@@ -185,9 +185,9 @@ SELECT * FROM tvm ORDER BY type;
z | 11 z | 11
(3 rows) (3 rows)
REFRESH MATERIALIZED VIEW CONCURRENTLY tm; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_tm;
REFRESH MATERIALIZED VIEW tvm; REFRESH MATERIALIZED VIEW mvtest_tvm;
SELECT * FROM tm ORDER BY type; SELECT * FROM mvtest_tm ORDER BY type;
type | totamt type | totamt
------+-------- ------+--------
x | 5 x | 5
...@@ -195,7 +195,7 @@ SELECT * FROM tm ORDER BY type; ...@@ -195,7 +195,7 @@ SELECT * FROM tm ORDER BY type;
z | 24 z | 24
(3 rows) (3 rows)
SELECT * FROM tvm ORDER BY type; SELECT * FROM mvtest_tvm ORDER BY type;
type | totamt type | totamt
------+-------- ------+--------
x | 5 x | 5
...@@ -206,84 +206,84 @@ SELECT * FROM tvm ORDER BY type; ...@@ -206,84 +206,84 @@ SELECT * FROM tvm ORDER BY type;
RESET search_path; RESET search_path;
-- confirm pre- and post-refresh contents of nested materialized views -- confirm pre- and post-refresh contents of nested materialized views
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tmm; SELECT * FROM mvtest_tmm;
QUERY PLAN QUERY PLAN
----------------- ------------------------
Seq Scan on tmm Seq Scan on mvtest_tmm
(1 row) (1 row)
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tvmm; SELECT * FROM mvtest_tvmm;
QUERY PLAN QUERY PLAN
------------------ -------------------------
Seq Scan on tvmm Seq Scan on mvtest_tvmm
(1 row) (1 row)
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tvvm; SELECT * FROM mvtest_tvvm;
QUERY PLAN QUERY PLAN
------------------ -------------------------
Seq Scan on tvvm Seq Scan on mvtest_tvvm
(1 row) (1 row)
SELECT * FROM tmm; SELECT * FROM mvtest_tmm;
grandtot grandtot
---------- ----------
28 28
(1 row) (1 row)
SELECT * FROM tvmm; SELECT * FROM mvtest_tvmm;
grandtot grandtot
---------- ----------
28 28
(1 row) (1 row)
SELECT * FROM tvvm; SELECT * FROM mvtest_tvvm;
grandtot grandtot
---------- ----------
28 28
(1 row) (1 row)
REFRESH MATERIALIZED VIEW tmm; REFRESH MATERIALIZED VIEW mvtest_tmm;
REFRESH MATERIALIZED VIEW CONCURRENTLY tvmm; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_tvmm;
ERROR: cannot refresh materialized view "public.tvmm" concurrently ERROR: cannot refresh materialized view "public.mvtest_tvmm" concurrently
HINT: Create a unique index with no WHERE clause on one or more columns of the materialized view. HINT: Create a unique index with no WHERE clause on one or more columns of the materialized view.
REFRESH MATERIALIZED VIEW tvmm; REFRESH MATERIALIZED VIEW mvtest_tvmm;
REFRESH MATERIALIZED VIEW tvvm; REFRESH MATERIALIZED VIEW mvtest_tvvm;
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tmm; SELECT * FROM mvtest_tmm;
QUERY PLAN QUERY PLAN
----------------- ------------------------
Seq Scan on tmm Seq Scan on mvtest_tmm
(1 row) (1 row)
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tvmm; SELECT * FROM mvtest_tvmm;
QUERY PLAN QUERY PLAN
------------------ -------------------------
Seq Scan on tvmm Seq Scan on mvtest_tvmm
(1 row) (1 row)
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tvvm; SELECT * FROM mvtest_tvvm;
QUERY PLAN QUERY PLAN
------------------ -------------------------
Seq Scan on tvvm Seq Scan on mvtest_tvvm
(1 row) (1 row)
SELECT * FROM tmm; SELECT * FROM mvtest_tmm;
grandtot grandtot
---------- ----------
41 41
(1 row) (1 row)
SELECT * FROM tvmm; SELECT * FROM mvtest_tvmm;
grandtot grandtot
---------- ----------
41 41
(1 row) (1 row)
SELECT * FROM tvvm; SELECT * FROM mvtest_tvvm;
grandtot grandtot
---------- ----------
41 41
...@@ -293,13 +293,13 @@ SELECT * FROM tvvm; ...@@ -293,13 +293,13 @@ SELECT * FROM tvvm;
DROP MATERIALIZED VIEW IF EXISTS no_such_mv; DROP MATERIALIZED VIEW IF EXISTS no_such_mv;
NOTICE: materialized view "no_such_mv" does not exist, skipping NOTICE: materialized view "no_such_mv" does not exist, skipping
-- make sure invalid comination of options is prohibited -- make sure invalid comination of options is prohibited
REFRESH MATERIALIZED VIEW CONCURRENTLY tvmm WITH NO DATA; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_tvmm WITH NO DATA;
ERROR: CONCURRENTLY and WITH NO DATA options cannot be used together ERROR: CONCURRENTLY and WITH NO DATA options cannot be used together
-- no tuple locks on materialized views -- no tuple locks on materialized views
SELECT * FROM tvvm FOR SHARE; SELECT * FROM mvtest_tvvm FOR SHARE;
ERROR: cannot lock rows in materialized view "tvvm" ERROR: cannot lock rows in materialized view "mvtest_tvvm"
-- test join of mv and view -- test join of mv and view
SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM tm m LEFT JOIN tv v USING (type) ORDER BY type; SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM mvtest_tm m LEFT JOIN mvtest_tv v USING (type) ORDER BY type;
type | mtot | vtot type | mtot | vtot
------+------+------ ------+------+------
x | 5 | 5 x | 5 | 5
...@@ -308,53 +308,53 @@ SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM tm m LEFT JOIN tv v USING ( ...@@ -308,53 +308,53 @@ SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM tm m LEFT JOIN tv v USING (
(3 rows) (3 rows)
-- make sure that dependencies are reported properly when they block the drop -- make sure that dependencies are reported properly when they block the drop
DROP TABLE t; DROP TABLE mvtest_t;
ERROR: cannot drop table t because other objects depend on it ERROR: cannot drop table mvtest_t because other objects depend on it
DETAIL: view tv depends on table t DETAIL: view mvtest_tv depends on table mvtest_t
view tvv depends on view tv view mvtest_tvv depends on view mvtest_tv
materialized view tvvm depends on view tvv materialized view mvtest_tvvm depends on view mvtest_tvv
view tvvmv depends on materialized view tvvm view mvtest_tvvmv depends on materialized view mvtest_tvvm
materialized view bb depends on view tvvmv materialized view mvtest_bb depends on view mvtest_tvvmv
materialized view mvschema.tvm depends on view tv materialized view mvtest_mvschema.mvtest_tvm depends on view mvtest_tv
materialized view tvmm depends on materialized view mvschema.tvm materialized view mvtest_tvmm depends on materialized view mvtest_mvschema.mvtest_tvm
materialized view tm depends on table t materialized view mvtest_tm depends on table mvtest_t
materialized view tmm depends on materialized view tm materialized view mvtest_tmm depends on materialized view mvtest_tm
HINT: Use DROP ... CASCADE to drop the dependent objects too. HINT: Use DROP ... CASCADE to drop the dependent objects too.
-- make sure dependencies are dropped and reported -- make sure dependencies are dropped and reported
-- and make sure that transactional behavior is correct on rollback -- and make sure that transactional behavior is correct on rollback
-- incidentally leaving some interesting materialized views for pg_dump testing -- incidentally leaving some interesting materialized views for pg_dump testing
BEGIN; BEGIN;
DROP TABLE t CASCADE; DROP TABLE mvtest_t CASCADE;
NOTICE: drop cascades to 9 other objects NOTICE: drop cascades to 9 other objects
DETAIL: drop cascades to view tv DETAIL: drop cascades to view mvtest_tv
drop cascades to view tvv drop cascades to view mvtest_tvv
drop cascades to materialized view tvvm drop cascades to materialized view mvtest_tvvm
drop cascades to view tvvmv drop cascades to view mvtest_tvvmv
drop cascades to materialized view bb drop cascades to materialized view mvtest_bb
drop cascades to materialized view mvschema.tvm drop cascades to materialized view mvtest_mvschema.mvtest_tvm
drop cascades to materialized view tvmm drop cascades to materialized view mvtest_tvmm
drop cascades to materialized view tm drop cascades to materialized view mvtest_tm
drop cascades to materialized view tmm drop cascades to materialized view mvtest_tmm
ROLLBACK; ROLLBACK;
-- some additional tests not using base tables -- some additional tests not using base tables
CREATE VIEW v_test1 AS SELECT 1 moo; CREATE VIEW mvtest_vt1 AS SELECT 1 moo;
CREATE VIEW v_test2 AS SELECT moo, 2*moo FROM v_test1 UNION ALL SELECT moo, 3*moo FROM v_test1; CREATE VIEW mvtest_vt2 AS SELECT moo, 2*moo FROM mvtest_vt1 UNION ALL SELECT moo, 3*moo FROM mvtest_vt1;
\d+ v_test2 \d+ mvtest_vt2
View "public.v_test2" View "public.mvtest_vt2"
Column | Type | Modifiers | Storage | Description Column | Type | Modifiers | Storage | Description
----------+---------+-----------+---------+------------- ----------+---------+-----------+---------+-------------
moo | integer | | plain | moo | integer | | plain |
?column? | integer | | plain | ?column? | integer | | plain |
View definition: View definition:
SELECT v_test1.moo, SELECT mvtest_vt1.moo,
2 * v_test1.moo 2 * mvtest_vt1.moo
FROM v_test1 FROM mvtest_vt1
UNION ALL UNION ALL
SELECT v_test1.moo, SELECT mvtest_vt1.moo,
3 * v_test1.moo 3 * mvtest_vt1.moo
FROM v_test1; FROM mvtest_vt1;
CREATE MATERIALIZED VIEW mv_test2 AS SELECT moo, 2*moo FROM v_test2 UNION ALL SELECT moo, 3*moo FROM v_test2; CREATE MATERIALIZED VIEW mv_test2 AS SELECT moo, 2*moo FROM mvtest_vt2 UNION ALL SELECT moo, 3*moo FROM mvtest_vt2;
\d+ mv_test2 \d+ mv_test2
Materialized view "public.mv_test2" Materialized view "public.mv_test2"
Column | Type | Modifiers | Storage | Stats target | Description Column | Type | Modifiers | Storage | Stats target | Description
...@@ -362,13 +362,13 @@ CREATE MATERIALIZED VIEW mv_test2 AS SELECT moo, 2*moo FROM v_test2 UNION ALL SE ...@@ -362,13 +362,13 @@ CREATE MATERIALIZED VIEW mv_test2 AS SELECT moo, 2*moo FROM v_test2 UNION ALL SE
moo | integer | | plain | | moo | integer | | plain | |
?column? | integer | | plain | | ?column? | integer | | plain | |
View definition: View definition:
SELECT v_test2.moo, SELECT mvtest_vt2.moo,
2 * v_test2.moo 2 * mvtest_vt2.moo
FROM v_test2 FROM mvtest_vt2
UNION ALL UNION ALL
SELECT v_test2.moo, SELECT mvtest_vt2.moo,
3 * v_test2.moo 3 * mvtest_vt2.moo
FROM v_test2; FROM mvtest_vt2;
CREATE MATERIALIZED VIEW mv_test3 AS SELECT * FROM mv_test2 WHERE moo = 12345; CREATE MATERIALIZED VIEW mv_test3 AS SELECT * FROM mv_test2 WHERE moo = 12345;
SELECT relispopulated FROM pg_class WHERE oid = 'mv_test3'::regclass; SELECT relispopulated FROM pg_class WHERE oid = 'mv_test3'::regclass;
...@@ -377,73 +377,73 @@ SELECT relispopulated FROM pg_class WHERE oid = 'mv_test3'::regclass; ...@@ -377,73 +377,73 @@ SELECT relispopulated FROM pg_class WHERE oid = 'mv_test3'::regclass;
t t
(1 row) (1 row)
DROP VIEW v_test1 CASCADE; DROP VIEW mvtest_vt1 CASCADE;
NOTICE: drop cascades to 3 other objects NOTICE: drop cascades to 3 other objects
DETAIL: drop cascades to view v_test2 DETAIL: drop cascades to view mvtest_vt2
drop cascades to materialized view mv_test2 drop cascades to materialized view mv_test2
drop cascades to materialized view mv_test3 drop cascades to materialized view mv_test3
-- test that vacuum does not make empty matview look unpopulated -- test that vacuum does not make empty matview look unpopulated
CREATE TABLE hoge (i int); CREATE TABLE mvtest_huge (i int);
INSERT INTO hoge VALUES (generate_series(1,100000)); INSERT INTO mvtest_huge VALUES (generate_series(1,100000));
CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge WHERE i % 2 = 0; CREATE MATERIALIZED VIEW mvtest_hugeview AS SELECT * FROM mvtest_huge WHERE i % 2 = 0;
CREATE INDEX hogeviewidx ON hogeview (i); CREATE INDEX mvtest_hugeviewidx ON mvtest_hugeview (i);
DELETE FROM hoge; DELETE FROM mvtest_huge;
REFRESH MATERIALIZED VIEW hogeview; REFRESH MATERIALIZED VIEW mvtest_hugeview;
SELECT * FROM hogeview WHERE i < 10; SELECT * FROM mvtest_hugeview WHERE i < 10;
i i
--- ---
(0 rows) (0 rows)
VACUUM ANALYZE hogeview; VACUUM ANALYZE mvtest_hugeview;
SELECT * FROM hogeview WHERE i < 10; SELECT * FROM mvtest_hugeview WHERE i < 10;
i i
--- ---
(0 rows) (0 rows)
DROP TABLE hoge CASCADE; DROP TABLE mvtest_huge CASCADE;
NOTICE: drop cascades to materialized view hogeview NOTICE: drop cascades to materialized view mvtest_hugeview
-- test that duplicate values on unique index prevent refresh -- test that duplicate values on unique index prevent refresh
CREATE TABLE foo(a, b) AS VALUES(1, 10); CREATE TABLE mvtest_foo(a, b) AS VALUES(1, 10);
CREATE MATERIALIZED VIEW mv AS SELECT * FROM foo; CREATE MATERIALIZED VIEW mvtest_mv AS SELECT * FROM mvtest_foo;
CREATE UNIQUE INDEX ON mv(a); CREATE UNIQUE INDEX ON mvtest_mv(a);
INSERT INTO foo SELECT * FROM foo; INSERT INTO mvtest_foo SELECT * FROM mvtest_foo;
REFRESH MATERIALIZED VIEW mv; REFRESH MATERIALIZED VIEW mvtest_mv;
ERROR: could not create unique index "mv_a_idx" ERROR: could not create unique index "mvtest_mv_a_idx"
DETAIL: Key (a)=(1) is duplicated. DETAIL: Key (a)=(1) is duplicated.
REFRESH MATERIALIZED VIEW CONCURRENTLY mv; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv;
ERROR: new data for materialized view "mv" contains duplicate rows without any null columns ERROR: new data for materialized view "mvtest_mv" contains duplicate rows without any null columns
DETAIL: Row: (1,10) DETAIL: Row: (1,10)
DROP TABLE foo CASCADE; DROP TABLE mvtest_foo CASCADE;
NOTICE: drop cascades to materialized view mv NOTICE: drop cascades to materialized view mvtest_mv
-- make sure that all columns covered by unique indexes works -- make sure that all columns covered by unique indexes works
CREATE TABLE foo(a, b, c) AS VALUES(1, 2, 3); CREATE TABLE mvtest_foo(a, b, c) AS VALUES(1, 2, 3);
CREATE MATERIALIZED VIEW mv AS SELECT * FROM foo; CREATE MATERIALIZED VIEW mvtest_mv AS SELECT * FROM mvtest_foo;
CREATE UNIQUE INDEX ON mv (a); CREATE UNIQUE INDEX ON mvtest_mv (a);
CREATE UNIQUE INDEX ON mv (b); CREATE UNIQUE INDEX ON mvtest_mv (b);
CREATE UNIQUE INDEX on mv (c); CREATE UNIQUE INDEX on mvtest_mv (c);
INSERT INTO foo VALUES(2, 3, 4); INSERT INTO mvtest_foo VALUES(2, 3, 4);
INSERT INTO foo VALUES(3, 4, 5); INSERT INTO mvtest_foo VALUES(3, 4, 5);
REFRESH MATERIALIZED VIEW mv; REFRESH MATERIALIZED VIEW mvtest_mv;
REFRESH MATERIALIZED VIEW CONCURRENTLY mv; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv;
DROP TABLE foo CASCADE; DROP TABLE mvtest_foo CASCADE;
NOTICE: drop cascades to materialized view mv NOTICE: drop cascades to materialized view mvtest_mv
-- allow subquery to reference unpopulated matview if WITH NO DATA is specified -- allow subquery to reference unpopulated matview if WITH NO DATA is specified
CREATE MATERIALIZED VIEW mv1 AS SELECT 1 AS col1 WITH NO DATA; CREATE MATERIALIZED VIEW mvtest_mv1 AS SELECT 1 AS col1 WITH NO DATA;
CREATE MATERIALIZED VIEW mv2 AS SELECT * FROM mv1 CREATE MATERIALIZED VIEW mvtest_mv2 AS SELECT * FROM mvtest_mv1
WHERE col1 = (SELECT LEAST(col1) FROM mv1) WITH NO DATA; WHERE col1 = (SELECT LEAST(col1) FROM mvtest_mv1) WITH NO DATA;
DROP MATERIALIZED VIEW mv1 CASCADE; DROP MATERIALIZED VIEW mvtest_mv1 CASCADE;
NOTICE: drop cascades to materialized view mv2 NOTICE: drop cascades to materialized view mvtest_mv2
-- make sure that types with unusual equality tests work -- make sure that types with unusual equality tests work
CREATE TABLE boxes (id serial primary key, b box); CREATE TABLE mvtest_boxes (id serial primary key, b box);
INSERT INTO boxes (b) VALUES INSERT INTO mvtest_boxes (b) VALUES
('(32,32),(31,31)'), ('(32,32),(31,31)'),
('(2.0000004,2.0000004),(1,1)'), ('(2.0000004,2.0000004),(1,1)'),
('(1.9999996,1.9999996),(1,1)'); ('(1.9999996,1.9999996),(1,1)');
CREATE MATERIALIZED VIEW boxmv AS SELECT * FROM boxes; CREATE MATERIALIZED VIEW mvtest_boxmv AS SELECT * FROM mvtest_boxes;
CREATE UNIQUE INDEX boxmv_id ON boxmv (id); CREATE UNIQUE INDEX mvtest_boxmv_id ON mvtest_boxmv (id);
UPDATE boxes SET b = '(2,2),(1,1)' WHERE id = 2; UPDATE mvtest_boxes SET b = '(2,2),(1,1)' WHERE id = 2;
REFRESH MATERIALIZED VIEW CONCURRENTLY boxmv; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_boxmv;
SELECT * FROM boxmv ORDER BY id; SELECT * FROM mvtest_boxmv ORDER BY id;
id | b id | b
----+----------------------------- ----+-----------------------------
1 | (32,32),(31,31) 1 | (32,32),(31,31)
...@@ -451,36 +451,36 @@ SELECT * FROM boxmv ORDER BY id; ...@@ -451,36 +451,36 @@ SELECT * FROM boxmv ORDER BY id;
3 | (1.9999996,1.9999996),(1,1) 3 | (1.9999996,1.9999996),(1,1)
(3 rows) (3 rows)
DROP TABLE boxes CASCADE; DROP TABLE mvtest_boxes CASCADE;
NOTICE: drop cascades to materialized view boxmv NOTICE: drop cascades to materialized view mvtest_boxmv
-- make sure that column names are handled correctly -- make sure that column names are handled correctly
CREATE TABLE v (i int, j int); CREATE TABLE mvtest_v (i int, j int);
CREATE MATERIALIZED VIEW mv_v (ii) AS SELECT i, j AS jj FROM v; CREATE MATERIALIZED VIEW mvtest_mv_v (ii) AS SELECT i, j AS jj FROM mvtest_v;
ALTER TABLE v RENAME COLUMN i TO x; ALTER TABLE mvtest_v RENAME COLUMN i TO x;
INSERT INTO v values (1, 2); INSERT INTO mvtest_v values (1, 2);
CREATE UNIQUE INDEX mv_v_ii ON mv_v (ii); CREATE UNIQUE INDEX mvtest_mv_v_ii ON mvtest_mv_v (ii);
REFRESH MATERIALIZED VIEW mv_v; REFRESH MATERIALIZED VIEW mvtest_mv_v;
UPDATE v SET j = 3 WHERE x = 1; UPDATE mvtest_v SET j = 3 WHERE x = 1;
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_v; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv_v;
SELECT * FROM v; SELECT * FROM mvtest_v;
x | j x | j
---+--- ---+---
1 | 3 1 | 3
(1 row) (1 row)
SELECT * FROM mv_v; SELECT * FROM mvtest_mv_v;
ii | jj ii | jj
----+---- ----+----
1 | 3 1 | 3
(1 row) (1 row)
DROP TABLE v CASCADE; DROP TABLE mvtest_v CASCADE;
NOTICE: drop cascades to materialized view mv_v NOTICE: drop cascades to materialized view mvtest_mv_v
-- make sure that matview rows can be referenced as source rows (bug #9398) -- make sure that matview rows can be referenced as source rows (bug #9398)
CREATE TABLE v AS SELECT generate_series(1,10) AS a; CREATE TABLE mvtest_v AS SELECT generate_series(1,10) AS a;
CREATE MATERIALIZED VIEW mv_v AS SELECT a FROM v WHERE a <= 5; CREATE MATERIALIZED VIEW mvtest_mv_v AS SELECT a FROM mvtest_v WHERE a <= 5;
DELETE FROM v WHERE EXISTS ( SELECT * FROM mv_v WHERE mv_v.a = v.a ); DELETE FROM mvtest_v WHERE EXISTS ( SELECT * FROM mvtest_mv_v WHERE mvtest_mv_v.a = mvtest_v.a );
SELECT * FROM v; SELECT * FROM mvtest_v;
a a
---- ----
6 6
...@@ -490,7 +490,7 @@ SELECT * FROM v; ...@@ -490,7 +490,7 @@ SELECT * FROM v;
10 10
(5 rows) (5 rows)
SELECT * FROM mv_v; SELECT * FROM mvtest_mv_v;
a a
--- ---
1 1
...@@ -500,21 +500,21 @@ SELECT * FROM mv_v; ...@@ -500,21 +500,21 @@ SELECT * FROM mv_v;
5 5
(5 rows) (5 rows)
DROP TABLE v CASCADE; DROP TABLE mvtest_v CASCADE;
NOTICE: drop cascades to materialized view mv_v NOTICE: drop cascades to materialized view mvtest_mv_v
-- make sure running as superuser works when MV owned by another role (bug #11208) -- make sure running as superuser works when MV owned by another role (bug #11208)
CREATE ROLE user_dw; CREATE ROLE regress_user_mvtest;
SET ROLE user_dw; SET ROLE regress_user_mvtest;
CREATE TABLE foo_data AS SELECT i, md5(random()::text) CREATE TABLE mvtest_foo_data AS SELECT i, md5(random()::text)
FROM generate_series(1, 10) i; FROM generate_series(1, 10) i;
CREATE MATERIALIZED VIEW mv_foo AS SELECT * FROM foo_data; CREATE MATERIALIZED VIEW mvtest_mv_foo AS SELECT * FROM mvtest_foo_data;
CREATE MATERIALIZED VIEW mv_foo AS SELECT * FROM foo_data; CREATE MATERIALIZED VIEW mvtest_mv_foo AS SELECT * FROM mvtest_foo_data;
ERROR: relation "mv_foo" already exists ERROR: relation "mvtest_mv_foo" already exists
CREATE MATERIALIZED VIEW IF NOT EXISTS mv_foo AS SELECT * FROM foo_data; CREATE MATERIALIZED VIEW IF NOT EXISTS mvtest_mv_foo AS SELECT * FROM mvtest_foo_data;
NOTICE: relation "mv_foo" already exists, skipping NOTICE: relation "mvtest_mv_foo" already exists, skipping
CREATE UNIQUE INDEX ON mv_foo (i); CREATE UNIQUE INDEX ON mvtest_mv_foo (i);
RESET ROLE; RESET ROLE;
REFRESH MATERIALIZED VIEW mv_foo; REFRESH MATERIALIZED VIEW mvtest_mv_foo;
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_foo; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv_foo;
DROP OWNED BY user_dw CASCADE; DROP OWNED BY regress_user_mvtest CASCADE;
DROP ROLE user_dw; DROP ROLE regress_user_mvtest;
...@@ -1289,6 +1289,14 @@ iexit| SELECT ih.name, ...@@ -1289,6 +1289,14 @@ iexit| SELECT ih.name,
FROM ihighway ih, FROM ihighway ih,
ramp r ramp r
WHERE (ih.thepath ## r.thepath); WHERE (ih.thepath ## r.thepath);
mvtest_tv| SELECT mvtest_t.type,
sum(mvtest_t.amt) AS totamt
FROM mvtest_t
GROUP BY mvtest_t.type;
mvtest_tvv| SELECT sum(mvtest_tv.totamt) AS grandtot
FROM mvtest_tv;
mvtest_tvvmv| SELECT mvtest_tvvm.grandtot
FROM mvtest_tvvm;
pg_available_extension_versions| SELECT e.name, pg_available_extension_versions| SELECT e.name,
e.version, e.version,
(x.extname IS NOT NULL) AS installed, (x.extname IS NOT NULL) AS installed,
...@@ -2251,14 +2259,6 @@ toyemp| SELECT emp.name, ...@@ -2251,14 +2259,6 @@ toyemp| SELECT emp.name,
emp.location, emp.location,
(12 * emp.salary) AS annualsal (12 * emp.salary) AS annualsal
FROM emp; FROM emp;
tv| SELECT t.type,
sum(t.amt) AS totamt
FROM t
GROUP BY t.type;
tvv| SELECT sum(tv.totamt) AS grandtot
FROM tv;
tvvmv| SELECT tvvm.grandtot
FROM tvvm;
SELECT tablename, rulename, definition FROM pg_rules SELECT tablename, rulename, definition FROM pg_rules
ORDER BY tablename, rulename; ORDER BY tablename, rulename;
pg_settings|pg_settings_n|CREATE RULE pg_settings_n AS pg_settings|pg_settings_n|CREATE RULE pg_settings_n AS
......
...@@ -588,7 +588,6 @@ SELECT user_relns() AS user_relns ...@@ -588,7 +588,6 @@ SELECT user_relns() AS user_relns
arrtest arrtest
b b
b_star b_star
bb
box_tbl box_tbl
bprime bprime
brinopers brinopers
...@@ -648,6 +647,16 @@ SELECT user_relns() AS user_relns ...@@ -648,6 +647,16 @@ SELECT user_relns() AS user_relns
lseg_tbl lseg_tbl
main_table main_table
money_data money_data
mvtest_bb
mvtest_t
mvtest_tm
mvtest_tmm
mvtest_tv
mvtest_tvm
mvtest_tvmm
mvtest_tvv
mvtest_tvvm
mvtest_tvvmv
num_data num_data
num_exp_add num_exp_add
num_exp_div num_exp_div
...@@ -682,7 +691,6 @@ SELECT user_relns() AS user_relns ...@@ -682,7 +691,6 @@ SELECT user_relns() AS user_relns
stud_emp stud_emp
student student
subselect_tbl subselect_tbl
t
tenk1 tenk1
tenk2 tenk2
test_range_excl test_range_excl
...@@ -699,15 +707,7 @@ SELECT user_relns() AS user_relns ...@@ -699,15 +707,7 @@ SELECT user_relns() AS user_relns
timestamptz_tbl timestamptz_tbl
timetz_tbl timetz_tbl
tinterval_tbl tinterval_tbl
tm
tmm
toyemp toyemp
tv
tvm
tvmm
tvv
tvvm
tvvmv
varchar_tbl varchar_tbl
xacttest xacttest
(132 rows) (132 rows)
......
-- create a table to use as a basis for views and materialized views in various combinations -- create a table to use as a basis for views and materialized views in various combinations
CREATE TABLE t (id int NOT NULL PRIMARY KEY, type text NOT NULL, amt numeric NOT NULL); CREATE TABLE mvtest_t (id int NOT NULL PRIMARY KEY, type text NOT NULL, amt numeric NOT NULL);
INSERT INTO t VALUES INSERT INTO mvtest_t VALUES
(1, 'x', 2), (1, 'x', 2),
(2, 'x', 3), (2, 'x', 3),
(3, 'y', 5), (3, 'y', 5),
...@@ -8,204 +8,204 @@ INSERT INTO t VALUES ...@@ -8,204 +8,204 @@ INSERT INTO t VALUES
(5, 'z', 11); (5, 'z', 11);
-- we want a view based on the table, too, since views present additional challenges -- we want a view based on the table, too, since views present additional challenges
CREATE VIEW tv AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type; CREATE VIEW mvtest_tv AS SELECT type, sum(amt) AS totamt FROM mvtest_t GROUP BY type;
SELECT * FROM tv ORDER BY type; SELECT * FROM mvtest_tv ORDER BY type;
-- create a materialized view with no data, and confirm correct behavior -- create a materialized view with no data, and confirm correct behavior
EXPLAIN (costs off) EXPLAIN (costs off)
CREATE MATERIALIZED VIEW tm AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type WITH NO DATA; CREATE MATERIALIZED VIEW mvtest_tm AS SELECT type, sum(amt) AS totamt FROM mvtest_t GROUP BY type WITH NO DATA;
CREATE MATERIALIZED VIEW tm AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type WITH NO DATA; CREATE MATERIALIZED VIEW mvtest_tm AS SELECT type, sum(amt) AS totamt FROM mvtest_t GROUP BY type WITH NO DATA;
SELECT relispopulated FROM pg_class WHERE oid = 'tm'::regclass; SELECT relispopulated FROM pg_class WHERE oid = 'mvtest_tm'::regclass;
SELECT * FROM tm; SELECT * FROM mvtest_tm;
REFRESH MATERIALIZED VIEW tm; REFRESH MATERIALIZED VIEW mvtest_tm;
SELECT relispopulated FROM pg_class WHERE oid = 'tm'::regclass; SELECT relispopulated FROM pg_class WHERE oid = 'mvtest_tm'::regclass;
CREATE UNIQUE INDEX tm_type ON tm (type); CREATE UNIQUE INDEX mvtest_tm_type ON mvtest_tm (type);
SELECT * FROM tm; SELECT * FROM mvtest_tm;
-- create various views -- create various views
EXPLAIN (costs off) EXPLAIN (costs off)
CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv ORDER BY type; CREATE MATERIALIZED VIEW mvtest_tvm AS SELECT * FROM mvtest_tv ORDER BY type;
CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv ORDER BY type; CREATE MATERIALIZED VIEW mvtest_tvm AS SELECT * FROM mvtest_tv ORDER BY type;
SELECT * FROM tvm; SELECT * FROM mvtest_tvm;
CREATE MATERIALIZED VIEW tmm AS SELECT sum(totamt) AS grandtot FROM tm; CREATE MATERIALIZED VIEW mvtest_tmm AS SELECT sum(totamt) AS grandtot FROM mvtest_tm;
CREATE MATERIALIZED VIEW tvmm AS SELECT sum(totamt) AS grandtot FROM tvm; CREATE MATERIALIZED VIEW mvtest_tvmm AS SELECT sum(totamt) AS grandtot FROM mvtest_tvm;
CREATE UNIQUE INDEX tvmm_expr ON tvmm ((grandtot > 0)); CREATE UNIQUE INDEX mvtest_tvmm_expr ON mvtest_tvmm ((grandtot > 0));
CREATE UNIQUE INDEX tvmm_pred ON tvmm (grandtot) WHERE grandtot < 0; CREATE UNIQUE INDEX mvtest_tvmm_pred ON mvtest_tvmm (grandtot) WHERE grandtot < 0;
CREATE VIEW tvv AS SELECT sum(totamt) AS grandtot FROM tv; CREATE VIEW mvtest_tvv AS SELECT sum(totamt) AS grandtot FROM mvtest_tv;
EXPLAIN (costs off) EXPLAIN (costs off)
CREATE MATERIALIZED VIEW tvvm AS SELECT * FROM tvv; CREATE MATERIALIZED VIEW mvtest_tvvm AS SELECT * FROM mvtest_tvv;
CREATE MATERIALIZED VIEW tvvm AS SELECT * FROM tvv; CREATE MATERIALIZED VIEW mvtest_tvvm AS SELECT * FROM mvtest_tvv;
CREATE VIEW tvvmv AS SELECT * FROM tvvm; CREATE VIEW mvtest_tvvmv AS SELECT * FROM mvtest_tvvm;
CREATE MATERIALIZED VIEW bb AS SELECT * FROM tvvmv; CREATE MATERIALIZED VIEW mvtest_bb AS SELECT * FROM mvtest_tvvmv;
CREATE INDEX aa ON bb (grandtot); CREATE INDEX mvtest_aa ON mvtest_bb (grandtot);
-- check that plans seem reasonable -- check that plans seem reasonable
\d+ tvm \d+ mvtest_tvm
\d+ tvm \d+ mvtest_tvm
\d+ tvvm \d+ mvtest_tvvm
\d+ bb \d+ mvtest_bb
-- test schema behavior -- test schema behavior
CREATE SCHEMA mvschema; CREATE SCHEMA mvtest_mvschema;
ALTER MATERIALIZED VIEW tvm SET SCHEMA mvschema; ALTER MATERIALIZED VIEW mvtest_tvm SET SCHEMA mvtest_mvschema;
\d+ tvm \d+ mvtest_tvm
\d+ tvmm \d+ mvtest_tvmm
SET search_path = mvschema, public; SET search_path = mvtest_mvschema, public;
\d+ tvm \d+ mvtest_tvm
-- modify the underlying table data -- modify the underlying table data
INSERT INTO t VALUES (6, 'z', 13); INSERT INTO mvtest_t VALUES (6, 'z', 13);
-- confirm pre- and post-refresh contents of fairly simple materialized views -- confirm pre- and post-refresh contents of fairly simple materialized views
SELECT * FROM tm ORDER BY type; SELECT * FROM mvtest_tm ORDER BY type;
SELECT * FROM tvm ORDER BY type; SELECT * FROM mvtest_tvm ORDER BY type;
REFRESH MATERIALIZED VIEW CONCURRENTLY tm; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_tm;
REFRESH MATERIALIZED VIEW tvm; REFRESH MATERIALIZED VIEW mvtest_tvm;
SELECT * FROM tm ORDER BY type; SELECT * FROM mvtest_tm ORDER BY type;
SELECT * FROM tvm ORDER BY type; SELECT * FROM mvtest_tvm ORDER BY type;
RESET search_path; RESET search_path;
-- confirm pre- and post-refresh contents of nested materialized views -- confirm pre- and post-refresh contents of nested materialized views
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tmm; SELECT * FROM mvtest_tmm;
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tvmm; SELECT * FROM mvtest_tvmm;
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tvvm; SELECT * FROM mvtest_tvvm;
SELECT * FROM tmm; SELECT * FROM mvtest_tmm;
SELECT * FROM tvmm; SELECT * FROM mvtest_tvmm;
SELECT * FROM tvvm; SELECT * FROM mvtest_tvvm;
REFRESH MATERIALIZED VIEW tmm; REFRESH MATERIALIZED VIEW mvtest_tmm;
REFRESH MATERIALIZED VIEW CONCURRENTLY tvmm; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_tvmm;
REFRESH MATERIALIZED VIEW tvmm; REFRESH MATERIALIZED VIEW mvtest_tvmm;
REFRESH MATERIALIZED VIEW tvvm; REFRESH MATERIALIZED VIEW mvtest_tvvm;
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tmm; SELECT * FROM mvtest_tmm;
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tvmm; SELECT * FROM mvtest_tvmm;
EXPLAIN (costs off) EXPLAIN (costs off)
SELECT * FROM tvvm; SELECT * FROM mvtest_tvvm;
SELECT * FROM tmm; SELECT * FROM mvtest_tmm;
SELECT * FROM tvmm; SELECT * FROM mvtest_tvmm;
SELECT * FROM tvvm; SELECT * FROM mvtest_tvvm;
-- test diemv when the mv does not exist -- test diemv when the mv does not exist
DROP MATERIALIZED VIEW IF EXISTS no_such_mv; DROP MATERIALIZED VIEW IF EXISTS no_such_mv;
-- make sure invalid comination of options is prohibited -- make sure invalid comination of options is prohibited
REFRESH MATERIALIZED VIEW CONCURRENTLY tvmm WITH NO DATA; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_tvmm WITH NO DATA;
-- no tuple locks on materialized views -- no tuple locks on materialized views
SELECT * FROM tvvm FOR SHARE; SELECT * FROM mvtest_tvvm FOR SHARE;
-- test join of mv and view -- test join of mv and view
SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM tm m LEFT JOIN tv v USING (type) ORDER BY type; SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM mvtest_tm m LEFT JOIN mvtest_tv v USING (type) ORDER BY type;
-- make sure that dependencies are reported properly when they block the drop -- make sure that dependencies are reported properly when they block the drop
DROP TABLE t; DROP TABLE mvtest_t;
-- make sure dependencies are dropped and reported -- make sure dependencies are dropped and reported
-- and make sure that transactional behavior is correct on rollback -- and make sure that transactional behavior is correct on rollback
-- incidentally leaving some interesting materialized views for pg_dump testing -- incidentally leaving some interesting materialized views for pg_dump testing
BEGIN; BEGIN;
DROP TABLE t CASCADE; DROP TABLE mvtest_t CASCADE;
ROLLBACK; ROLLBACK;
-- some additional tests not using base tables -- some additional tests not using base tables
CREATE VIEW v_test1 AS SELECT 1 moo; CREATE VIEW mvtest_vt1 AS SELECT 1 moo;
CREATE VIEW v_test2 AS SELECT moo, 2*moo FROM v_test1 UNION ALL SELECT moo, 3*moo FROM v_test1; CREATE VIEW mvtest_vt2 AS SELECT moo, 2*moo FROM mvtest_vt1 UNION ALL SELECT moo, 3*moo FROM mvtest_vt1;
\d+ v_test2 \d+ mvtest_vt2
CREATE MATERIALIZED VIEW mv_test2 AS SELECT moo, 2*moo FROM v_test2 UNION ALL SELECT moo, 3*moo FROM v_test2; CREATE MATERIALIZED VIEW mv_test2 AS SELECT moo, 2*moo FROM mvtest_vt2 UNION ALL SELECT moo, 3*moo FROM mvtest_vt2;
\d+ mv_test2 \d+ mv_test2
CREATE MATERIALIZED VIEW mv_test3 AS SELECT * FROM mv_test2 WHERE moo = 12345; CREATE MATERIALIZED VIEW mv_test3 AS SELECT * FROM mv_test2 WHERE moo = 12345;
SELECT relispopulated FROM pg_class WHERE oid = 'mv_test3'::regclass; SELECT relispopulated FROM pg_class WHERE oid = 'mv_test3'::regclass;
DROP VIEW v_test1 CASCADE; DROP VIEW mvtest_vt1 CASCADE;
-- test that vacuum does not make empty matview look unpopulated -- test that vacuum does not make empty matview look unpopulated
CREATE TABLE hoge (i int); CREATE TABLE mvtest_huge (i int);
INSERT INTO hoge VALUES (generate_series(1,100000)); INSERT INTO mvtest_huge VALUES (generate_series(1,100000));
CREATE MATERIALIZED VIEW hogeview AS SELECT * FROM hoge WHERE i % 2 = 0; CREATE MATERIALIZED VIEW mvtest_hugeview AS SELECT * FROM mvtest_huge WHERE i % 2 = 0;
CREATE INDEX hogeviewidx ON hogeview (i); CREATE INDEX mvtest_hugeviewidx ON mvtest_hugeview (i);
DELETE FROM hoge; DELETE FROM mvtest_huge;
REFRESH MATERIALIZED VIEW hogeview; REFRESH MATERIALIZED VIEW mvtest_hugeview;
SELECT * FROM hogeview WHERE i < 10; SELECT * FROM mvtest_hugeview WHERE i < 10;
VACUUM ANALYZE hogeview; VACUUM ANALYZE mvtest_hugeview;
SELECT * FROM hogeview WHERE i < 10; SELECT * FROM mvtest_hugeview WHERE i < 10;
DROP TABLE hoge CASCADE; DROP TABLE mvtest_huge CASCADE;
-- test that duplicate values on unique index prevent refresh -- test that duplicate values on unique index prevent refresh
CREATE TABLE foo(a, b) AS VALUES(1, 10); CREATE TABLE mvtest_foo(a, b) AS VALUES(1, 10);
CREATE MATERIALIZED VIEW mv AS SELECT * FROM foo; CREATE MATERIALIZED VIEW mvtest_mv AS SELECT * FROM mvtest_foo;
CREATE UNIQUE INDEX ON mv(a); CREATE UNIQUE INDEX ON mvtest_mv(a);
INSERT INTO foo SELECT * FROM foo; INSERT INTO mvtest_foo SELECT * FROM mvtest_foo;
REFRESH MATERIALIZED VIEW mv; REFRESH MATERIALIZED VIEW mvtest_mv;
REFRESH MATERIALIZED VIEW CONCURRENTLY mv; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv;
DROP TABLE foo CASCADE; DROP TABLE mvtest_foo CASCADE;
-- make sure that all columns covered by unique indexes works -- make sure that all columns covered by unique indexes works
CREATE TABLE foo(a, b, c) AS VALUES(1, 2, 3); CREATE TABLE mvtest_foo(a, b, c) AS VALUES(1, 2, 3);
CREATE MATERIALIZED VIEW mv AS SELECT * FROM foo; CREATE MATERIALIZED VIEW mvtest_mv AS SELECT * FROM mvtest_foo;
CREATE UNIQUE INDEX ON mv (a); CREATE UNIQUE INDEX ON mvtest_mv (a);
CREATE UNIQUE INDEX ON mv (b); CREATE UNIQUE INDEX ON mvtest_mv (b);
CREATE UNIQUE INDEX on mv (c); CREATE UNIQUE INDEX on mvtest_mv (c);
INSERT INTO foo VALUES(2, 3, 4); INSERT INTO mvtest_foo VALUES(2, 3, 4);
INSERT INTO foo VALUES(3, 4, 5); INSERT INTO mvtest_foo VALUES(3, 4, 5);
REFRESH MATERIALIZED VIEW mv; REFRESH MATERIALIZED VIEW mvtest_mv;
REFRESH MATERIALIZED VIEW CONCURRENTLY mv; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv;
DROP TABLE foo CASCADE; DROP TABLE mvtest_foo CASCADE;
-- allow subquery to reference unpopulated matview if WITH NO DATA is specified -- allow subquery to reference unpopulated matview if WITH NO DATA is specified
CREATE MATERIALIZED VIEW mv1 AS SELECT 1 AS col1 WITH NO DATA; CREATE MATERIALIZED VIEW mvtest_mv1 AS SELECT 1 AS col1 WITH NO DATA;
CREATE MATERIALIZED VIEW mv2 AS SELECT * FROM mv1 CREATE MATERIALIZED VIEW mvtest_mv2 AS SELECT * FROM mvtest_mv1
WHERE col1 = (SELECT LEAST(col1) FROM mv1) WITH NO DATA; WHERE col1 = (SELECT LEAST(col1) FROM mvtest_mv1) WITH NO DATA;
DROP MATERIALIZED VIEW mv1 CASCADE; DROP MATERIALIZED VIEW mvtest_mv1 CASCADE;
-- make sure that types with unusual equality tests work -- make sure that types with unusual equality tests work
CREATE TABLE boxes (id serial primary key, b box); CREATE TABLE mvtest_boxes (id serial primary key, b box);
INSERT INTO boxes (b) VALUES INSERT INTO mvtest_boxes (b) VALUES
('(32,32),(31,31)'), ('(32,32),(31,31)'),
('(2.0000004,2.0000004),(1,1)'), ('(2.0000004,2.0000004),(1,1)'),
('(1.9999996,1.9999996),(1,1)'); ('(1.9999996,1.9999996),(1,1)');
CREATE MATERIALIZED VIEW boxmv AS SELECT * FROM boxes; CREATE MATERIALIZED VIEW mvtest_boxmv AS SELECT * FROM mvtest_boxes;
CREATE UNIQUE INDEX boxmv_id ON boxmv (id); CREATE UNIQUE INDEX mvtest_boxmv_id ON mvtest_boxmv (id);
UPDATE boxes SET b = '(2,2),(1,1)' WHERE id = 2; UPDATE mvtest_boxes SET b = '(2,2),(1,1)' WHERE id = 2;
REFRESH MATERIALIZED VIEW CONCURRENTLY boxmv; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_boxmv;
SELECT * FROM boxmv ORDER BY id; SELECT * FROM mvtest_boxmv ORDER BY id;
DROP TABLE boxes CASCADE; DROP TABLE mvtest_boxes CASCADE;
-- make sure that column names are handled correctly -- make sure that column names are handled correctly
CREATE TABLE v (i int, j int); CREATE TABLE mvtest_v (i int, j int);
CREATE MATERIALIZED VIEW mv_v (ii) AS SELECT i, j AS jj FROM v; CREATE MATERIALIZED VIEW mvtest_mv_v (ii) AS SELECT i, j AS jj FROM mvtest_v;
ALTER TABLE v RENAME COLUMN i TO x; ALTER TABLE mvtest_v RENAME COLUMN i TO x;
INSERT INTO v values (1, 2); INSERT INTO mvtest_v values (1, 2);
CREATE UNIQUE INDEX mv_v_ii ON mv_v (ii); CREATE UNIQUE INDEX mvtest_mv_v_ii ON mvtest_mv_v (ii);
REFRESH MATERIALIZED VIEW mv_v; REFRESH MATERIALIZED VIEW mvtest_mv_v;
UPDATE v SET j = 3 WHERE x = 1; UPDATE mvtest_v SET j = 3 WHERE x = 1;
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_v; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv_v;
SELECT * FROM v; SELECT * FROM mvtest_v;
SELECT * FROM mv_v; SELECT * FROM mvtest_mv_v;
DROP TABLE v CASCADE; DROP TABLE mvtest_v CASCADE;
-- make sure that matview rows can be referenced as source rows (bug #9398) -- make sure that matview rows can be referenced as source rows (bug #9398)
CREATE TABLE v AS SELECT generate_series(1,10) AS a; CREATE TABLE mvtest_v AS SELECT generate_series(1,10) AS a;
CREATE MATERIALIZED VIEW mv_v AS SELECT a FROM v WHERE a <= 5; CREATE MATERIALIZED VIEW mvtest_mv_v AS SELECT a FROM mvtest_v WHERE a <= 5;
DELETE FROM v WHERE EXISTS ( SELECT * FROM mv_v WHERE mv_v.a = v.a ); DELETE FROM mvtest_v WHERE EXISTS ( SELECT * FROM mvtest_mv_v WHERE mvtest_mv_v.a = mvtest_v.a );
SELECT * FROM v; SELECT * FROM mvtest_v;
SELECT * FROM mv_v; SELECT * FROM mvtest_mv_v;
DROP TABLE v CASCADE; DROP TABLE mvtest_v CASCADE;
-- make sure running as superuser works when MV owned by another role (bug #11208) -- make sure running as superuser works when MV owned by another role (bug #11208)
CREATE ROLE user_dw; CREATE ROLE regress_user_mvtest;
SET ROLE user_dw; SET ROLE regress_user_mvtest;
CREATE TABLE foo_data AS SELECT i, md5(random()::text) CREATE TABLE mvtest_foo_data AS SELECT i, md5(random()::text)
FROM generate_series(1, 10) i; FROM generate_series(1, 10) i;
CREATE MATERIALIZED VIEW mv_foo AS SELECT * FROM foo_data; CREATE MATERIALIZED VIEW mvtest_mv_foo AS SELECT * FROM mvtest_foo_data;
CREATE MATERIALIZED VIEW mv_foo AS SELECT * FROM foo_data; CREATE MATERIALIZED VIEW mvtest_mv_foo AS SELECT * FROM mvtest_foo_data;
CREATE MATERIALIZED VIEW IF NOT EXISTS mv_foo AS SELECT * FROM foo_data; CREATE MATERIALIZED VIEW IF NOT EXISTS mvtest_mv_foo AS SELECT * FROM mvtest_foo_data;
CREATE UNIQUE INDEX ON mv_foo (i); CREATE UNIQUE INDEX ON mvtest_mv_foo (i);
RESET ROLE; RESET ROLE;
REFRESH MATERIALIZED VIEW mv_foo; REFRESH MATERIALIZED VIEW mvtest_mv_foo;
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_foo; REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv_foo;
DROP OWNED BY user_dw CASCADE; DROP OWNED BY regress_user_mvtest CASCADE;
DROP ROLE user_dw; DROP ROLE regress_user_mvtest;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment