Re: not null constraints, again
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Tender Wang <tndrwang@gmail.com>
Cc: jian he <jian.universality@gmail.com>, Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-09-20T21:15:19Z
Lists: pgsql-hackers
Attachments
- v4-0001-Catalog-not-null-constraints.patch (text/x-diff)
On 2024-Sep-20, Alvaro Herrera wrote:
> Yeah, there's a bunch of conflicts in current master. I rebased
> yesterday but I'm still composing the email for v4. Coming soon.
Okay, so here is v4 with these problems fixed, including correct
propagation of constraint names to children tables, which I had
inadvertently broken earlier. This one does pass the pg_upgrade tests
and as far as I can see pg_dump does all the correct things also. I
cleaned up the tests to remove everything that's unneeded, redundant, or
testing behavior that no longer exists.
I changed the behavior of ALTER TABLE ONLY <parent> ADD PRIMARY KEY, so
that it throws error in case a child does not have a NOT NULL constraint
on one of the columns, rather than silently creating such a constraint.
(This is how `master` currently behaves). I think this is better
behavior, because it lets the user decide whether they want to scan the
table to create that constraint or not. It's a bit crude at present,
because (1) a child could have a NO INHERIT constraint and have further
children, which would foil the check (I think changing
find_inheritance_children to find_all_inheritors would be sufficient to
fix this, but that's only needed in legacy inheritance not
partitioning); (2) the error message doesn't have an errcode, and the
wording might need work.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Learn about compilers. Then everything looks like either a compiler or
a database, and now you have two problems but one of them is fun."
https://twitter.com/thingskatedid/status/1456027786158776329
Commits
-
Suppress "may be used uninitialized" warnings from older compilers.
- fc5e966f73f0 18.0 landed
-
Elide not-null constraint checks on child tables during PK creation
- 11ff192b5bb7 18.0 landed
-
Remove unnecessary code to handle CONSTR_NOTNULL
- 5b291d1c9c09 18.0 landed
-
Silence compilers about extractNotNullColumn()
- ff239c3bf4e8 18.0 landed
-
Add pg_constraint rows for not-null constraints
- 14e87ffa5c54 18.0 landed