Re: bug when apply fast default mechanism for adding new column over domain with default value
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-03-03T14:20:21Z
Lists: pgsql-hackers
Attachments
- v3-0001-minor-refactoring-DefineRelation-StoreAttrDefa.no-cfbot (application/octet-stream)
On Mon, Mar 3, 2025 at 4:45 PM jian he <jian.universality@gmail.com> wrote: > > looking at DefineRelation comments: > * We can set the atthasdef flags now in the tuple descriptor; this just > * saves StoreAttrDefault from having to do an immediate update of the > * pg_attribute rows. > this seems not right? > DefineRelation->heap_create_with_catalog->heap_create->RelationBuildLocalRelation->CreateTupleDescCopy > don't copy atthasdef. > RelationBuildLocalRelation later didn't touch atthasdef. > populate_compact_attribute didn't touch atthasdef. > so StoreAttrDefault has to update that pg_attribute row. > CREATE TABLE (COLUMN x DEFAULT y): for each (Relation rel, AttrNumber attnum), we can enter StoreAttrDefault once. Also for the above quoted reason, in DefineRelation, we didn't change pg_attribute.atthasdef before entering StoreAttrDefault. ALTER TABLE ALTER COLUMN SET/DROP DEFAULT: in ATExecColumnDefault will first do RemoveAttrDefault, then re add the default expression. In this case, in StoreAttrDefault: attStruct->atthasdef will be false. overall, i think DefineRelation about StoreAttrDefault comments can be removed. and StoreAttrDefault, "if (!attStruct->atthasdef)" part logic can also be changed. The attached is the minor change I came up with, based on v3-0001 and v3-0002.
Commits
-
Need to do CommandCounterIncrement after StoreAttrMissingVal.
- dd34cbfce296 13.21 landed
- d31d39cfe4f5 14.18 landed
- bd178960c69b 18.0 landed
- 2d6cfb0cddd3 15.13 landed
- 0941aadcd55b 17.5 landed
- 053222a97b13 16.9 landed
-
Simplify some logic around setting pg_attribute.atthasdef.
- 35c8dd9e1176 18.0 landed
-
Remove now-dead code in StoreAttrDefault().
- 4528768d98f8 18.0 landed
-
Fix broken handling of domains in atthasmissing logic.
- 95f650674d2c 18.0 landed
- edc3bccd0dc7 16.9 landed
- d6dd2a02bae0 17.5 landed
- c75c830e2392 14.18 landed
- aac07b56256e 13.21 landed
- 1d180931cc3b 15.13 landed