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-04 13:08:15
Message-ID: 202410041308.umwqeozh2zir@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2024-Oct-03, jian he wrote:

> I thought SearchSysCacheCopyAttNum is expensive.
> Relation->rd_att is enough for checking attnotnull.
>
> What do you think of the following refactoring of set_attnotnull?

Eh, sure, why not. I mean, I expect that this is going to be barely
noticeable performance-wise, but I don't see a reason not to do it this
way.

The new code in transformIndexConstraint() I added to verify NO INHERIT
for columns in the PK[1] is likely to have a more noticeable impact: we
have to scan the whole cxt->nnconstraints list for each column of the
PK, and strcmp() the column names in order to find matches. I expect
this this to be slow (and affect everybody) but I don't see any other
reasonable way to do it. A possibility is to add a Constraint member to
ColumnDef, and pre-process so that we attach the correct constraint
definition to each column definition before invoking
transformIndexConstraints in transformCreateStmt; we already do the
match there, so it would be a good place for that. Alternatively, turn
is_not_null into a tristate (yes, no, "yes but is no inherit").

[1] https://github.com/alvherre/postgres/commit/22e5820e241c744fb36cbc643a4d8d94162c562e

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"The problem with the facetime model is not just that it's demoralizing, but
that the people pretending to work interrupt the ones actually working."
-- Paul Graham, http://www.paulgraham.com/opensource.html

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2024-10-04 13:11:44 Re: not null constraints, again
Previous Message jian he 2024-10-04 12:33:07 Re: SQL:2023 JSON simplified accessor support