Fix CREATE TABLE ... LIKE ... INCLUDING INDEXES to not cause unwanted
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 7 Feb 2008 17:09:51 +0000 (17:09 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 7 Feb 2008 17:09:51 +0000 (17:09 +0000)
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.)

src/backend/commands/indexcmds.c
src/backend/commands/tablecmds.c
src/backend/executor/execMain.c
src/backend/parser/parse_utilcmd.c
src/include/nodes/parsenodes.h

index e9d64b22f3eed30dad4ba214df3ea074b6fcc35f..f39a4e84aaba6df38f3c57e12a8095b0b10442f8 100644 (file)
@@ -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;
 
index 8dc6b1aee89836209ed5a5e57990569ac98f731d..886b7924bc9286a27fb486bff916aa426a9bc298 100644 (file)
@@ -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;
 
index def4b01c77508fc95788ffead72b40a092ee5a67..7b43e6e459a9ee0fb693320fd39fe9cb34f14010 100644 (file)
@@ -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;
 
index 08b2917ff13155ec3edbd556424078ed6bd43a68..eec1e30d817f70e80d25dc4743d40e12a83a6203 100644 (file)
@@ -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;
index 768e28e19b61e272b6a1404b904c169fad2832b3..7b2716d209bf02c00fd17779bcba01fe19d04f8e 100644 (file)
@@ -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) */