From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: NOT NULL NOT ENFORCED |
Date: | 2025-09-08 10:39:14 |
Message-ID: | CACJufxFQqA-BV58_nZViFX=WAQc4kn4SJk0gE7Te+kQFdNf9aQ@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Sep 4, 2025 at 8:00 PM Álvaro Herrera <alvherre(at)kurilemu(dot)de> wrote:
>
> > @@ -9937,9 +9962,9 @@ ATAddCheckNNConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
> > * If adding a valid not-null constraint, set the pg_attribute flag
> > * and tell phase 3 to verify existing rows, if needed. For an
> > * invalid constraint, just set attnotnull, without queueing
> > - * verification.
> > + * verification. For not enforced not-null, no need set attnotnull.
> > */
> > - if (constr->contype == CONSTR_NOTNULL)
> > + if (constr->contype == CONSTR_NOTNULL && ccon->is_enforced)
> > set_attnotnull(wqueue, rel, ccon->attnum,
> > !constr->skip_validation,
> > !constr->skip_validation);
>
> Didn't we decide that attnotnull meant whether a constraint exists at
> all, without making a judgement on whether it's enforced or valid? The
> important change should be in CheckNNConstraintFetch() which should
> determine attnullability in a way that allows executor know whether the
> column is nullable or not. I admit we might want to handle this
> differently for unenforced constraints, but we should discuss that and
> make sure that's what we want.
>
In CheckNNConstraintFetch, I changed it to
"""
if (conform->contype == CONSTRAINT_NOTNULL)
{
if (!conform->convalidated && conform->conenforced)
{
AttrNumber attnum;
attnum = extractNotNullColumn(htup);
Assert(relation->rd_att->compact_attrs[attnum -
1].attnullability ==
ATTNULLABLE_UNKNOWN);
relation->rd_att->compact_attrs[attnum - 1].attnullability =
ATTNULLABLE_INVALID;
}
continue;
}
"""
set pg_attribute.attnotnull to true for not-valid not-null is still
useful for INSERT/UPDATE.
set pg_attribute.attnotnull to true for not-enforced not-null
constraints doesn't have real benefits, IMHO.
If we let pg_attribute.attnotnull to true for not-enforced not-null,
then do we need to change the definition of
TupleConstr->has_not_null?
From | Date | Subject | |
---|---|---|---|
Next Message | Ilia Evdokimov | 2025-09-08 10:45:06 | Re: Use merge-based matching for MCVs in eqjoinsel |
Previous Message | Ilia Evdokimov | 2025-09-08 10:35:50 | Re: Use merge-based matching for MCVs in eqjoinsel |