Re: bug when apply fast default mechanism for adding new column over domain with default value
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jian he <jian.universality@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-03-01T23:54:21Z
Lists: pgsql-hackers
jian he <jian.universality@gmail.com> writes: > So I duplicated StoreAttrDefault and removed pg_attribute.atthasdef, > pg_attrdef related code. > and it works fine. I think the fundamental problem here is that StoreAttrDefault shouldn't be involved in this in the first place. It looks like somebody did that in the hopes of avoiding two updates of the new pg_attribute row (one to set atthasdef and the other to fill attmissingval), but it's just bad code structure. We should take that code out of StoreAttrDefault, not duplicate it, because the assumption that the missingval is identical to what goes into pg_attrdef is just wrong. (We could possibly get back down to one update by moving code in ATExecAddColumn so that we know before calling InsertPgAttributeTuples whether the column will have a non-null default, and then we could set atthasdef correctly in the originally-inserted tuple. That's an optimization though, not part of the basic bug fix.) Also, since the "if (RELKIND_HAS_STORAGE(relkind))" stanza in ATExecAddColumn is already calling expression_planner, we should be able to avoid doing that twice on the way to discovering whether the expression is a constant. I kind of feel that StoreAttrMissingVal belongs in heap.c; it's got about nothing to do with pg_attrdef. regards, tom lane
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