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: Tender Wang <tndrwang@gmail.com>, Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-10-02T14:25:13Z
Lists: pgsql-hackers
On 2024-Oct-02, Alvaro Herrera wrote: > On 2024-Oct-02, jian he wrote: > > > On Tue, Oct 1, 2024 at 11:20 PM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote: > > after v7, still not bullet-proof. as before, pg_dump/restore will fail > > for the following: > > > > drop table if exists t2, t2_0 > > create table t2 (a int, b int, c int, constraint foo primary key(a), > > constraint foo1 not null a no inherit); > > create table t2_0 (a int constraint foo1 not null no inherit, b int, c > > int, constraint foo12 primary key(a)); > > Rats. Fixing :-) Hmm, I thought this was going to be a five-minute job: I figured I could add a check in DefineIndex() that reads all columns and ensure they're no-inherit. First complication: when creating a partition, we do DefineIndex to create the indexes that the parent table has, before we do AddRelationNotNullConstraints(), so the not-null constraint lookup fails. Easy enough to fix: just move the AddRelationNotNullConstraints call a few lines up. However, things are still not OK because ALTER TABLE ALTER COLUMN TYPE does want to recreate the PK before the not-nulls (per ATPostAlterTypeParse), because AT_PASS_OLD_INDEX comes before AT_PASS_OLD_CONSTR ... and obviously we cannot change that. Another possibility is to add something like AT_PASS_OLD_NOTNULL but that sounds far too ad-hoc. Maybe I need the restriction to appear somewhere else rather than on DefineIndex. Still looking ... -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Los dioses no protegen a los insensatos. Éstos reciben protección de otros insensatos mejor dotados" (Luis Wu, Mundo Anillo)
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