@@ -8,12 +8,12 @@ INSERT INTO t VALUES
8
8
(5, 'z', 11);
9
9
-- we want a view based on the table, too, since views present additional challenges
10
10
CREATE 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 ;
12
12
type | totamt
13
13
------+--------
14
+ x | 5
14
15
y | 12
15
16
z | 11
16
- x | 5
17
17
(3 rows)
18
18
19
19
-- create a materialized view with no data, and confirm correct behavior
@@ -53,20 +53,22 @@ SELECT * FROM tm;
53
53
54
54
-- create various views
55
55
EXPLAIN (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)
62
64
63
- CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv;
65
+ CREATE MATERIALIZED VIEW tvm AS SELECT * FROM tv ORDER BY type ;
64
66
SELECT * FROM tvm;
65
67
type | totamt
66
68
------+--------
69
+ x | 5
67
70
y | 12
68
71
z | 11
69
- x | 5
70
72
(3 rows)
71
73
72
74
CREATE MATERIALIZED VIEW tmm AS SELECT sum(totamt) AS grandtot FROM tm;
@@ -95,7 +97,8 @@ CREATE INDEX aa ON bb (grandtot);
95
97
View definition:
96
98
SELECT tv.type,
97
99
tv.totamt
98
- FROM tv;
100
+ FROM tv
101
+ ORDER BY tv.type;
99
102
100
103
\d+ tvm
101
104
Materialized view "public.tvm"
@@ -106,7 +109,8 @@ View definition:
106
109
View definition:
107
110
SELECT tv.type,
108
111
tv.totamt
109
- FROM tv;
112
+ FROM tv
113
+ ORDER BY tv.type;
110
114
111
115
\d+ tvvm
112
116
Materialized view "public.tvvm"
@@ -151,7 +155,8 @@ SET search_path = mvschema, public;
151
155
View definition:
152
156
SELECT tv.type,
153
157
tv.totamt
154
- FROM tv;
158
+ FROM tv
159
+ ORDER BY tv.type;
155
160
156
161
-- modify the underlying table data
157
162
INSERT INTO t VALUES (6, 'z', 13);
@@ -328,12 +333,12 @@ SELECT * FROM tum;
328
333
(3 rows)
329
334
330
335
-- 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 ;
332
337
type | mtot | vtot
333
338
------+------+------
339
+ x | 5 | 5
334
340
y | 12 | 12
335
341
z | 24 | 24
336
- x | 5 | 5
337
342
(3 rows)
338
343
339
344
-- test diemv when the mv does exist
0 commit comments