| From: | Sami Imseih <samimseih(at)gmail(dot)com> |
|---|---|
| To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
| Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: question about is_valid parameter in set_attnotnull |
| Date: | 2026-07-29 18:55:22 |
| Message-ID: | CAA5RZ0sbMzrJgrkVfpp3Zxb3YqZgLfN4m9KbO_kWmcOpZZZNUA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Thanks for looking!
> > I was looking at code in tablecmds.c for some other patch and I
> > spotted that the is_valid parameter in set_attnotnull(), added in
> > a379061a22a8, is never used in the function body. It's not clear
> > why it was added, except that it's passed by the caller. The
> > CompactAttribute is unconditionally set to ATTNULLABLE_VALID:
> >
> > ```
> > thisatt = TupleDescCompactAttr(RelationGetDescr(rel), attnum - 1);
> > thisatt->attnullability = ATTNULLABLE_VALID;
> > ```
> >
> > The only caller that passes is_valid=false is ATAddCheckNNConstraint
> > (for NOT VALID constraints).
>
> Hmm, yeah -- as I recall, the intention there is that is_valid would be
> false when you want to create an invalid constraint. I suppose it was
> used that way during development but we later changed our minds about
> the design, made the parameter obsolete, and forgot to set it correctly
> or remove it. I would have to study the code to remember in more
> detail, but I suspect the right action now is to remove it.
At least I could not find any reason for it, but I may have missed something.
The function header comment and callers never mention is_valid either;
only attnotnull and queue_validation.
> Maybe we
> don't need thisatt at all and it should also be removed?
Right, both the is_valid and thisatt are dead code AFAICT.
Here is a patch that cleans it up.
--
Sami
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Remove-dead-code-in-set_attnotnull.patch | application/octet-stream | 3.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Antonin Houska | 2026-07-29 19:06:19 | Re: Tracking per-RelOptInfo uniqueness during planning |
| Previous Message | Bruce Momjian | 2026-07-29 18:21:04 | Re: DOCS QUESTION - space added within synopsis replaceable tag. |