Page MenuHomePhabricator

Execute project membership materialization as "SELECT" + "INSERT", not "INSERT ... SELECT"
ClosedPublic

Authored by epriestley on Jan 27 2021, 11:20 PM.
Tags
None
Referenced Files
F18819250: D21527.id51245.diff
Oct 22 2025, 5:15 AM
F18785801: D21527.id.diff
Oct 14 2025, 11:53 AM
F18773410: D21527.id51242.diff
Oct 9 2025, 9:38 AM
F18761248: D21527.diff
Oct 6 2025, 1:13 PM
F18571497: D21527.id51245.diff
Sep 10 2025, 5:05 AM
F18571496: D21527.id51242.diff
Sep 10 2025, 5:04 AM
F18101328: D21527.id.diff
Aug 9 2025, 12:27 PM
F17756237: D21527.id51245.diff
Jul 22 2025, 1:52 PM
Subscribers
None

Details

Summary

Ref T13596. See that task for discussion. Executing "INSERT ... SELECT" at default isolation levels requires more locking than executing "SELECT" + "INSERT" separately.

Decompose this "INSERT ... SELECT" into "SELECT + INSERT", and reformat it to execute a minimal set of changes instead of wiping everything out and then writing all of it back. In most cases, this means we write 1 row instead of O(number of project members) rows.

Test Plan
  • Created a project. Added and removed members, looked at database and saw a consistent membership/materialization list.
  • Created a subproject. Added and removed members, looked at database and saw a consistent membership/materialization list.

I wasn't successful in reproducing the LOCK WAIT issue locally by trying various concurrent SELECT / INSERT / INSERT ... SELECT strategies. It may depend on the "DELETE + INSERT ... SELECT" structure used here, or versions/config/etc, so we'll have to see how that fares in production.

Diff Detail

Repository
rP Phabricator
Lint
Lint Not Applicable
Unit
Tests Not Applicable