Set all variable-length fields of pg_attribute to null on column drop

Started by Peter Eisentrautover 2 years ago4 messageshackers
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

I noticed that when a column is dropped, RemoveAttributeById() clears
out certain fields in pg_attribute, but it leaves the variable-length
fields at the end (attacl, attoptions, and attfdwoptions) unchanged.
This is probably harmless, but it seems wasteful and unclean, and leaves
potentially dangling data lying around (for example, attacl could
contain references to users that are later also dropped).

I suggest the attached patch to set those fields to null when a column
is marked as dropped.

Attachments:

v1-0001-Set-all-variable-length-fields-of-pg_attribute-to.patchtext/plain; charset=UTF-8; name=v1-0001-Set-all-variable-length-fields-of-pg_attribute-to.patchDownload+21-19
#2Robert Haas
robertmhaas@gmail.com
In reply to: Peter Eisentraut (#1)
Re: Set all variable-length fields of pg_attribute to null on column drop

On Thu, Nov 30, 2023 at 6:24 AM Peter Eisentraut <peter@eisentraut.org> wrote:

I noticed that when a column is dropped, RemoveAttributeById() clears
out certain fields in pg_attribute, but it leaves the variable-length
fields at the end (attacl, attoptions, and attfdwoptions) unchanged.
This is probably harmless, but it seems wasteful and unclean, and leaves
potentially dangling data lying around (for example, attacl could
contain references to users that are later also dropped).

I suggest the attached patch to set those fields to null when a column
is marked as dropped.

I haven't reviewed the patch, but +1 for the idea.

--
Robert Haas
EDB: http://www.enterprisedb.com

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Peter Eisentraut (#1)
Re: Set all variable-length fields of pg_attribute to null on column drop

On 2023-Nov-30, Peter Eisentraut wrote:

I noticed that when a column is dropped, RemoveAttributeById() clears out
certain fields in pg_attribute, but it leaves the variable-length fields at
the end (attacl, attoptions, and attfdwoptions) unchanged. This is probably
harmless, but it seems wasteful and unclean, and leaves potentially dangling
data lying around (for example, attacl could contain references to users
that are later also dropped).

Yeah, this looks like an ancient oversight -- when DROP COLUMN was added
we didn't have any varlena fields in this catalog, and when the first
one was added (attacl in commit 3cb5d6580a33) resetting it on DROP
COLUMN was overlooked.

LGTM.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"No hay ausente sin culpa ni presente sin disculpa" (Prov. francés)

#4Peter Eisentraut
peter_e@gmx.net
In reply to: Alvaro Herrera (#3)
Re: Set all variable-length fields of pg_attribute to null on column drop

On 22.12.23 10:05, Alvaro Herrera wrote:

On 2023-Nov-30, Peter Eisentraut wrote:

I noticed that when a column is dropped, RemoveAttributeById() clears out
certain fields in pg_attribute, but it leaves the variable-length fields at
the end (attacl, attoptions, and attfdwoptions) unchanged. This is probably
harmless, but it seems wasteful and unclean, and leaves potentially dangling
data lying around (for example, attacl could contain references to users
that are later also dropped).

Yeah, this looks like an ancient oversight -- when DROP COLUMN was added
we didn't have any varlena fields in this catalog, and when the first
one was added (attacl in commit 3cb5d6580a33) resetting it on DROP
COLUMN was overlooked.

LGTM.

committed