Re: Support NOT VALID / VALIDATE constraint options for named NOT NULL constraints
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: jian he <jian.universality@gmail.com>
Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>, Rushabh Lathia <rushabh.lathia@gmail.com>,
PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2025-03-21T14:50:37Z
Lists: pgsql-hackers
On 2025-Mar-21, jian he wrote: > * if partitioned table have valid not-null, then partition with > invalid not-null can not attach to the partition tree. Correct. > if partitioned table have not valid not-null, we *can* attach a > valid not-null to the partition tree. Also correct. > (inheritance hierarchy behaves the same). Good -- it should! :-) > this part does not require a lot of code changes. > However, to make the pg_dump working with partitioned table we need to > tweak AdjustNotNullInheritance a little bit. Hmm, well, modifying a function to suite what we need it to do is part of code patching :-) > i changed this accordingly. > ALTER TABLE .. ALTER COLUMN .. SET NOT NULL > will validate not-null and set attnotnull, attinvalidnotnull accordingly. Okay. > i basically model NOT NULL NOT VALID == CHECK (x IS NOT NULL). > i think your idea may need more refactoring? > all the "if (attr->attnotnull" need change to "if (attr->attnotnull && > attr->attnotnullvalid)" > or am i missing something? In some places, yes we will need to change like that. However, many places do not need to change like that. In particular, (most?) client applications do not necessarily need that change, and to me, that's the most important part, because we do not control external applications, and --as I said upthread-- we do not have the luxury of breaking them. > Anyway, I will just share my idea first, and will explore your idea later. Thank you. > in my attached patch, you will only create an not-null not valid > pg_constraint entry > If `if (constr->contype == CONSTR_NOTNULL && constr->skip_validation)` > in ATAddCheckNNConstraint conditions are satisfied. > > > imho, my approach is less bug-prone, almost no need to refactor current code. I'll give this a look ... probably won't have time today ... however, IMO the consideration of external applications (ORMs, LibreOffice, admin GUIs, etc) not breaking is the most important thing to keep in mind. You can go over the code found by codesearch.debian.net when searching for `attnotnull` to see the sort of code that would be affected. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "¿Qué importan los años? Lo que realmente importa es comprobar que a fin de cuentas la mejor edad de la vida es estar vivo" (Mafalda)
Commits
-
Allow NOT NULL constraints to be added as NOT VALID
- a379061a22a8 18.0 landed
-
Add missing deparsing of [NO] IDENT to XMLSERIALIZE()
- 984410b92326 18.0 cited
-
backend launchers void * arguments for binary data
- 7202d72787d3 18.0 cited
-
Add pg_constraint rows for not-null constraints
- 14e87ffa5c54 18.0 cited
-
Create the infrastructure for planner support functions.
- 1fb57af92069 12.0 cited
-
Add prokind column, replacing proisagg and proiswindow
- fd1a421fe661 11.0 cited