Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f0e3675

Browse files
jianhe-funCommitfest Bot
authored and
Commitfest Bot
committed
make ALTER DOMAIN VALIDATE CONSTRAINT no-op when constraint is validated
Looking at AlterDomainValidateConstraint, it seems currently, ALTER DOMAIN VALIDATE CONSTRAINT will re-validate a constraint that has already been validated, which would just waste cycles. Ideally, this operation should be a no-op when the constraint is already validated.
1 parent 03c53a7 commit f0e3675

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/backend/commands/typecmds.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,24 +3087,29 @@ AlterDomainValidateConstraint(List *names, const char *constrName)
30873087
errmsg("constraint \"%s\" of domain \"%s\" is not a check constraint",
30883088
constrName, TypeNameToString(typename))));
30893089

3090-
val = SysCacheGetAttrNotNull(CONSTROID, tuple, Anum_pg_constraint_conbin);
3091-
conbin = TextDatumGetCString(val);
3090+
if (!con->convalidated)
3091+
{
3092+
val = SysCacheGetAttrNotNull(CONSTROID, tuple, Anum_pg_constraint_conbin);
3093+
conbin = TextDatumGetCString(val);
30923094

3093-
validateDomainCheckConstraint(domainoid, conbin);
3095+
validateDomainCheckConstraint(domainoid, conbin);
30943096

3095-
/*
3096-
* Now update the catalog, while we have the door open.
3097-
*/
3098-
copyTuple = heap_copytuple(tuple);
3099-
copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
3100-
copy_con->convalidated = true;
3101-
CatalogTupleUpdate(conrel, &copyTuple->t_self, copyTuple);
3097+
/*
3098+
* Now update the catalog, while we have the door open.
3099+
*/
3100+
copyTuple = heap_copytuple(tuple);
3101+
copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
3102+
copy_con->convalidated = true;
3103+
CatalogTupleUpdate(conrel, &copyTuple->t_self, copyTuple);
31023104

3103-
InvokeObjectPostAlterHook(ConstraintRelationId, con->oid, 0);
3105+
InvokeObjectPostAlterHook(ConstraintRelationId, con->oid, 0);
31043106

3105-
ObjectAddressSet(address, TypeRelationId, domainoid);
3107+
ObjectAddressSet(address, TypeRelationId, domainoid);
31063108

3107-
heap_freetuple(copyTuple);
3109+
heap_freetuple(copyTuple);
3110+
}
3111+
else
3112+
address = InvalidObjectAddress; /* already validated */
31083113

31093114
systable_endscan(scan);
31103115

0 commit comments

Comments
 (0)