Re: not null constraints, again
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Tender Wang <tndrwang@gmail.com>, jian he <jian.universality@gmail.com>,
Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-04-15T19:51:14Z
Lists: pgsql-hackers
Alvaro Herrera <alvherre@alvh.no-ip.org> writes: > However, I've also been looking at this and realized that this code can > have different structure which may allows us to skip the > find_inheritance_children() altogether. The reason is that we already > scan the parent's list of columns searching for not-null constraints on > each of them; we only need to run this verification on children for > columns where there is none in the parent, and then only in the case > where recursion is turned off. +1. Fundamentally the problem here is that pg_restore needs ALTER TABLE ONLY foo ADD PRIMARY KEY to not recurse to child tables at all. It is expecting this command to acquire a lock on foo and nothing else; and it has already taken care of making foo's PK column(s) NOT NULL, so there is no reason we should have to examine the children. Looking at the patch itself, it doesn't seem like the got_children flag is accomplishing anything; I guess that was leftover from an earlier version? You could declare "List *children" inside the block where it's used, too. Basically, this patch is just moving the check-the-children logic from one place to another. Also I find the comments still a bit confusing, but maybe that's on me. regards, tom lane
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