Skip to content

Commit ecaaa07

Browse files
author
Commitfest Bot
committed
[CF 5752] v1 - make VALIDATE domain constraint lock on related relations as ShareUpdateExclusiveLock
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5752 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CACJufxHz92A88NLRTA2msgE2dpXpE-EoZ2QO61od76-6bfqurA@mail.gmail.com Author(s): Jian He
2 parents 9ea3b6f + 5f6f8d2 commit ecaaa07

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/backend/commands/typecmds.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static Oid findTypeSubscriptingFunction(List *procname, Oid typeOid);
126126
static Oid findRangeSubOpclass(List *opcname, Oid subtype);
127127
static Oid findRangeCanonicalFunction(List *procname, Oid typeOid);
128128
static 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);
130130
static void validateDomainNotNullConstraint(Oid domainoid);
131131
static List *get_rels_with_domain(Oid domainOid, LOCKMODE lockmode);
132132
static 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
*/
31953205
static 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

Comments
 (0)