diff options
| author | Shigeru Hanada | 2011-07-04 00:50:47 +0000 |
|---|---|---|
| committer | Shigeru Hanada | 2011-07-04 00:50:47 +0000 |
| commit | 99c74ddec4ba4dfcdf477c947a16924595e6d977 (patch) | |
| tree | bb798e53d24fdc794fb0e625ad456b4f16032f57 /src/backend | |
| parent | c01a5997ba93d319a9aed4f164305efcd9e5d0b6 (diff) | |
| parent | 99e47ed0b2d2c559da813e679260e218f2c1d2ee (diff) | |
Merge branch 'master' into check_alwayscheck_always
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/catalog/namespace.c | 57 | ||||
| -rw-r--r-- | src/backend/commands/tablecmds.c | 13 | ||||
| -rw-r--r-- | src/backend/commands/typecmds.c | 6 | ||||
| -rw-r--r-- | src/backend/commands/view.c | 27 | ||||
| -rw-r--r-- | src/backend/executor/execMain.c | 13 | ||||
| -rw-r--r-- | src/backend/parser/parse_utilcmd.c | 4 | ||||
| -rw-r--r-- | src/backend/utils/adt/pgstatfuncs.c | 14 |
7 files changed, 82 insertions, 52 deletions
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index 41e92992de..ce795a61c5 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -311,19 +311,6 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation) newRelation->relname))); } - if (newRelation->relpersistence == RELPERSISTENCE_TEMP) - { - /* TEMP tables are created in our backend-local temp namespace */ - if (newRelation->schemaname) - ereport(ERROR, - (errcode(ERRCODE_INVALID_TABLE_DEFINITION), - errmsg("temporary tables cannot specify a schema name"))); - /* Initialize temp namespace if first time through */ - if (!OidIsValid(myTempNamespace)) - InitTempTableNamespace(); - return myTempNamespace; - } - if (newRelation->schemaname) { /* check for pg_temp alias */ @@ -338,6 +325,13 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation) namespaceId = get_namespace_oid(newRelation->schemaname, false); /* we do not check for USAGE rights here! */ } + else if (newRelation->relpersistence == RELPERSISTENCE_TEMP) + { + /* Initialize temp namespace if first time through */ + if (!OidIsValid(myTempNamespace)) + InitTempTableNamespace(); + return myTempNamespace; + } else { /* use the default creation namespace */ @@ -390,6 +384,43 @@ RangeVarGetAndCheckCreationNamespace(const RangeVar *newRelation) } /* + * Adjust the relpersistence for an about-to-be-created relation based on the + * creation namespace, and throw an error for invalid combinations. + */ +void +RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid) +{ + switch (newRelation->relpersistence) + { + case RELPERSISTENCE_TEMP: + if (!isTempOrToastNamespace(nspid)) + { + if (isAnyTempNamespace(nspid)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_TABLE_DEFINITION), + errmsg("cannot create relations in temporary schemas of other sessions"))); + else + ereport(ERROR, + (errcode(ERRCODE_INVALID_TABLE_DEFINITION), + errmsg("cannot create temporary relation in non-temporary schema"))); + } + break; + case RELPERSISTENCE_PERMANENT: + if (isTempOrToastNamespace(nspid)) + newRelation->relpersistence = RELPERSISTENCE_TEMP; + else if (isAnyTempNamespace(nspid)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_TABLE_DEFINITION), + errmsg("cannot create relations in temporary schemas of other sessions"))); + break; + default: + ereport(ERROR, + (errcode(ERRCODE_INVALID_TABLE_DEFINITION), + errmsg("only temporary relations may be created in temporary schemas"))); + } +} + +/* * RelnameGetRelid * Try to resolve an unqualified relation name. * Returns OID if relation found in search path, else InvalidOid. diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index cfc685b949..a3a99d2880 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -432,6 +432,13 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId) errmsg("constraints on foreign tables are not supported"))); /* + * Look up the namespace in which we are supposed to create the relation, + * and check we have permission to create there. + */ + namespaceId = RangeVarGetAndCheckCreationNamespace(stmt->relation); + RangeVarAdjustRelationPersistence(stmt->relation, namespaceId); + + /* * Security check: disallow creating temp tables from security-restricted * code. This is needed because calling code might not expect untrusted * tables to appear in pg_temp at the front of its search path. @@ -443,12 +450,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId) errmsg("cannot create temporary table within security-restricted operation"))); /* - * Look up the namespace in which we are supposed to create the relation, - * and check we have permission to create there. - */ - namespaceId = RangeVarGetAndCheckCreationNamespace(stmt->relation); - - /* * Select tablespace to use. If not specified, use default tablespace * (which may in turn default to database's default). */ diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 437d23a810..85a7585c6c 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -1610,6 +1610,7 @@ DefineCompositeType(const RangeVar *typevar, List *coldeflist) * instead of below about a "relation". */ typeNamespace = RangeVarGetCreationNamespace(createStmt->relation); + RangeVarAdjustRelationPersistence(createStmt->relation, typeNamespace); old_type_oid = GetSysCacheOid2(TYPENAMENSP, CStringGetDatum(createStmt->relation->relname), @@ -2046,7 +2047,7 @@ AlterDomainValidateConstraint(List *names, char *constrName) Relation conrel; HeapTuple tup; Form_pg_type typTup; - Form_pg_constraint con; + Form_pg_constraint con = NULL; Form_pg_constraint copy_con; char *conbin; SysScanDesc scan; @@ -2094,13 +2095,10 @@ AlterDomainValidateConstraint(List *names, char *constrName) } if (!found) - { - con = NULL; /* keep compiler quiet */ ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("constraint \"%s\" of domain \"%s\" does not exist", constrName, NameStr(con->conname)))); - } if (con->contype != CONSTRAINT_CHECK) ereport(ERROR, diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c index be681e3fd4..b238199658 100644 --- a/src/backend/commands/view.c +++ b/src/backend/commands/view.c @@ -97,10 +97,10 @@ isViewOnTempTable_walker(Node *node, void *context) *--------------------------------------------------------------------- */ static Oid -DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace) +DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace, + Oid namespaceId) { - Oid viewOid, - namespaceId; + Oid viewOid; CreateStmt *createStmt = makeNode(CreateStmt); List *attrList; ListCell *t; @@ -160,7 +160,6 @@ DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace) /* * Check to see if we want to replace an existing view. */ - namespaceId = RangeVarGetCreationNamespace(relation); viewOid = get_relname_relid(relation->relname, namespaceId); if (OidIsValid(viewOid) && replace) @@ -417,6 +416,7 @@ DefineView(ViewStmt *stmt, const char *queryString) { Query *viewParse; Oid viewOid; + Oid namespaceId; RangeVar *view; /* @@ -480,28 +480,31 @@ DefineView(ViewStmt *stmt, const char *queryString) "names than columns"))); } + /* Unlogged views are not sensible. */ + if (stmt->view->relpersistence == RELPERSISTENCE_UNLOGGED) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("views cannot be unlogged because they do not have storage"))); + /* * If the user didn't explicitly ask for a temporary view, check whether * we need one implicitly. We allow TEMP to be inserted automatically as * long as the CREATE command is consistent with that --- no explicit * schema name. */ - view = stmt->view; + view = copyObject(stmt->view); /* don't corrupt original command */ if (view->relpersistence == RELPERSISTENCE_PERMANENT && isViewOnTempTable(viewParse)) { - view = copyObject(view); /* don't corrupt original command */ view->relpersistence = RELPERSISTENCE_TEMP; ereport(NOTICE, (errmsg("view \"%s\" will be a temporary view", view->relname))); } - /* Unlogged views are not sensible. */ - if (view->relpersistence == RELPERSISTENCE_UNLOGGED) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("views cannot be unlogged because they do not have storage"))); + /* Might also need to make it temporary if placed in temp schema. */ + namespaceId = RangeVarGetCreationNamespace(view); + RangeVarAdjustRelationPersistence(view, namespaceId); /* * Create the view relation @@ -510,7 +513,7 @@ DefineView(ViewStmt *stmt, const char *queryString) * aborted. */ viewOid = DefineVirtualRelation(view, viewParse->targetList, - stmt->replace); + stmt->replace, namespaceId); /* * The relation we have just created is not visible to any other commands diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 2f8deb470c..eacd863647 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -2414,6 +2414,13 @@ OpenIntoRel(QueryDesc *queryDesc) errmsg("ON COMMIT can only be used on temporary tables"))); /* + * Find namespace to create in, check its permissions + */ + intoName = into->rel->relname; + namespaceId = RangeVarGetAndCheckCreationNamespace(into->rel); + RangeVarAdjustRelationPersistence(into->rel, namespaceId); + + /* * Security check: disallow creating temp tables from security-restricted * code. This is needed because calling code might not expect untrusted * tables to appear in pg_temp at the front of its search path. @@ -2425,12 +2432,6 @@ OpenIntoRel(QueryDesc *queryDesc) errmsg("cannot create temporary table within security-restricted operation"))); /* - * Find namespace to create in, check its permissions - */ - intoName = into->rel->relname; - namespaceId = RangeVarGetAndCheckCreationNamespace(into->rel); - - /* * Select tablespace to use. If not specified, use default tablespace * (which may in turn default to database's default). */ diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index d40a963b74..1771fee647 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -162,6 +162,7 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString) * possible. */ namespaceid = RangeVarGetAndCheckCreationNamespace(stmt->relation); + RangeVarAdjustRelationPersistence(stmt->relation, namespaceid); /* * If the relation already exists and the user specified "IF NOT EXISTS", @@ -374,7 +375,10 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column) if (cxt->rel) snamespaceid = RelationGetNamespace(cxt->rel); else + { snamespaceid = RangeVarGetCreationNamespace(cxt->relation); + RangeVarAdjustRelationPersistence(cxt->relation, snamespaceid); + } snamespace = get_namespace_name(snamespaceid); sname = ChooseRelationName(cxt->relation->relname, column->colname, diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 4d07bdd24b..12dbff4c9a 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -1537,17 +1537,9 @@ pg_stat_reset(PG_FUNCTION_ARGS) Datum pg_stat_reset_shared(PG_FUNCTION_ARGS) { - if (PG_ARGISNULL(0)) - /* - * Same error message as in pgstat_reset_shared_counters(), - * to keep translations the same. - */ - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("unrecognized reset target: \"%s\"", "null"), - errhint("Target must be \"bgwriter\"."))); - - pgstat_reset_shared_counters(text_to_cstring(PG_GETARG_TEXT_PP(0))); + char *target = text_to_cstring(PG_GETARG_TEXT_PP(0)); + + pgstat_reset_shared_counters(target); PG_RETURN_VOID(); } |
