From: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
---|---|
To: | jian he <jian(dot)universality(at)gmail(dot)com> |
Cc: | Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Support NOT VALID / VALIDATE constraint options for named NOT NULL constraints |
Date: | 2025-03-21 14:50:37 |
Message-ID: | 202503211450.4lps7qf3jutr@alvherre.pgsql |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
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)
From | Date | Subject | |
---|---|---|---|
Next Message | Andres Freund | 2025-03-21 15:16:58 | Re: Snapshot related assert failure on skink |
Previous Message | Robert Haas | 2025-03-21 14:45:47 | Re: Update Unicode data to Unicode 16.0.0 |