Skip to content

Commit b7fe5f7

Browse files
committed
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.)
1 parent 26351d1 commit b7fe5f7

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

src/backend/commands/indexcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.170 2008/01/09 21:52:36 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.171 2008/02/07 17:09:51 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -215,7 +215,7 @@ DefineIndex(RangeVar *heapRelation,
215215
}
216216

217217
/* Check permissions except when using database's default */
218-
if (OidIsValid(tablespaceId))
218+
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
219219
{
220220
AclResult aclresult;
221221

src/backend/commands/tablecmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.241 2008/01/30 19:46:48 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.242 2008/02/07 17:09:51 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -340,7 +340,7 @@ DefineRelation(CreateStmt *stmt, char relkind)
340340
}
341341

342342
/* Check permissions except when using database's default */
343-
if (OidIsValid(tablespaceId))
343+
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
344344
{
345345
AclResult aclresult;
346346

src/backend/executor/execMain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.302 2008/01/01 19:45:49 momjian Exp $
29+
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.303 2008/02/07 17:09:51 tgl Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -2594,7 +2594,7 @@ OpenIntoRel(QueryDesc *queryDesc)
25942594
}
25952595

25962596
/* Check permissions except when using the database's default space */
2597-
if (OidIsValid(tablespaceId))
2597+
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
25982598
{
25992599
AclResult aclresult;
26002600

src/backend/parser/parse_utilcmd.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
22-
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.8 2008/01/01 19:45:51 momjian Exp $
22+
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.9 2008/02/07 17:09:51 tgl Exp $
2323
*
2424
*-------------------------------------------------------------------------
2525
*/
@@ -767,7 +767,10 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
767767
index = makeNode(IndexStmt);
768768
index->relation = cxt->relation;
769769
index->accessMethod = pstrdup(NameStr(amrec->amname));
770-
index->tableSpace = get_tablespace_name(source_idx->rd_node.spcNode);
770+
if (OidIsValid(idxrelrec->reltablespace))
771+
index->tableSpace = get_tablespace_name(idxrelrec->reltablespace);
772+
else
773+
index->tableSpace = NULL;
771774
index->unique = idxrec->indisunique;
772775
index->primary = idxrec->indisprimary;
773776
index->concurrent = false;

src/include/nodes/parsenodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.358 2008/01/01 19:45:58 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.359 2008/02/07 17:09:51 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1537,7 +1537,7 @@ typedef struct IndexStmt
15371537
char *idxname; /* name of new index, or NULL for default */
15381538
RangeVar *relation; /* relation to build index on */
15391539
char *accessMethod; /* name of access method (eg. btree) */
1540-
char *tableSpace; /* tablespace, or NULL to use parent's */
1540+
char *tableSpace; /* tablespace, or NULL for default */
15411541
List *indexParams; /* a list of IndexElem */
15421542
List *options; /* options from WITH clause */
15431543
Node *whereClause; /* qualification (partial-index predicate) */

0 commit comments

Comments
 (0)