mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
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.
This commit is contained in:
@ -5389,6 +5389,7 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel,
|
||||
Oid new_index;
|
||||
|
||||
Assert(IsA(stmt, IndexStmt));
|
||||
Assert(!stmt->concurrent);
|
||||
|
||||
/* suppress schema rights check when rebuilding existing index */
|
||||
check_rights = !is_rebuild;
|
||||
@ -5399,26 +5400,12 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel,
|
||||
|
||||
/* The IndexStmt has already been through transformIndexStmt */
|
||||
|
||||
new_index = DefineIndex(stmt->relation, /* relation */
|
||||
stmt->idxname, /* index name */
|
||||
new_index = DefineIndex(stmt,
|
||||
InvalidOid, /* no predefined OID */
|
||||
stmt->oldNode,
|
||||
stmt->accessMethod, /* am name */
|
||||
stmt->tableSpace,
|
||||
stmt->indexParams, /* parameters */
|
||||
(Expr *) stmt->whereClause,
|
||||
stmt->options,
|
||||
stmt->excludeOpNames,
|
||||
stmt->unique,
|
||||
stmt->primary,
|
||||
stmt->isconstraint,
|
||||
stmt->deferrable,
|
||||
stmt->initdeferred,
|
||||
true, /* is_alter_table */
|
||||
check_rights,
|
||||
skip_build,
|
||||
quiet,
|
||||
false);
|
||||
quiet);
|
||||
|
||||
/*
|
||||
* If TryReuseIndex() stashed a relfilenode for us, we used it for the new
|
||||
@ -7968,7 +7955,6 @@ ATPostAlterTypeParse(Oid oldId, char *cmd,
|
||||
static void
|
||||
TryReuseIndex(Oid oldId, IndexStmt *stmt)
|
||||
{
|
||||
|
||||
if (CheckIndexCompatible(oldId,
|
||||
stmt->relation,
|
||||
stmt->accessMethod,
|
||||
|
Reference in New Issue
Block a user