- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit0ac5ad5
committed
Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FORKEY SHARE" and "SELECT FOR NO KEY UPDATE". These don't block eachother, in contrast with already existing "SELECT FOR SHARE" and "SELECTFOR UPDATE". UPDATE commands that do not modify the values stored inthe columns that are part of the key of the tuple now grab a SELECT FORNO KEY UPDATE lock on the tuple, allowing them to proceed concurrentlywith tuple locks of the FOR KEY SHARE variety.Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; thismeans the concurrency improvement applies to them, which is the wholepoint of this patch.The added tuple lock semantics require some rejiggering of the multixactmodule, so that the locking level that each transaction is holding canbe stored alongside its Xid. Also, multixacts now need to persistacross server restarts and crashes, because they can now represent notonly tuple locks, but also tuple updates. This means we need morecareful tracking of lifetime of pg_multixact SLRU files; since they nowpersist longer, we require more infrastructure to figure out when theycan be removed. pg_upgrade also needs to be careful to copypg_multixact files over from the old server to the new, or at least partof multixact.c state, depending on the versions of the old and newservers.Tuple time qualification rules (HeapTupleSatisfies routines) need to becareful not to consider tuples with the "is multi" infomask bit set asbeing only locked; they might need to look up MultiXact values (i.e.possibly do pg_multixact I/O) to find out the Xid that updated a tuple,whereas they previously were assured to only use information readilyavailable from the tuple header. This is considered acceptable, becausethe extra I/O would involve cases that would previously cause somecommands to block waiting for concurrent transactions to finish.Another important change is the fact that locking tuples that havepreviously been updated causes the future versions to be marked aslocked, too; this is essential for correctness of foreign key checks.This causes additional WAL-logging, also (there was previously a singleWAL record for a locked tuple; now there are as many as updated copiesof the tuple there exist.)With all this in place, contention related to tuples being checked byforeign key rules should be much reduced.As a bonus, the old behavior that a subtransaction grabbing a strongertuple lock than the parent (sub)transaction held on a given tuple andlater aborting caused the weaker lock to be lost, has been fixed.Many new spec files were added for isolation tester framework, to ensureoverall behavior is sane. There's probably room for several more tests.There were several reviewers of this patch; in particular, Noah Mischand Andres Freund spent considerable time in it. Original idea for thepatch came from Simon Riggs, after a problem report by Joel Jacobson.Most code is from me, with contributions from Marti Raudsepp, AlexanderShulgin, Noah Misch and Andres Freund.This patch was discussed in several pgsql-hackers threads; the mostimportant start at the following message-ids:AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com1290721684-sup-3951@alvh.no-ip.org1294953201-sup-2099@alvh.no-ip.org1320343602-sup-2290@alvh.no-ip.org1339690386-sup-8927@alvh.no-ip.org4FE5FF020200002500048A3D@gw.wicourts.gov4FEAB90A0200002500048B7D@gw.wicourts.gov1 parentf925c79 commit0ac5ad5
File tree
106 files changed
+6023
-1487
lines changed- contrib
- file_fdw/output
- pageinspect
- pg_upgrade
- pgrowlocks
- doc/src/sgml
- ref
- src
- backend
- access
- common
- heap
- rmgrdesc
- transam
- catalog
- commands
- executor
- nodes
- optimizer/plan
- parser
- postmaster
- rewrite
- storage/lmgr
- tcop
- utils
- adt
- cache
- time
- bin
- pg_controldata
- pg_resetxlog
- include
- access
- catalog
- commands
- executor
- nodes
- parser
- storage
- utils
- test/isolation
- expected
- specs
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
106 files changed
+6023
-1487
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
191 | 191 |
| |
192 | 192 |
| |
193 | 193 |
| |
194 |
| - | |
| 194 | + | |
195 | 195 |
| |
196 | 196 |
| |
197 | 197 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
163 | 163 |
| |
164 | 164 |
| |
165 | 165 |
| |
166 |
| - | |
| 166 | + | |
167 | 167 |
| |
168 | 168 |
| |
169 | 169 |
| |
|
Lines changed: 46 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
40 | 40 |
| |
41 | 41 |
| |
42 | 42 |
| |
| 43 | + | |
| 44 | + | |
| 45 | + | |
43 | 46 |
| |
44 | 47 |
| |
45 | 48 |
| |
| |||
246 | 249 |
| |
247 | 250 |
| |
248 | 251 |
| |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
249 | 285 |
| |
250 | 286 |
| |
251 | 287 |
| |
| |||
433 | 469 |
| |
434 | 470 |
| |
435 | 471 |
| |
| 472 | + | |
436 | 473 |
| |
437 | 474 |
| |
438 | 475 |
| |
| |||
448 | 485 |
| |
449 | 486 |
| |
450 | 487 |
| |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
451 | 497 |
| |
452 | 498 |
| |
453 | 499 |
| |
|
Lines changed: 46 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
382 | 382 |
| |
383 | 383 |
| |
384 | 384 |
| |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
385 | 431 |
| |
386 | 432 |
| |
387 | 433 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
108 | 108 |
| |
109 | 109 |
| |
110 | 110 |
| |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
111 | 115 |
| |
112 | 116 |
| |
113 | 117 |
| |
| |||
182 | 186 |
| |
183 | 187 |
| |
184 | 188 |
| |
| 189 | + | |
| 190 | + | |
| 191 | + | |
185 | 192 |
| |
186 | 193 |
| |
187 | 194 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4 | 4 |
| |
5 | 5 |
| |
6 | 6 |
| |
7 |
| - | |
| 7 | + | |
8 | 8 |
| |
9 | 9 |
| |
10 | 10 |
| |
|
Lines changed: 17 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + |
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 |
| - | |
| 1 | + | |
2 | 2 |
| |
3 | 3 |
| |
4 | 4 |
| |
5 | 5 |
| |
6 | 6 |
| |
7 | 7 |
| |
8 |
| - | |
9 | 8 |
| |
10 | 9 |
| |
11 | 10 |
| |
| 11 | + | |
12 | 12 |
| |
13 | 13 |
| |
14 | 14 |
| |
|
0 commit comments
Comments
(0)