From c176e122222c63844c0a2f3f8c568c3fe6c57d15 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 23 Dec 2009 16:43:43 +0000 Subject: [PATCH] Remove code that attempted to rename index columns to keep them in sync with their underlying table columns. That code was not bright enough to cope with collision situations (ie, new name conflicts with some other column of the index). Since there is no functional reason to do this at all, trying to upgrade the logic to be bulletproof doesn't seem worth the trouble. This change means that both the index name and the column names of an index are set when it's created, and won't be automatically changed when the underlying table columns are renamed. Neatnik DBAs are still free to rename them manually, of course. --- src/backend/commands/tablecmds.c | 76 ++------------------------------ 1 file changed, 4 insertions(+), 72 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index d7b6d9bc2e..5595473808 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.310 2009/12/15 04:57:47 rhaas Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.311 2009/12/23 16:43:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1905,17 +1905,6 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass) /* * renameatt - changes the name of a attribute in a relation - * - * Attname attribute is changed in attribute catalog. - * No record of the previous attname is kept (correct?). - * - * get proper relrelation from relation catalog (if not arg) - * scan attribute catalog - * for name conflict (within rel) - * for original attribute (if not arg) - * modify attname in attribute tuple - * insert modified attribute in attribute catalog - * delete original attribute from attribute catalog */ void renameatt(Oid myrelid, @@ -1929,8 +1918,6 @@ renameatt(Oid myrelid, HeapTuple atttup; Form_pg_attribute attform; int attnum; - List *indexoidlist; - ListCell *indexoidscan; /* * Grab an exclusive lock on the target table, which we will NOT release @@ -2024,7 +2011,8 @@ renameatt(Oid myrelid, errmsg("cannot rename inherited column \"%s\"", oldattname))); - /* should not already exist */ + /* new name should not already exist */ + /* this test is deliberately not attisdropped-aware */ if (SearchSysCacheExists(ATTNAME, ObjectIdGetDatum(myrelid), @@ -2035,6 +2023,7 @@ renameatt(Oid myrelid, errmsg("column \"%s\" of relation \"%s\" already exists", newattname, RelationGetRelationName(targetrelation)))); + /* apply the update */ namestrcpy(&(attform->attname), newattname); simple_heap_update(attrelation, &atttup->t_self, atttup); @@ -2044,63 +2033,6 @@ renameatt(Oid myrelid, heap_freetuple(atttup); - /* - * Update column names of indexes that refer to the column being renamed. - */ - indexoidlist = RelationGetIndexList(targetrelation); - - foreach(indexoidscan, indexoidlist) - { - Oid indexoid = lfirst_oid(indexoidscan); - HeapTuple indextup; - Form_pg_index indexform; - int i; - - /* - * Scan through index columns to see if there's any simple index - * entries for this attribute. We ignore expressional entries. - */ - indextup = SearchSysCache(INDEXRELID, - ObjectIdGetDatum(indexoid), - 0, 0, 0); - if (!HeapTupleIsValid(indextup)) - elog(ERROR, "cache lookup failed for index %u", indexoid); - indexform = (Form_pg_index) GETSTRUCT(indextup); - - for (i = 0; i < indexform->indnatts; i++) - { - if (attnum != indexform->indkey.values[i]) - continue; - - /* - * Found one, rename it. - */ - atttup = SearchSysCacheCopy(ATTNUM, - ObjectIdGetDatum(indexoid), - Int16GetDatum(i + 1), - 0, 0); - if (!HeapTupleIsValid(atttup)) - continue; /* should we raise an error? */ - - /* - * Update the (copied) attribute tuple. - */ - namestrcpy(&(((Form_pg_attribute) GETSTRUCT(atttup))->attname), - newattname); - - simple_heap_update(attrelation, &atttup->t_self, atttup); - - /* keep system catalog indexes current */ - CatalogUpdateIndexes(attrelation, atttup); - - heap_freetuple(atttup); - } - - ReleaseSysCache(indextup); - } - - list_free(indexoidlist); - heap_close(attrelation, RowExclusiveLock); relation_close(targetrelation, NoLock); /* close rel but keep lock */