Skip to content

Commit 3727240

Browse files
committed
Avoid pre-determining index names during CREATE TABLE LIKE parsing.
Formerly, when trying to copy both indexes and comments, CREATE TABLE LIKE had to pre-assign names to indexes that had comments, because it made up an explicit CommentStmt command to apply the comment and so it had to know the name for the index. This creates bad interactions with other indexes, as shown in bug #6734 from Daniele Varrazzo: the preassignment logic couldn't take any other indexes into account so it could choose a conflicting name. To fix, add a field to IndexStmt that allows it to carry a comment to be assigned to the new index. (This isn't a user-exposed feature of CREATE INDEX, only an internal option.) Now we don't need preassignment of index names in any situation. I also took the opportunity to refactor DefineIndex to accept the IndexStmt as such, rather than passing all its fields individually in a mile-long parameter list. Back-patch to 9.2, but no further, because it seems too dangerous to change IndexStmt or DefineIndex's API in released branches. The bug exists back to 9.0 where CREATE TABLE LIKE grew the ability to copy comments, but given the lack of prior complaints we'll just let it go unfixed before 9.2.
1 parent 1116c9d commit 3727240

File tree

11 files changed

+147
-204
lines changed

11 files changed

+147
-204
lines changed

src/backend/bootstrap/bootparse.y

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,37 +280,69 @@ Boot_InsertStmt:
280280
Boot_DeclareIndexStmt:
281281
XDECLARE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
282282
{
283+
IndexStmt *stmt = makeNode(IndexStmt);
284+
283285
do_start();
284286

285-
DefineIndex(makeRangeVar(NULL, $6, -1),
286-
$3,
287+
stmt->idxname = $3;
288+
stmt->relation = makeRangeVar(NULL, $6, -1);
289+
stmt->accessMethod = $8;
290+
stmt->tableSpace = NULL;
291+
stmt->indexParams = $10;
292+
stmt->options = NIL;
293+
stmt->whereClause = NULL;
294+
stmt->excludeOpNames = NIL;
295+
stmt->idxcomment = NULL;
296+
stmt->indexOid = InvalidOid;
297+
stmt->oldNode = InvalidOid;
298+
stmt->unique = false;
299+
stmt->primary = false;
300+
stmt->isconstraint = false;
301+
stmt->deferrable = false;
302+
stmt->initdeferred = false;
303+
stmt->concurrent = false;
304+
305+
DefineIndex(stmt,
287306
$4,
288-
InvalidOid,
289-
$8,
290-
NULL,
291-
$10,
292-
NULL, NIL, NIL,
293-
false, false, false, false, false,
294-
false, false, true, false, false);
307+
false,
308+
false,
309+
true, /* skip_build */
310+
false);
295311
do_end();
296312
}
297313
;
298314

299315
Boot_DeclareUniqueIndexStmt:
300316
XDECLARE UNIQUE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
301317
{
318+
IndexStmt *stmt = makeNode(IndexStmt);
319+
302320
do_start();
303321

304-
DefineIndex(makeRangeVar(NULL, $7, -1),
305-
$4,
322+
stmt->idxname = $4;
323+
stmt->relation = makeRangeVar(NULL, $7, -1);
324+
stmt->accessMethod = $9;
325+
stmt->tableSpace = NULL;
326+
stmt->indexParams = $11;
327+
stmt->options = NIL;
328+
stmt->whereClause = NULL;
329+
stmt->excludeOpNames = NIL;
330+
stmt->idxcomment = NULL;
331+
stmt->indexOid = InvalidOid;
332+
stmt->oldNode = InvalidOid;
333+
stmt->unique = true;
334+
stmt->primary = false;
335+
stmt->isconstraint = false;
336+
stmt->deferrable = false;
337+
stmt->initdeferred = false;
338+
stmt->concurrent = false;
339+
340+
DefineIndex(stmt,
306341
$5,
307-
InvalidOid,
308-
$9,
309-
NULL,
310-
$11,
311-
NULL, NIL, NIL,
312-
true, false, false, false, false,
313-
false, false, true, false, false);
342+
false,
343+
false,
344+
true, /* skip_build */
345+
false);
314346
do_end();
315347
}
316348
;

0 commit comments

Comments
 (0)