Re: not null constraints, again

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Tender Wang <tndrwang(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: not null constraints, again
Date: 2024-10-01 20:12:45
Message-ID: 202410012012.tp3lf6ytz4f5@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2024-Oct-01, jian he wrote:

> ATExecDropInherit
> /*
> * If the parent has a primary key, then we decrement counts for all NOT
> * NULL constraints
> */
> ObjectAddressSet(address, RelationRelationId,
> RelationGetRelid(parent_rel));
>
> only not-null constraint,
> with ALTER TABLE NO INHERIT we still decrement counts for not-null constraints.
> I feel the comment is in the wrong place?

Yeah, I think it's uselessly left over after removing some code that was
there. I dropped it.

> please check the attached function MergeConstraintsIntoExisting refactoring
> 1. make it error check more confined within CONSTRAINT_CHECK and
> CONSTRAINT_NOTNULL.

I had already rewritten this, as I mentioned in an earlier response; I
just made the error check apply regardless of constraint type. Note
that in your patch, you left a useless comment in place.

> 2. since get_attname will do system cache search, we can just use
> Relation->rd_att and TupleDescAttr

Hmm, you're right, but I think we can do even better than that: we
should use an AttrMap to map the column numbers from parent to child
without having the compare column names. This should be much faster.

I also re-verified pg_upgrade from earlier releases (I tried 15 and 17).
There was a problem whereby we'd bogusly end up with some constraints
having islocal=true, because the UPDATE pg_constraint that tries to flip
it false doesn't have a constraint name to reference. I made it use
'conkey' in the WHERE for that case; with that, the tests pass.

I pushed this branch to my github clone [1] here, and Cirrus is running
it here [2].
[1] https://github.com/alvherre/postgres/commits/notnull-init-18/
[2] https://cirrus-ci.com/build/6343292823011328

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Nunca confiaré en un traidor. Ni siquiera si el traidor lo he creado yo"
(Barón Vladimir Harkonnen)

Attachment Content-Type Size
v7-0001-Catalog-not-null-constraints.patch text/x-diff 314.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2024-10-01 20:15:08 Re: Converting README documentation to Markdown
Previous Message Masahiko Sawada 2024-10-01 19:58:03 Re: Using per-transaction memory contexts for storing decoded tuples