From: Tom Lane Date: Thu, 7 Feb 2008 17:09:51 +0000 (+0000) Subject: Fix CREATE TABLE ... LIKE ... INCLUDING INDEXES to not cause unwanted X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=09448eba44b477d3d6cf62e191af8164a9367603;p=users%2Fbernd%2Fpostgres.git Fix CREATE TABLE ... LIKE ... INCLUDING INDEXES to not cause unwanted tablespace permissions failures when copying an index that is in the database's default tablespace. A side-effect of the change is that explicitly specifying the default tablespace no longer triggers a permissions check; this is not how it was done in pre-8.3 releases but is argued to be more consistent. Per bug #3921 from Andrew Gilligan. (Note: I argued in the subsequent discussion that maybe LIKE shouldn't copy index tablespaces at all, but since no one indicated agreement with that idea, I've refrained from doing it.) --- diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index e9d64b22f3..f39a4e84aa 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -215,7 +215,7 @@ DefineIndex(RangeVar *heapRelation, } /* Check permissions except when using database's default */ - if (OidIsValid(tablespaceId)) + if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) { AclResult aclresult; diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 8dc6b1aee8..886b7924bc 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -340,7 +340,7 @@ DefineRelation(CreateStmt *stmt, char relkind) } /* Check permissions except when using database's default */ - if (OidIsValid(tablespaceId)) + if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) { AclResult aclresult; diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index def4b01c77..7b43e6e459 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -2594,7 +2594,7 @@ OpenIntoRel(QueryDesc *queryDesc) } /* Check permissions except when using the database's default space */ - if (OidIsValid(tablespaceId)) + if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) { AclResult aclresult; diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index 08b2917ff1..eec1e30d81 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -767,7 +767,10 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx, index = makeNode(IndexStmt); index->relation = cxt->relation; index->accessMethod = pstrdup(NameStr(amrec->amname)); - index->tableSpace = get_tablespace_name(source_idx->rd_node.spcNode); + if (OidIsValid(idxrelrec->reltablespace)) + index->tableSpace = get_tablespace_name(idxrelrec->reltablespace); + else + index->tableSpace = NULL; index->unique = idxrec->indisunique; index->primary = idxrec->indisprimary; index->concurrent = false; diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 768e28e19b..7b2716d209 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -1537,7 +1537,7 @@ typedef struct IndexStmt char *idxname; /* name of new index, or NULL for default */ RangeVar *relation; /* relation to build index on */ char *accessMethod; /* name of access method (eg. btree) */ - char *tableSpace; /* tablespace, or NULL to use parent's */ + char *tableSpace; /* tablespace, or NULL for default */ List *indexParams; /* a list of IndexElem */ List *options; /* options from WITH clause */ Node *whereClause; /* qualification (partial-index predicate) */