Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c176e12

Browse files
committed
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.
1 parent df0cdd5 commit c176e12

File tree

1 file changed

+4
-72
lines changed

1 file changed

+4
-72
lines changed

src/backend/commands/tablecmds.c

Lines changed: 4 additions & 72 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.310 2009/12/15 04:57:47 rhaas Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.311 2009/12/23 16:43:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1905,17 +1905,6 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass)
19051905

19061906
/*
19071907
* renameatt - changes the name of a attribute in a relation
1908-
*
1909-
* Attname attribute is changed in attribute catalog.
1910-
* No record of the previous attname is kept (correct?).
1911-
*
1912-
* get proper relrelation from relation catalog (if not arg)
1913-
* scan attribute catalog
1914-
* for name conflict (within rel)
1915-
* for original attribute (if not arg)
1916-
* modify attname in attribute tuple
1917-
* insert modified attribute in attribute catalog
1918-
* delete original attribute from attribute catalog
19191908
*/
19201909
void
19211910
renameatt(Oid myrelid,
@@ -1929,8 +1918,6 @@ renameatt(Oid myrelid,
19291918
HeapTuple atttup;
19301919
Form_pg_attribute attform;
19311920
int attnum;
1932-
List *indexoidlist;
1933-
ListCell *indexoidscan;
19341921

19351922
/*
19361923
* Grab an exclusive lock on the target table, which we will NOT release
@@ -2024,7 +2011,8 @@ renameatt(Oid myrelid,
20242011
errmsg("cannot rename inherited column \"%s\"",
20252012
oldattname)));
20262013

2027-
/* should not already exist */
2014+
/* new name should not already exist */
2015+
20282016
/* this test is deliberately not attisdropped-aware */
20292017
if (SearchSysCacheExists(ATTNAME,
20302018
ObjectIdGetDatum(myrelid),
@@ -2035,6 +2023,7 @@ renameatt(Oid myrelid,
20352023
errmsg("column \"%s\" of relation \"%s\" already exists",
20362024
newattname, RelationGetRelationName(targetrelation))));
20372025

2026+
/* apply the update */
20382027
namestrcpy(&(attform->attname), newattname);
20392028

20402029
simple_heap_update(attrelation, &atttup->t_self, atttup);
@@ -2044,63 +2033,6 @@ renameatt(Oid myrelid,
20442033

20452034
heap_freetuple(atttup);
20462035

2047-
/*
2048-
* Update column names of indexes that refer to the column being renamed.
2049-
*/
2050-
indexoidlist = RelationGetIndexList(targetrelation);
2051-
2052-
foreach(indexoidscan, indexoidlist)
2053-
{
2054-
Oid indexoid = lfirst_oid(indexoidscan);
2055-
HeapTuple indextup;
2056-
Form_pg_index indexform;
2057-
int i;
2058-
2059-
/*
2060-
* Scan through index columns to see if there's any simple index
2061-
* entries for this attribute. We ignore expressional entries.
2062-
*/
2063-
indextup = SearchSysCache(INDEXRELID,
2064-
ObjectIdGetDatum(indexoid),
2065-
0, 0, 0);
2066-
if (!HeapTupleIsValid(indextup))
2067-
elog(ERROR, "cache lookup failed for index %u", indexoid);
2068-
indexform = (Form_pg_index) GETSTRUCT(indextup);
2069-
2070-
for (i = 0; i < indexform->indnatts; i++)
2071-
{
2072-
if (attnum != indexform->indkey.values[i])
2073-
continue;
2074-
2075-
/*
2076-
* Found one, rename it.
2077-
*/
2078-
atttup = SearchSysCacheCopy(ATTNUM,
2079-
ObjectIdGetDatum(indexoid),
2080-
Int16GetDatum(i + 1),
2081-
0, 0);
2082-
if (!HeapTupleIsValid(atttup))
2083-
continue; /* should we raise an error? */
2084-
2085-
/*
2086-
* Update the (copied) attribute tuple.
2087-
*/
2088-
namestrcpy(&(((Form_pg_attribute) GETSTRUCT(atttup))->attname),
2089-
newattname);
2090-
2091-
simple_heap_update(attrelation, &atttup->t_self, atttup);
2092-
2093-
/* keep system catalog indexes current */
2094-
CatalogUpdateIndexes(attrelation, atttup);
2095-
2096-
heap_freetuple(atttup);
2097-
}
2098-
2099-
ReleaseSysCache(indextup);
2100-
}
2101-
2102-
list_free(indexoidlist);
2103-
21042036
heap_close(attrelation, RowExclusiveLock);
21052037

21062038
relation_close(targetrelation, NoLock); /* close rel but keep lock */

0 commit comments

Comments
 (0)