8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -1905,17 +1905,6 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass)
1905
1905
1906
1906
/*
1907
1907
* 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
1919
1908
*/
1920
1909
void
1921
1910
renameatt (Oid myrelid ,
@@ -1929,8 +1918,6 @@ renameatt(Oid myrelid,
1929
1918
HeapTuple atttup ;
1930
1919
Form_pg_attribute attform ;
1931
1920
int attnum ;
1932
- List * indexoidlist ;
1933
- ListCell * indexoidscan ;
1934
1921
1935
1922
/*
1936
1923
* Grab an exclusive lock on the target table, which we will NOT release
@@ -2024,7 +2011,8 @@ renameatt(Oid myrelid,
2024
2011
errmsg ("cannot rename inherited column \"%s\"" ,
2025
2012
oldattname )));
2026
2013
2027
- /* should not already exist */
2014
+ /* new name should not already exist */
2015
+
2028
2016
/* this test is deliberately not attisdropped-aware */
2029
2017
if (SearchSysCacheExists (ATTNAME ,
2030
2018
ObjectIdGetDatum (myrelid ),
@@ -2035,6 +2023,7 @@ renameatt(Oid myrelid,
2035
2023
errmsg ("column \"%s\" of relation \"%s\" already exists" ,
2036
2024
newattname , RelationGetRelationName (targetrelation ))));
2037
2025
2026
+ /* apply the update */
2038
2027
namestrcpy (& (attform -> attname ), newattname );
2039
2028
2040
2029
simple_heap_update (attrelation , & atttup -> t_self , atttup );
@@ -2044,63 +2033,6 @@ renameatt(Oid myrelid,
2044
2033
2045
2034
heap_freetuple (atttup );
2046
2035
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
-
2104
2036
heap_close (attrelation , RowExclusiveLock );
2105
2037
2106
2038
relation_close (targetrelation , NoLock ); /* close rel but keep lock */
0 commit comments