diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2023-12-22 21:44:55 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2023-12-22 21:44:55 +0100 |
commit | 3e2e0d5ad7fcb89d18a71cbfc885ef184e1b6f2e (patch) | |
tree | da03307ed09a28bcfa129abaf0c98e9fcddf07a5 /src | |
parent | e2b73f4a4de6c2df6a1e623ad06b42f1bb2471ad (diff) | |
download | postgresql-3e2e0d5ad7fcb89d18a71cbfc885ef184e1b6f2e.tar.gz postgresql-3e2e0d5ad7fcb89d18a71cbfc885ef184e1b6f2e.zip |
Set all variable-length fields of pg_attribute to null on column drop
When a column is dropped, the fields attacl, attoptions, and
attfdwoptions were kept unchanged. This is probably harmless, but it
seems wasteful, and leaves potentially dangling data lying around (for
example, attacl could contain references to users that are later also
dropped).
Change this to set those fields to null when a column is marked as
dropped.
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/249d819d-1763-4580-8110-0bf91a0f08b7@eisentraut.org
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/catalog/heap.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 7224d966950..b93894889d6 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -1647,6 +1647,9 @@ RemoveAttributeById(Oid relid, AttrNumber attnum) HeapTuple tuple; Form_pg_attribute attStruct; char newattname[NAMEDATALEN]; + Datum valuesAtt[Natts_pg_attribute] = {0}; + bool nullsAtt[Natts_pg_attribute] = {0}; + bool replacesAtt[Natts_pg_attribute] = {0}; /* * Grab an exclusive lock on the target table, which we will NOT release @@ -1695,24 +1698,24 @@ RemoveAttributeById(Oid relid, AttrNumber attnum) "........pg.dropped.%d........", attnum); namestrcpy(&(attStruct->attname), newattname); - /* clear the missing value if any */ - if (attStruct->atthasmissing) - { - Datum valuesAtt[Natts_pg_attribute] = {0}; - bool nullsAtt[Natts_pg_attribute] = {0}; - bool replacesAtt[Natts_pg_attribute] = {0}; - - /* update the tuple - set atthasmissing and attmissingval */ - valuesAtt[Anum_pg_attribute_atthasmissing - 1] = - BoolGetDatum(false); - replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true; - valuesAtt[Anum_pg_attribute_attmissingval - 1] = (Datum) 0; - nullsAtt[Anum_pg_attribute_attmissingval - 1] = true; - replacesAtt[Anum_pg_attribute_attmissingval - 1] = true; - - tuple = heap_modify_tuple(tuple, RelationGetDescr(attr_rel), - valuesAtt, nullsAtt, replacesAtt); - } + /* Clear the missing value */ + attStruct->atthasmissing = false; + nullsAtt[Anum_pg_attribute_attmissingval - 1] = true; + replacesAtt[Anum_pg_attribute_attmissingval - 1] = true; + + /* + * Clear the other variable-length fields. This saves some space in + * pg_attribute and removes no longer useful information. + */ + nullsAtt[Anum_pg_attribute_attacl - 1] = true; + replacesAtt[Anum_pg_attribute_attacl - 1] = true; + nullsAtt[Anum_pg_attribute_attoptions - 1] = true; + replacesAtt[Anum_pg_attribute_attoptions - 1] = true; + nullsAtt[Anum_pg_attribute_attfdwoptions - 1] = true; + replacesAtt[Anum_pg_attribute_attfdwoptions - 1] = true; + + tuple = heap_modify_tuple(tuple, RelationGetDescr(attr_rel), + valuesAtt, nullsAtt, replacesAtt); CatalogTupleUpdate(attr_rel, &tuple->t_self, tuple); |