8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*
14
14
* INTERFACE ROUTINES
@@ -458,7 +458,9 @@ CheckAttributeType(const char *attname, Oid atttypid)
458
458
static void
459
459
AddNewAttributeTuples (Oid new_rel_oid ,
460
460
TupleDesc tupdesc ,
461
- char relkind )
461
+ char relkind ,
462
+ bool oidislocal ,
463
+ int oidinhcount )
462
464
{
463
465
Form_pg_attribute * dpp ;
464
466
int i ;
@@ -531,11 +533,18 @@ AddNewAttributeTuples(Oid new_rel_oid,
531
533
false,
532
534
ATTRIBUTE_TUPLE_SIZE ,
533
535
(void * ) * dpp );
536
+ attStruct = (Form_pg_attribute ) GETSTRUCT (tup );
534
537
535
538
/* Fill in the correct relation OID in the copied tuple */
536
- attStruct = (Form_pg_attribute ) GETSTRUCT (tup );
537
539
attStruct -> attrelid = new_rel_oid ;
538
540
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
+
539
548
/*
540
549
* Unneeded since they should be OK in the constant data
541
550
* anyway
@@ -713,6 +722,8 @@ heap_create_with_catalog(const char *relname,
713
722
TupleDesc tupdesc ,
714
723
char relkind ,
715
724
bool shared_relation ,
725
+ bool oidislocal ,
726
+ int oidinhcount ,
716
727
OnCommitAction oncommit ,
717
728
bool allow_system_table_mods )
718
729
{
@@ -786,7 +797,8 @@ heap_create_with_catalog(const char *relname,
786
797
* now add tuples to pg_attribute for the attributes in our new
787
798
* relation.
788
799
*/
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 );
790
802
791
803
/*
792
804
* make a dependency link to force the relation to be deleted if its
@@ -973,35 +985,46 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
973
985
attnum , relid );
974
986
attStruct = (Form_pg_attribute ) GETSTRUCT (tuple );
975
987
976
- /* Mark the attribute as dropped */
977
- attStruct -> attisdropped = true;
988
+ if (attnum < 0 )
989
+ {
990
+ /* System attribute (probably OID) ... just delete the row */
978
991
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 */
989
997
990
- /* Remove any NOT NULL constraint the column may have */
991
- attStruct -> attnotnull = false ;
998
+ /* Mark the attribute as dropped */
999
+ attStruct -> attisdropped = true ;
992
1000
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 ;
995
1011
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;
1000
1014
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 ;
1002
1017
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
+ }
1005
1028
1006
1029
/*
1007
1030
* Because updating the pg_attribute row will trigger a relcache flush
@@ -1011,7 +1034,8 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
1011
1034
1012
1035
heap_close (attr_rel , RowExclusiveLock );
1013
1036
1014
- RemoveStatistics (rel , attnum );
1037
+ if (attnum > 0 )
1038
+ RemoveStatistics (rel , attnum );
1015
1039
1016
1040
relation_close (rel , NoLock );
1017
1041
}
0 commit comments