88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.260 2004/02/15 21:01:39 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.261 2004/03/23 19:35:16 tgl Exp $
1212 *
1313 *
1414 * INTERFACE ROUTINES
@@ -458,7 +458,9 @@ CheckAttributeType(const char *attname, Oid atttypid)
458458static void
459459AddNewAttributeTuples (Oid new_rel_oid ,
460460 TupleDesc tupdesc ,
461- char relkind )
461+ char relkind ,
462+ bool oidislocal ,
463+ int oidinhcount )
462464{
463465 Form_pg_attribute * dpp ;
464466 int i ;
@@ -531,11 +533,18 @@ AddNewAttributeTuples(Oid new_rel_oid,
531533 false,
532534 ATTRIBUTE_TUPLE_SIZE ,
533535 (void * ) * dpp );
536+ attStruct = (Form_pg_attribute ) GETSTRUCT (tup );
534537
535538 /* Fill in the correct relation OID in the copied tuple */
536- attStruct = (Form_pg_attribute ) GETSTRUCT (tup );
537539 attStruct -> attrelid = new_rel_oid ;
538540
541+ /* Fill in correct inheritance info for the OID column */
542+ if (attStruct -> attnum == ObjectIdAttributeNumber )
543+ {
544+ attStruct -> attislocal = oidislocal ;
545+ attStruct -> attinhcount = oidinhcount ;
546+ }
547+
539548 /*
540549 * Unneeded since they should be OK in the constant data
541550 * anyway
@@ -713,6 +722,8 @@ heap_create_with_catalog(const char *relname,
713722 TupleDesc tupdesc ,
714723 char relkind ,
715724 bool shared_relation ,
725+ bool oidislocal ,
726+ int oidinhcount ,
716727 OnCommitAction oncommit ,
717728 bool allow_system_table_mods )
718729{
@@ -786,7 +797,8 @@ heap_create_with_catalog(const char *relname,
786797 * now add tuples to pg_attribute for the attributes in our new
787798 * relation.
788799 */
789- AddNewAttributeTuples (new_rel_oid , new_rel_desc -> rd_att , relkind );
800+ AddNewAttributeTuples (new_rel_oid , new_rel_desc -> rd_att , relkind ,
801+ oidislocal , oidinhcount );
790802
791803 /*
792804 * make a dependency link to force the relation to be deleted if its
@@ -973,35 +985,46 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
973985 attnum , relid );
974986 attStruct = (Form_pg_attribute ) GETSTRUCT (tuple );
975987
976- /* Mark the attribute as dropped */
977- attStruct -> attisdropped = true;
988+ if (attnum < 0 )
989+ {
990+ /* System attribute (probably OID) ... just delete the row */
978991
979- /*
980- * Set the type OID to invalid. A dropped attribute's type link
981- * cannot be relied on (once the attribute is dropped, the type might
982- * be too). Fortunately we do not need the type row --- the only
983- * really essential information is the type's typlen and typalign,
984- * which are preserved in the attribute's attlen and attalign. We set
985- * atttypid to zero here as a means of catching code that incorrectly
986- * expects it to be valid.
987- */
988- attStruct -> atttypid = InvalidOid ;
992+ simple_heap_delete (attr_rel , & tuple -> t_self );
993+ }
994+ else
995+ {
996+ /* Dropping user attributes is lots harder */
989997
990- /* Remove any NOT NULL constraint the column may have */
991- attStruct -> attnotnull = false ;
998+ /* Mark the attribute as dropped */
999+ attStruct -> attisdropped = true ;
9921000
993- /* We don't want to keep stats for it anymore */
994- attStruct -> attstattarget = 0 ;
1001+ /*
1002+ * Set the type OID to invalid. A dropped attribute's type link
1003+ * cannot be relied on (once the attribute is dropped, the type might
1004+ * be too). Fortunately we do not need the type row --- the only
1005+ * really essential information is the type's typlen and typalign,
1006+ * which are preserved in the attribute's attlen and attalign. We set
1007+ * atttypid to zero here as a means of catching code that incorrectly
1008+ * expects it to be valid.
1009+ */
1010+ attStruct -> atttypid = InvalidOid ;
9951011
996- /* Change the column name to something that isn't likely to conflict */
997- snprintf (newattname , sizeof (newattname ),
998- "........pg.dropped.%d........" , attnum );
999- namestrcpy (& (attStruct -> attname ), newattname );
1012+ /* Remove any NOT NULL constraint the column may have */
1013+ attStruct -> attnotnull = false;
10001014
1001- simple_heap_update (attr_rel , & tuple -> t_self , tuple );
1015+ /* We don't want to keep stats for it anymore */
1016+ attStruct -> attstattarget = 0 ;
10021017
1003- /* keep the system catalog indexes current */
1004- CatalogUpdateIndexes (attr_rel , tuple );
1018+ /* Change the column name to something that isn't likely to conflict */
1019+ snprintf (newattname , sizeof (newattname ),
1020+ "........pg.dropped.%d........" , attnum );
1021+ namestrcpy (& (attStruct -> attname ), newattname );
1022+
1023+ simple_heap_update (attr_rel , & tuple -> t_self , tuple );
1024+
1025+ /* keep the system catalog indexes current */
1026+ CatalogUpdateIndexes (attr_rel , tuple );
1027+ }
10051028
10061029 /*
10071030 * Because updating the pg_attribute row will trigger a relcache flush
@@ -1011,7 +1034,8 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
10111034
10121035 heap_close (attr_rel , RowExclusiveLock );
10131036
1014- RemoveStatistics (rel , attnum );
1037+ if (attnum > 0 )
1038+ RemoveStatistics (rel , attnum );
10151039
10161040 relation_close (rel , NoLock );
10171041}
0 commit comments