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

Commit 549dae0

Browse files
committed
Fix problems with incomplete attempt to prohibit OIDS with MVs.
Problem with assertion failure in restoring from pg_dump output reported by Joachim Wieland. Review and suggestions by Tom Lane and Robert Haas.
1 parent 4912385 commit 549dae0

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

doc/src/sgml/ref/create_materialized_view.sgml

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ CREATE [ UNLOGGED ] MATERIALIZED VIEW <replaceable>table_name</replaceable>
4444
<command>CREATE MATERIALIZED VIEW</command> is similar to
4545
<command>CREATE TABLE AS</>, except that it also remembers the query used
4646
to initialize the view, so that it can be refreshed later upon demand.
47+
A materialized view has many of the same properties as a table, but there
48+
is no support for temporary materialized views or automatic generation of
49+
OIDs.
4750
</para>
4851
</refsect1>
4952

@@ -88,7 +91,9 @@ CREATE [ UNLOGGED ] MATERIALIZED VIEW <replaceable>table_name</replaceable>
8891
This clause specifies optional storage parameters for the new
8992
materialized view; see <xref linkend="sql-createtable-storage-parameters"
9093
endterm="sql-createtable-storage-parameters-title"> for more
91-
information.
94+
information. All parameters supported for <literal>CREATE
95+
TABLE</literal> are also supported for <literal>CREATE MATERIALIZED
96+
VIEW</literal> with the exception of <literal>OIDS</literal>.
9297
See <xref linkend="sql-createtable"> for more information.
9398
</para>
9499
</listitem>

src/backend/commands/createas.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,15 @@ GetIntoRelEFlags(IntoClause *intoClause)
218218
* because it doesn't have enough information to do so itself (since we
219219
* can't build the target relation until after ExecutorStart).
220220
*/
221-
if (interpretOidsOption(intoClause->options))
221+
if (interpretOidsOption(intoClause->options, intoClause->relkind))
222222
flags = EXEC_FLAG_WITH_OIDS;
223223
else
224224
flags = EXEC_FLAG_WITHOUT_OIDS;
225225

226+
Assert(intoClause->relkind != RELKIND_MATVIEW ||
227+
(flags & (EXEC_FLAG_WITH_OIDS | EXEC_FLAG_WITHOUT_OIDS)) ==
228+
EXEC_FLAG_WITHOUT_OIDS);
229+
226230
if (intoClause->skipData)
227231
flags |= EXEC_FLAG_WITH_NO_DATA;
228232

src/backend/commands/tablecmds.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
559559
*/
560560
descriptor = BuildDescForRelation(schema);
561561

562-
localHasOids = interpretOidsOption(stmt->options);
562+
localHasOids = interpretOidsOption(stmt->options, relkind);
563563
descriptor->tdhasoid = (localHasOids || parentOidCount > 0);
564564

565565
/*

src/backend/parser/parse_clause.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,14 @@ interpretInhOption(InhOption inhOpt)
243243
* table/result set should be created with OIDs. This needs to be done after
244244
* parsing the query string because the return value can depend upon the
245245
* default_with_oids GUC var.
246+
*
247+
* Materialized views are handled here rather than reloptions.c because that
248+
* code explicitly punts checking for oids to here. We prohibit any explicit
249+
* specification of the oids option for a materialized view, and indicate that
250+
* oids are not needed if we don't get an error.
246251
*/
247252
bool
248-
interpretOidsOption(List *defList)
253+
interpretOidsOption(List *defList, char relkind)
249254
{
250255
ListCell *cell;
251256

@@ -256,9 +261,19 @@ interpretOidsOption(List *defList)
256261

257262
if (def->defnamespace == NULL &&
258263
pg_strcasecmp(def->defname, "oids") == 0)
264+
{
265+
if (relkind == RELKIND_MATVIEW)
266+
ereport(ERROR,
267+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
268+
errmsg("unrecognized parameter \"%s\"", "oids")));
269+
259270
return defGetBoolean(def);
271+
}
260272
}
261273

274+
if (relkind == RELKIND_MATVIEW)
275+
return false;
276+
262277
/* OIDS option was not specified, so use default. */
263278
return default_with_oids;
264279
}

src/backend/parser/parse_utilcmd.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,14 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
199199
{
200200
cxt.stmtType = "CREATE FOREIGN TABLE";
201201
cxt.isforeign = true;
202+
cxt.hasoids = interpretOidsOption(stmt->options,
203+
RELKIND_FOREIGN_TABLE);
202204
}
203205
else
204206
{
205207
cxt.stmtType = "CREATE TABLE";
206208
cxt.isforeign = false;
209+
cxt.hasoids = interpretOidsOption(stmt->options, RELKIND_RELATION);
207210
}
208211
cxt.relation = stmt->relation;
209212
cxt.rel = NULL;
@@ -217,7 +220,6 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
217220
cxt.blist = NIL;
218221
cxt.alist = NIL;
219222
cxt.pkey = NULL;
220-
cxt.hasoids = interpretOidsOption(stmt->options);
221223

222224
Assert(!stmt->ofTypename || !stmt->inhRelations); /* grammar enforces */
223225

src/include/parser/parse_clause.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern void transformFromClause(ParseState *pstate, List *frmList);
2020
extern int setTargetTable(ParseState *pstate, RangeVar *relation,
2121
bool inh, bool alsoSource, AclMode requiredPerms);
2222
extern bool interpretInhOption(InhOption inhOpt);
23-
extern bool interpretOidsOption(List *defList);
23+
extern bool interpretOidsOption(List *defList, char relkind);
2424

2525
extern Node *transformWhereClause(ParseState *pstate, Node *clause,
2626
ParseExprKind exprKind, const char *constructName);

0 commit comments

Comments
 (0)