Re: not null constraints, again
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: jian he <jian.universality@gmail.com>
Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>, Tender Wang <tndrwang@gmail.com>
Date: 2024-10-14T16:06:05Z
Lists: pgsql-hackers
Attachments
- v10-0001-Catalog-not-null-constraints.patch (text/x-diff)
On 2024-Oct-10, jian he wrote: > tricky case: > drop table if exists part, part0 cascade; > create table part (a int not null) partition by range (a); > create table part0 (a int primary key); > alter table part attach partition part0 for values from (0) to (1000); > alter table ONLY part add primary key(a); > alter table ONLY part drop constraint part_a_not_null; > -- alter table ONLY part alter column a drop not null; > > > Now we are in a state where a partitioned > table have a primary key but doesn't have a not-null constraint for it. Oh, of course! This means that the comment in RelationGetIndexList (reverted in 6f8bb7c1e961) was incorrect: it was not only about pg_dump's strategy for dumping PKs in partitioned tables, but it was also about protecting those not-nulls under PKs for the same tables. By removing it (which I did when I forward-ported the reversal of the reversal) I removed that protection, and failed to notice because we don't have this test case. Anyway, I put it back, fixing the comment; and I also had to change RelationGetPrimaryKeyIndex API to have an additional "bool deferrable_ok" parameter, so that it knows it can return a deferrable PK. This is needed by the code just added in dropconstraint_internal(). I also added your test case. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ Officer Krupke, what are we to do? Gee, officer Krupke, Krup you! (West Side Story, "Gee, Officer Krupke")
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