Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3e2e0d5

Browse files
committed
Set all variable-length fields of pg_attribute to null on column drop
When a column is dropped, the fields attacl, attoptions, andattfdwoptions were kept unchanged. This is probably harmless, but itseems wasteful, and leaves potentially dangling data lying around (forexample, attacl could contain references to users that are later alsodropped).Change this to set those fields to null when a column is marked asdropped.Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>Discussion:https://www.postgresql.org/message-id/flat/249d819d-1763-4580-8110-0bf91a0f08b7@eisentraut.org
1 parente2b73f4 commit3e2e0d5

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

‎src/backend/catalog/heap.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,9 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
16471647
HeapTupletuple;
16481648
Form_pg_attributeattStruct;
16491649
charnewattname[NAMEDATALEN];
1650+
DatumvaluesAtt[Natts_pg_attribute]= {0};
1651+
boolnullsAtt[Natts_pg_attribute]= {0};
1652+
boolreplacesAtt[Natts_pg_attribute]= {0};
16501653

16511654
/*
16521655
* Grab an exclusive lock on the target table, which we will NOT release
@@ -1695,24 +1698,24 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
16951698
"........pg.dropped.%d........",attnum);
16961699
namestrcpy(&(attStruct->attname),newattname);
16971700

1698-
/*clear the missing value if any */
1699-
if (attStruct->atthasmissing)
1700-
{
1701-
DatumvaluesAtt[Natts_pg_attribute]={0};
1702-
boolnullsAtt[Natts_pg_attribute]= {0};
1703-
boolreplacesAtt[Natts_pg_attribute]= {0};
1704-
1705-
/* update the tuple - set atthasmissing and attmissingval */
1706-
valuesAtt[Anum_pg_attribute_atthasmissing-1]=
1707-
BoolGetDatum(false);
1708-
replacesAtt[Anum_pg_attribute_atthasmissing-1]= true;
1709-
valuesAtt[Anum_pg_attribute_attmissingval-1]=(Datum)0;
1710-
nullsAtt[Anum_pg_attribute_attmissingval-1]= true;
1711-
replacesAtt[Anum_pg_attribute_attmissingval-1]= true;
1712-
1713-
tuple=heap_modify_tuple(tuple,RelationGetDescr(attr_rel),
1714-
valuesAtt,nullsAtt,replacesAtt);
1715-
}
1701+
/*Clear the missing value */
1702+
attStruct->atthasmissing= false;
1703+
nullsAtt[Anum_pg_attribute_attmissingval-1]= true;
1704+
replacesAtt[Anum_pg_attribute_attmissingval-1]=true;
1705+
1706+
/*
1707+
* Clear the other variable-length fields. This saves some space in
1708+
* pg_attribute and removes no longer useful information.
1709+
*/
1710+
nullsAtt[Anum_pg_attribute_attacl-1]= true;
1711+
replacesAtt[Anum_pg_attribute_attacl-1]= true;
1712+
nullsAtt[Anum_pg_attribute_attoptions-1]=true;
1713+
replacesAtt[Anum_pg_attribute_attoptions-1]= true;
1714+
nullsAtt[Anum_pg_attribute_attfdwoptions-1]= true;
1715+
replacesAtt[Anum_pg_attribute_attfdwoptions-1]= true;
1716+
1717+
tuple=heap_modify_tuple(tuple,RelationGetDescr(attr_rel),
1718+
valuesAtt,nullsAtt,replacesAtt);
17161719

17171720
CatalogTupleUpdate(attr_rel,&tuple->t_self,tuple);
17181721

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp