Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3223b25

Browse files
committed
Disallow unlogged materialized views.
The initial implementation of this feature was really unsupportable, because it's relying on the physical size of an on-disk file to carry the relation's populated/unpopulated state, which is at least a modularity violation and could have serious long-term consequences. We could say that an unlogged matview goes to empty on crash, but not everybody likes that definition, so let's just remove the feature for 9.3. We can add it back when we have a less klugy implementation. I left the grammar and tab-completion support for CREATE UNLOGGED MATERIALIZED VIEW in place, since it's harmless and allows delivering a more specific error message about the unsupported feature. I'm committing this separately to ease identification of what should be reverted when/if we are able to re-enable the feature.
1 parent c298660 commit 3223b25

File tree

4 files changed

+16
-84
lines changed

4 files changed

+16
-84
lines changed

doc/src/sgml/ref/create_materialized_view.sgml

+1-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PostgreSQL documentation
2121

2222
<refsynopsisdiv>
2323
<synopsis>
24-
CREATE [ UNLOGGED ] MATERIALIZED VIEW <replaceable>table_name</replaceable>
24+
CREATE MATERIALIZED VIEW <replaceable>table_name</replaceable>
2525
[ (<replaceable>column_name</replaceable> [, ...] ) ]
2626
[ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) ]
2727
[ TABLESPACE <replaceable class="PARAMETER">tablespace_name</replaceable> ]
@@ -54,16 +54,6 @@ CREATE [ UNLOGGED ] MATERIALIZED VIEW <replaceable>table_name</replaceable>
5454
<title>Parameters</title>
5555

5656
<variablelist>
57-
<varlistentry>
58-
<term><literal>UNLOGGED</></term>
59-
<listitem>
60-
<para>
61-
If specified, the materialized view will be unlogged.
62-
Refer to <xref linkend="sql-createtable"> for details.
63-
</para>
64-
</listitem>
65-
</varlistentry>
66-
6757
<varlistentry>
6858
<term><replaceable>table_name</replaceable></term>
6959
<listitem>

src/backend/parser/analyze.c

+12
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,18 @@ transformCreateTableAsStmt(ParseState *pstate, CreateTableAsStmt *stmt)
21662166
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
21672167
errmsg("materialized views may not be defined using bound parameters")));
21682168

2169+
/*
2170+
* For now, we disallow unlogged materialized views, because it
2171+
* seems like a bad idea for them to just go to empty after a crash.
2172+
* (If we could mark them as unpopulated, that would be better, but
2173+
* that requires catalog changes which crash recovery can't presently
2174+
* handle.)
2175+
*/
2176+
if (stmt->into->rel->relpersistence == RELPERSISTENCE_UNLOGGED)
2177+
ereport(ERROR,
2178+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2179+
errmsg("materialized views cannot be UNLOGGED")));
2180+
21692181
/*
21702182
* At runtime, we'll need a copy of the parsed-but-not-rewritten Query
21712183
* for purposes of creating the view's ON SELECT rule. We stash that

src/test/regress/expected/matview.out

+2-55
Original file line numberDiff line numberDiff line change
@@ -279,59 +279,8 @@ SELECT * FROM tvvm;
279279
(1 row)
280280

281281
-- test diemv when the mv does not exist
282-
DROP MATERIALIZED VIEW IF EXISTS tum;
283-
NOTICE: materialized view "tum" does not exist, skipping
284-
-- make sure that an unlogged materialized view works (in the absence of a crash)
285-
CREATE UNLOGGED MATERIALIZED VIEW tum AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type WITH NO DATA;
286-
SELECT pg_relation_is_scannable('tum'::regclass);
287-
pg_relation_is_scannable
288-
--------------------------
289-
f
290-
(1 row)
291-
292-
SELECT * FROM tum;
293-
ERROR: materialized view "tum" has not been populated
294-
HINT: Use the REFRESH MATERIALIZED VIEW command.
295-
REFRESH MATERIALIZED VIEW tum;
296-
SELECT pg_relation_is_scannable('tum'::regclass);
297-
pg_relation_is_scannable
298-
--------------------------
299-
t
300-
(1 row)
301-
302-
SELECT * FROM tum;
303-
type | totamt
304-
------+--------
305-
y | 12
306-
z | 24
307-
x | 5
308-
(3 rows)
309-
310-
REFRESH MATERIALIZED VIEW tum WITH NO DATA;
311-
SELECT pg_relation_is_scannable('tum'::regclass);
312-
pg_relation_is_scannable
313-
--------------------------
314-
f
315-
(1 row)
316-
317-
SELECT * FROM tum;
318-
ERROR: materialized view "tum" has not been populated
319-
HINT: Use the REFRESH MATERIALIZED VIEW command.
320-
REFRESH MATERIALIZED VIEW tum WITH DATA;
321-
SELECT pg_relation_is_scannable('tum'::regclass);
322-
pg_relation_is_scannable
323-
--------------------------
324-
t
325-
(1 row)
326-
327-
SELECT * FROM tum;
328-
type | totamt
329-
------+--------
330-
y | 12
331-
z | 24
332-
x | 5
333-
(3 rows)
334-
282+
DROP MATERIALIZED VIEW IF EXISTS no_such_mv;
283+
NOTICE: materialized view "no_such_mv" does not exist, skipping
335284
-- test join of mv and view
336285
SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM tm m LEFT JOIN tv v USING (type) ORDER BY type;
337286
type | mtot | vtot
@@ -341,8 +290,6 @@ SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM tm m LEFT JOIN tv v USING (
341290
z | 24 | 24
342291
(3 rows)
343292

344-
-- test diemv when the mv does exist
345-
DROP MATERIALIZED VIEW IF EXISTS tum;
346293
-- make sure that dependencies are reported properly when they block the drop
347294
DROP TABLE t;
348295
ERROR: cannot drop table t because other objects depend on it

src/test/regress/sql/matview.sql

+1-18
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,11 @@ SELECT * FROM tvmm;
8787
SELECT * FROM tvvm;
8888

8989
-- test diemv when the mv does not exist
90-
DROP MATERIALIZED VIEW IF EXISTS tum;
91-
92-
-- make sure that an unlogged materialized view works (in the absence of a crash)
93-
CREATE UNLOGGED MATERIALIZED VIEW tum AS SELECT type, sum(amt) AS totamt FROM t GROUP BY type WITH NO DATA;
94-
SELECT pg_relation_is_scannable('tum'::regclass);
95-
SELECT * FROM tum;
96-
REFRESH MATERIALIZED VIEW tum;
97-
SELECT pg_relation_is_scannable('tum'::regclass);
98-
SELECT * FROM tum;
99-
REFRESH MATERIALIZED VIEW tum WITH NO DATA;
100-
SELECT pg_relation_is_scannable('tum'::regclass);
101-
SELECT * FROM tum;
102-
REFRESH MATERIALIZED VIEW tum WITH DATA;
103-
SELECT pg_relation_is_scannable('tum'::regclass);
104-
SELECT * FROM tum;
90+
DROP MATERIALIZED VIEW IF EXISTS no_such_mv;
10591

10692
-- test join of mv and view
10793
SELECT type, m.totamt AS mtot, v.totamt AS vtot FROM tm m LEFT JOIN tv v USING (type) ORDER BY type;
10894

109-
-- test diemv when the mv does exist
110-
DROP MATERIALIZED VIEW IF EXISTS tum;
111-
11295
-- make sure that dependencies are reported properly when they block the drop
11396
DROP TABLE t;
11497

0 commit comments

Comments
 (0)