Re: Fix ALTER DOMAIN VALIDATE CONSTRAINT locking
Re: Fix ALTER DOMAIN VALIDATE CONSTRAINT locking
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Mon, Jun 8, 2026 at 12:54 PM Chao Li wrote:
> See the attached patch for details. I also added an isolation test that follows the repro above.
Thanks for the patch! It looks good to me.
I just have a few minor review comments.
* The lockmode is used for relations using the domain. It should be
* ShareLock when adding a new constraint to domain. It can be
* ShareUpdateExclusiveLock when validating an existing constraint.
This comment in validateDomainCheckConstraint() still references
ShareUpdateExclusiveLock, so it seems to need updating.
Regarding the test, I think it would be safer to also check whether
pg_constraint.convalidated is set correctly. For example:
-----------------------
step s3_validate { ALTER DOMAIN alter_domain_validate_d VALIDATE
CONSTRAINT alter_domain_validate_d_pos; }
+step s3_validated { SELECT convalidated FROM pg_constraint WHERE
conname = 'alter_domain_validate_d_pos'; }
step s3_check { SELECT count(*) FROM alter_domain_validate_t; }
-permutation s1_lock s2_insert s3_add s3_validate s1_unlock s3_check
+permutation s1_lock s2_insert s3_add s3_validate s1_unlock s3_validated s3_chec
-----------------------
After the fix is committed, we should probably also ask Bruce to update
the following v19 release note item?:
Reduce lock level of ALTER DOMAIN ... VALIDATE CONSTRAINT to match
ALTER TABLE ... VALIDATE CONSTRAINT (Jian He) §
Regards,
--
Fujii Masao
Re: Fix ALTER DOMAIN VALIDATE CONSTRAINT locking
> On Jun 12, 2026, at 19:47, Fujii Masao wrote:
>
> On Mon, Jun 8, 2026 at 12:54 PM Chao Li wrote:
>> See the attached patch for details. I also added an isolation test that follows the repro above.
>
> Thanks for the patch! It looks good to me.
>
> I just have a few minor review comments.
>
>
> * The lockmode is used for relations using the domain. It should be
> * ShareLock when adding a new constraint to domain. It can be
> * ShareUpdateExclusiveLock when validating an existing constraint.
>
> This comment in validateDomainCheckConstraint() still references
> ShareUpdateExclusiveLock, so it seems to need updating.
>
>
> Regarding the test, I think it would be safer to also check whether
> pg_constraint.convalidated is set correctly. For example:
>
> -----------------------
> step s3_validate { ALTER DOMAIN alter_domain_validate_d VALIDATE
> CONSTRAINT alter_domain_validate_d_pos; }
> +step s3_validated { SELECT convalidated FROM pg_constraint WHERE
> conname = 'alter_domain_validate_d_pos'; }
> step s3_check { SELECT count(*) FROM alter_domain_validate_t; }
>
> -permutation s1_lock s2_insert s3_add s3_validate s1_unlock s3_check
> +permutation s1_lock s2_insert s3_add s3_validate s1_unlock s3_validated s3_chec
> -----------------------
>
>
> After the fix is committed, we should probably also ask Bruce to update
> the following v19 release note item?:
>
> Reduce lock level of ALTER DOMAIN ... VALIDATE CONSTRAINT to match
> ALTER TABLE ... VALIDATE CONSTRAINT (Jian He) §
>
> Regards,
>
> --
> Fujii Masao
Hi Fujii-san,
Thanks for picking this up. PFA v2 that addressed your comments.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Re: Fix ALTER DOMAIN VALIDATE CONSTRAINT locking
От:
Álvaro Herrera <alvherre@kurilemu.de>
Дата:
Hello, On 2026-Jun-12, Fujii Masao wrote: > I just have a few minor review comments. > > * The lockmode is used for relations using the domain. It should be > * ShareLock when adding a new constraint to domain. It can be > * ShareUpdateExclusiveLock when validating an existing constraint. > > This comment in validateDomainCheckConstraint() still references > ShareUpdateExclusiveLock, so it seems to need updating. I may be missing something, but doesn't changing the ShareUpdateExclusive lock to ShareLock means essentially reverting 16a0039dc0d1? I mean, the code was previously using ShareLock for both uses of validateDomainCheckConstraint(); and what that commit did was change AlterDomainValidateConstraint() to use ShareUpdateExclusiveLock, while AlterDomainAddConstraint() retained the stronger ShareLock level. If we now change AlterDomainValidateConstraint() back to ShareLock, then the aforementioned commit has no effect whatsoever. > After the fix is committed, we should probably also ask Bruce to update > the following v19 release note item?: > > Reduce lock level of ALTER DOMAIN ... VALIDATE CONSTRAINT to match > ALTER TABLE ... VALIDATE CONSTRAINT (Jian He) § If we make this change, then the release note item should be removed entirely, ISTM. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "Hay quien adquiere la mala costumbre de ser infeliz" (M. A. Evans)
Re: Fix ALTER DOMAIN VALIDATE CONSTRAINT locking
От:
Chao Li <li.evan.chao@gmail.com>
Дата:
> On Jun 12, 2026, at 21:02, Álvaro Herrera wrote: > > Hello, > > On 2026-Jun-12, Fujii Masao wrote: > >> I just have a few minor review comments. >> >> * The lockmode is used for relations using the domain. It should be >> * ShareLock when adding a new constraint to domain. It can be >> * ShareUpdateExclusiveLock when validating an existing constraint. >> >> This comment in validateDomainCheckConstraint() still references >> ShareUpdateExclusiveLock, so it seems to need updating. > > I may be missing something, but doesn't changing the > ShareUpdateExclusive lock to ShareLock means essentially reverting > 16a0039dc0d1? I mean, the code was previously using ShareLock for both > uses of validateDomainCheckConstraint(); and what that commit did was > change AlterDomainValidateConstraint() to use ShareUpdateExclusiveLock, > while AlterDomainAddConstraint() retained the stronger ShareLock level. > If we now change AlterDomainValidateConstraint() back to ShareLock, then > the aforementioned commit has no effect whatsoever. From a runtime behavior perspective, yes, this patch reverts the behavior change made by 16a0039dc0d1. However: * 16a0039dc0d1 also refactored validateDomainCheckConstraint() to allow passing in the lock mode, and I think that refactoring is still useful and maybe worth keeping. * A follow-up commit, a99c6b56f, made validating an already-validated constraint a no-op. A direct revert of 16a0039dc0d1 would conflict with later changes around this code. * This patch also adds a test to prevent future changes from making the same mistake. > >> After the fix is committed, we should probably also ask Bruce to update >> the following v19 release note item?: >> >> Reduce lock level of ALTER DOMAIN ... VALIDATE CONSTRAINT to match >> ALTER TABLE ... VALIDATE CONSTRAINT (Jian He) § > > If we make this change, then the release note item should be removed > entirely, ISTM. > True. Once this patch is pushed, this item should be removed from the release note. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/
Re: Fix ALTER DOMAIN VALIDATE CONSTRAINT locking
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Fri, Jun 12, 2026 at 11:02 PM Chao Li wrote: > From a runtime behavior perspective, yes, this patch reverts the behavior change made by 16a0039dc0d1. Yes. > However: > > * 16a0039dc0d1 also refactored validateDomainCheckConstraint() to allow passing in the lock mode, and I think that refactoring is still useful and maybe worth keeping. I'd prefer to remove that refactoring code, since after the fix there is no longer any user of the lockmode argument in validateDomainCheckConstraint(). > * A follow-up commit, a99c6b56f, made validating an already-validated constraint a no-op. A direct revert of 16a0039dc0d1 would conflict with later changes around this code. Yes, but fixing that conflict does not seem very difficult, no? > * This patch also adds a test to prevent future changes from making the same mistake. +1 for adding the test! > > If we make this change, then the release note item should be removed > > entirely, ISTM. > > > > True. Once this patch is pushed, this item should be removed from the release note. Agreed. Regards, -- Fujii Masao
Re: Fix ALTER DOMAIN VALIDATE CONSTRAINT locking
> On Jun 14, 2026, at 23:52, Fujii Masao wrote: > > On Fri, Jun 12, 2026 at 11:02 PM Chao Li wrote: >> From a runtime behavior perspective, yes, this patch reverts the behavior change made by 16a0039dc0d1. > > Yes. > > >> However: >> >> * 16a0039dc0d1 also refactored validateDomainCheckConstraint() to allow passing in the lock mode, and I think that refactoring is still useful and maybe worth keeping. > > I'd prefer to remove that refactoring code, since after the fix there > is no longer any user of the lockmode argument in > validateDomainCheckConstraint(). > > >> * A follow-up commit, a99c6b56f, made validating an already-validated constraint a no-op. A direct revert of 16a0039dc0d1 would conflict with later changes around this code. > > Yes, but fixing that conflict does not seem very difficult, no? > > >> * This patch also adds a test to prevent future changes from making the same mistake. > > +1 for adding the test! > > >>> If we make this change, then the release note item should be removed >>> entirely, ISTM. >>> >> >> True. Once this patch is pushed, this item should be removed from the release note. > > Agreed. > > Regards, > > -- > Fujii Masao Okay, I manually reverted 16a0039dc0d1 with retaining a99c6b56f. I also updated the commit message accordingly. See the attached v3. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/