@@ -126,7 +126,7 @@ static Oid findTypeSubscriptingFunction(List *procname, Oid typeOid);
126126static Oid findRangeSubOpclass (List * opcname , Oid subtype );
127127static Oid findRangeCanonicalFunction (List * procname , Oid typeOid );
128128static Oid findRangeSubtypeDiffFunction (List * procname , Oid subtype );
129- static void validateDomainCheckConstraint (Oid domainoid , const char * ccbin );
129+ static void validateDomainCheckConstraint (Oid domainoid , const char * ccbin , LOCKMODE lockmode );
130130static void validateDomainNotNullConstraint (Oid domainoid );
131131static List * get_rels_with_domain (Oid domainOid , LOCKMODE lockmode );
132132static void checkEnumOwner (HeapTuple tup );
@@ -2986,7 +2986,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint,
29862986 * to.
29872987 */
29882988 if (!constr -> skip_validation )
2989- validateDomainCheckConstraint (domainoid , ccbin );
2989+ validateDomainCheckConstraint (domainoid , ccbin , ShareLock );
29902990
29912991 /*
29922992 * We must send out an sinval message for the domain, to ensure that
@@ -3098,7 +3098,12 @@ AlterDomainValidateConstraint(List *names, const char *constrName)
30983098 val = SysCacheGetAttrNotNull (CONSTROID , tuple , Anum_pg_constraint_conbin );
30993099 conbin = TextDatumGetCString (val );
31003100
3101- validateDomainCheckConstraint (domainoid , conbin );
3101+ /*
3102+ * lock related relations with ShareUpdateExclusiveLock is ok, since not
3103+ * valid constraints will still be enforced against subsequent inserts or
3104+ * updates.
3105+ */
3106+ validateDomainCheckConstraint (domainoid , conbin , ShareUpdateExclusiveLock );
31023107
31033108 /*
31043109 * Now update the catalog, while we have the door open.
@@ -3191,9 +3196,14 @@ validateDomainNotNullConstraint(Oid domainoid)
31913196/*
31923197 * Verify that all columns currently using the domain satisfy the given check
31933198 * constraint expression.
3199+ *
3200+ * It is used to validate existing constraints and to add newly created check
3201+ * constraints to a domain.
3202+ * The lockmode is ShareLock when add a new constraint to domain, it can be
3203+ * ShareUpdateExclusiveLock when validating existing constraint.
31943204 */
31953205static void
3196- validateDomainCheckConstraint (Oid domainoid , const char * ccbin )
3206+ validateDomainCheckConstraint (Oid domainoid , const char * ccbin , LOCKMODE lockmode )
31973207{
31983208 Expr * expr = (Expr * ) stringToNode (ccbin );
31993209 List * rels ;
@@ -3210,9 +3220,7 @@ validateDomainCheckConstraint(Oid domainoid, const char *ccbin)
32103220 exprstate = ExecPrepareExpr (expr , estate );
32113221
32123222 /* Fetch relation list with attributes based on this domain */
3213- /* ShareLock is sufficient to prevent concurrent data changes */
3214-
3215- rels = get_rels_with_domain (domainoid , ShareLock );
3223+ rels = get_rels_with_domain (domainoid , lockmode );
32163224
32173225 foreach (rt , rels )
32183226 {
0 commit comments