From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
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-03 07:16:43 |
Message-ID: | CACJufxH1=dBitf9BWTh1hY76Lse7bad8wVX_qcL5+yCaD2ppOQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
I thought SearchSysCacheCopyAttNum is expensive.
Relation->rd_att is enough for checking attnotnull.
What do you think of the following refactoring of set_attnotnull?
static void
set_attnotnull(List **wqueue, Relation rel, AttrNumber attnum,
LOCKMODE lockmode)
{
Oid reloid = RelationGetRelid(rel);
HeapTuple tuple;
Form_pg_attribute attForm;
Form_pg_attribute attr;
TupleDesc tupleDesc;
CheckAlterTableIsSafe(rel);
tupleDesc = RelationGetDescr(rel);
attr = TupleDescAttr(tupleDesc, attnum - 1);
if (attr->attisdropped)
return;
if (!attr->attnotnull)
{
Relation attr_rel;
attr_rel = table_open(AttributeRelationId, RowExclusiveLock);
tuple = SearchSysCacheCopyAttNum(reloid, attnum);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
attnum, reloid);
attForm = (Form_pg_attribute) GETSTRUCT(tuple);
attForm->attnotnull = true;
CatalogTupleUpdate(attr_rel, &tuple->t_self, tuple);
if (wqueue && !NotNullImpliedByRelConstraints(rel, attForm))
{
AlteredTableInfo *tab;
tab = ATGetQueueEntry(wqueue, rel);
tab->verify_new_notnull = true;
}
CommandCounterIncrement();
heap_freetuple(tuple);
table_close(attr_rel, RowExclusiveLock);
}
}
From | Date | Subject | |
---|---|---|---|
Next Message | jian he | 2024-10-03 07:27:19 | Re: Add new COPY option REJECT_LIMIT |
Previous Message | Michael Paquier | 2024-10-03 07:14:58 | Re: Add parallel columns for pg_stat_statements |