@@ -8,12 +8,12 @@ INSERT INTO t VALUES
88 (5, 'z', 11);
99-- we want a view based on the table, too, since views present additional challenges
1010CREATE VIEW tv AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type;
11- SELECT * FROM tv;
11+ SELECT * FROM tv ORDER BY type ;
1212 type | totamt
1313------+--------
14+ x | 5
1415 y | 12
1516 z | 11
16- x | 5
1717(3 rows)
1818
1919-- create a materialized view with no data, and confirm correct behavior
@@ -53,20 +53,22 @@ SELECT * FROM tm;
5353
5454-- create various views
5555EXPLAIN (costs off)
56- CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv;
57- QUERY PLAN
58- ---------------------
59- HashAggregate
60- -> Seq Scan on t
61- (2 rows)
56+ CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv ORDER BY type;
57+ QUERY PLAN
58+ ---------------------------
59+ Sort
60+ Sort Key: t.type
61+ -> HashAggregate
62+ -> Seq Scan on t
63+ (4 rows)
6264
63- CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv;
65+ CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv ORDER BY type ;
6466SELECT * FROM tvm;
6567 type | totamt
6668------+--------
69+ x | 5
6770 y | 12
6871 z | 11
69- x | 5
7072(3 rows)
7173
7274CREATE MATERIALIZED VIEW tmm AS SELECT sum(totamt) AS grandtot FROM tm;
@@ -95,7 +97,8 @@ CREATE INDEX aa ON bb (grandtot);
9597View definition:
9698 SELECT tv.type,
9799 tv.totamt
98- FROM tv;
100+ FROM tv
101+ ORDER BY tv.type;
99102
100103\d+ tvm
101104 Materialized view "public.tvm"
@@ -106,7 +109,8 @@ View definition:
106109View definition:
107110 SELECT tv.type,
108111 tv.totamt
109- FROM tv;
112+ FROM tv
113+ ORDER BY tv.type;
110114
111115\d+ tvvm
112116 Materialized view "public.tvvm"
@@ -151,7 +155,8 @@ SET search_path = mvschema, public;
151155View definition:
152156 SELECT tv.type,
153157 tv.totamt
154- FROM tv;
158+ FROM tv
159+ ORDER BY tv.type;
155160
156161-- modify the underlying table data
157162INSERT INTO t VALUES (6, 'z', 13);
@@ -328,12 +333,12 @@ SELECT * FROM tum;
328333(3 rows)
329334
330335-- test join of mv and view
331- SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM tm m LEFT JOIN tv v USING (type);
336+ SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM tm m LEFT JOIN tv v USING (type) ORDER BY type ;
332337 type | mtot | vtot
333338------+------+------
339+ x | 5 | 5
334340 y | 12 | 12
335341 z | 24 | 24
336- x | 5 | 5
337342(3 rows)
338343
339344-- test diemv when the mv does exist
0 commit comments