Skip site navigation (1) Skip section navigation (2)

pgsql: Avoid pre-determining index names during CREATE TABLE LIKEparsi

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Avoid pre-determining index names during CREATE TABLE LIKEparsi
Date: 2012-07-16 17:25:44
Message-ID: E1Sqp3I-0008Lo-7v@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
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.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/3727240d01c4e7980ff9fe754e6524636edeaea7

Modified Files
--------------
src/backend/bootstrap/bootparse.y  |   68 +++++++++++++-----
src/backend/commands/indexcmds.c   |  135 +++++++++++++++--------------------
src/backend/commands/tablecmds.c   |   20 +-----
src/backend/nodes/copyfuncs.c      |    1 +
src/backend/nodes/equalfuncs.c     |    1 +
src/backend/nodes/outfuncs.c       |    1 +
src/backend/parser/gram.y          |    7 ++
src/backend/parser/parse_utilcmd.c |   58 +++-------------
src/backend/tcop/utility.c         |   18 +----
src/include/commands/defrem.h      |   22 +-----
src/include/nodes/parsenodes.h     |   20 +++---
11 files changed, 147 insertions(+), 204 deletions(-)

pgsql-committers by date

Next:From: Peter EisentrautDate: 2012-07-16 19:17:15
Subject: pgsql: Remove unreachable code
Previous:From: Tom LaneDate: 2012-07-15 17:29:14
Subject: pgsql: Prevent corner-case core dump in rfree().

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group