Fix CREATE TABLE ... LIKE ... INCLUDING INDEXES to not cause unwanted
authorTom Lane
Thu, 7 Feb 2008 17:09:51 +0000 (17:09 +0000)
committerTom Lane
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 952109f7845483f0c19e9de9940fbe90e60ee05d..fe4a1ef1b05c26bd97abe92767381f25acde22d5 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.170 2008/01/09 21:52:36 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.171 2008/02/07 17:09:51 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 3bd0b4d44de3c3b88279910c37a75af24bae072b..027fe51eca4761c1caf16bff3d0088e419a41e97 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.241 2008/01/30 19:46:48 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.242 2008/02/07 17:09:51 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 9b56a2241ebf59b01b2fa7b4e68627f57b2bf0b1..e9fb69be68e81ee4dcc3cd16908e17616cbaaf49 100644 (file)
@@ -26,7 +26,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.302 2008/01/01 19:45:49 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.303 2008/02/07 17:09:51 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 d7a1114bf15931ac244fe9aca5c533aae879d9ed..a9079ff2a9edfe3766a1b8613bd6111bf0dad477 100644 (file)
@@ -19,7 +19,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.8 2008/01/01 19:45:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.9 2008/02/07 17:09:51 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 6029bf67d2783a193f528f004232ee683187952b..c973eea729dbb2d3a5503e591feb245a78d3fde5 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.358 2008/01/01 19:45:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.359 2008/02/07 17:09:51 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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) */