Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16a0039

Browse files
committed
Reduce lock level for ALTER DOMAIN ... VALIDATE CONSTRAINT
Reduce from ShareLock to ShareUpdateExclusivelock. Validation duringALTER DOMAIN ... ADD CONSTRAINT keeps using ShareLock.Example: create domain d1 as int; create table t (a d1); alter domain d1 add constraint cc10 check (value > 10) not valid; begin; alter domain d1 validate constraint cc10; -- another session insert into t values (8);Now we should still be able to perform DML operations on table t whilethe domain constraint is being validated. The equivalent worksalready on table constraints.Author: jian he <jian.universality@gmail.com>Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/CACJufxHz92A88NLRTA2msgE2dpXpE-EoZ2QO61od76-6bfqurA%40mail.gmail.com
1 parent123e65f commit16a0039

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

‎src/backend/commands/typecmds.c‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static OidfindTypeSubscriptingFunction(List *procname, Oid typeOid);
126126
staticOidfindRangeSubOpclass(List*opcname,Oidsubtype);
127127
staticOidfindRangeCanonicalFunction(List*procname,OidtypeOid);
128128
staticOidfindRangeSubtypeDiffFunction(List*procname,Oidsubtype);
129-
staticvoidvalidateDomainCheckConstraint(Oiddomainoid,constchar*ccbin);
129+
staticvoidvalidateDomainCheckConstraint(Oiddomainoid,constchar*ccbin,LOCKMODElockmode);
130130
staticvoidvalidateDomainNotNullConstraint(Oiddomainoid);
131131
staticList*get_rels_with_domain(OiddomainOid,LOCKMODElockmode);
132132
staticvoidcheckEnumOwner(HeapTupletup);
@@ -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+
* Locking related relations with ShareUpdateExclusiveLock is ok because
3103+
* not-yet-valid constraints are still enforced against concurrent inserts
3104+
* or updates.
3105+
*/
3106+
validateDomainCheckConstraint(domainoid,conbin,ShareUpdateExclusiveLock);
31023107

31033108
/*
31043109
* Now update the catalog, while we have the door open.
@@ -3191,9 +3196,16 @@ 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+
*
3203+
* The lockmode is used for relations using the domain. It should be
3204+
* ShareLock when adding a new constraint to domain. It can be
3205+
* ShareUpdateExclusiveLock when validating an existing constraint.
31943206
*/
31953207
staticvoid
3196-
validateDomainCheckConstraint(Oiddomainoid,constchar*ccbin)
3208+
validateDomainCheckConstraint(Oiddomainoid,constchar*ccbin,LOCKMODElockmode)
31973209
{
31983210
Expr*expr= (Expr*)stringToNode(ccbin);
31993211
List*rels;
@@ -3210,9 +3222,7 @@ validateDomainCheckConstraint(Oid domainoid, const char *ccbin)
32103222
exprstate=ExecPrepareExpr(expr,estate);
32113223

32123224
/* 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);
3225+
rels=get_rels_with_domain(domainoid,lockmode);
32163226

32173227
foreach(rt,rels)
32183228
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp