- Notifications
You must be signed in to change notification settings - Fork5k
Commit11ff192
committed
Elide not-null constraint checks on child tables during PK creation
We were unnecessarily acquiring AccessExclusiveLock on all child tableswhen "ALTER TABLE ONLY sometab ADD PRIMARY KEY" was run on their parenttable, an oversight in commit14e87ff. This caused deadlocksduring pg_restore of partitioned tables.The reason to acquire the AEL was that we need to verify that childtables have the involved columns already marked as not-null; but if theparent table has an inheritable not-null constraint, then all childrenmust necessarily be in the correct state already, so we can skip thecheck, which avoids acquiring the lock. Reorder the code so that itworks that way. This doesn't change things in the case where theconstraint doesn't exist, but that case is of lesser importance becauseit doesn't occur during parallel pg_restore.While at it, reword some errmsg() and add errhint() to similar cases inrelated but not adjacent code.Diagnosed-by: Tom Lane <tgl@sss.pgh.pa.us>Reviewed-by: Tender Wang <tndrwang@gmail.com>Discussion:https://postgr.es/m/67469c1c-38bc-7d94-918a-67033f5dd731@gmx.netDiscussion:https://postgr.es/m/2045026.1743801143@sss.pgh.pa.usDiscussion:https://postgr.es/m/1280408.1744650810@sss.pgh.pa.us1 parent1fd3566 commit11ff192
File tree
5 files changed
+136
-65
lines changed- src
- backend
- catalog
- commands
- test/regress
- expected
- sql
5 files changed
+136
-65
lines changedLines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
756 | 756 |
| |
757 | 757 |
| |
758 | 758 |
| |
759 |
| - | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
760 | 762 |
| |
761 | 763 |
| |
762 | 764 |
| |
| |||
767 | 769 |
| |
768 | 770 |
| |
769 | 771 |
| |
770 |
| - | |
| 772 | + | |
| 773 | + | |
771 | 774 |
| |
772 | 775 |
| |
773 | 776 |
| |
|
Lines changed: 88 additions & 57 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
540 | 540 |
| |
541 | 541 |
| |
542 | 542 |
| |
| 543 | + | |
543 | 544 |
| |
544 | 545 |
| |
545 | 546 |
| |
| |||
9438 | 9439 |
| |
9439 | 9440 |
| |
9440 | 9441 |
| |
9441 |
| - | |
| 9442 | + | |
9442 | 9443 |
| |
| 9444 | + | |
| 9445 | + | |
| 9446 | + | |
| 9447 | + | |
| 9448 | + | |
| 9449 | + | |
| 9450 | + | |
| 9451 | + | |
| 9452 | + | |
| 9453 | + | |
| 9454 | + | |
| 9455 | + | |
| 9456 | + | |
| 9457 | + | |
| 9458 | + | |
| 9459 | + | |
| 9460 | + | |
| 9461 | + | |
9443 | 9462 |
| |
9444 | 9463 |
| |
9445 | 9464 |
| |
9446 | 9465 |
| |
9447 | 9466 |
| |
9448 | 9467 |
| |
9449 | 9468 |
| |
| 9469 | + | |
| 9470 | + | |
9450 | 9471 |
| |
9451 | 9472 |
| |
9452 | 9473 |
| |
9453 | 9474 |
| |
9454 | 9475 |
| |
9455 |
| - | |
9456 |
| - | |
9457 |
| - | |
9458 |
| - | |
9459 |
| - | |
9460 |
| - | |
9461 |
| - | |
9462 |
| - | |
9463 |
| - | |
9464 |
| - | |
9465 |
| - | |
9466 |
| - | |
9467 |
| - | |
9468 |
| - | |
9469 |
| - | |
9470 |
| - | |
9471 |
| - | |
9472 |
| - | |
9473 |
| - | |
9474 |
| - | |
9475 |
| - | |
9476 |
| - | |
9477 |
| - | |
9478 |
| - | |
9479 |
| - | |
9480 |
| - | |
9481 |
| - | |
9482 |
| - | |
9483 |
| - | |
9484 |
| - | |
9485 |
| - | |
9486 | 9476 |
| |
9487 | 9477 |
| |
9488 | 9478 |
| |
| |||
9498 | 9488 |
| |
9499 | 9489 |
| |
9500 | 9490 |
| |
9501 |
| - | |
9502 |
| - | |
9503 |
| - | |
9504 |
| - | |
9505 |
| - | |
9506 |
| - | |
9507 |
| - | |
9508 |
| - | |
9509 |
| - | |
9510 |
| - | |
9511 |
| - | |
9512 |
| - | |
9513 |
| - | |
9514 |
| - | |
9515 |
| - | |
9516 |
| - | |
9517 |
| - | |
9518 |
| - | |
9519 |
| - | |
9520 |
| - | |
9521 |
| - | |
9522 |
| - | |
9523 |
| - | |
9524 |
| - | |
9525 |
| - | |
| 9491 | + | |
9526 | 9492 |
| |
9527 | 9493 |
| |
9528 | 9494 |
| |
9529 | 9495 |
| |
9530 | 9496 |
| |
| 9497 | + | |
| 9498 | + | |
| 9499 | + | |
| 9500 | + | |
| 9501 | + | |
| 9502 | + | |
| 9503 | + | |
| 9504 | + | |
| 9505 | + | |
| 9506 | + | |
| 9507 | + | |
| 9508 | + | |
| 9509 | + | |
| 9510 | + | |
| 9511 | + | |
| 9512 | + | |
| 9513 | + | |
| 9514 | + | |
| 9515 | + | |
| 9516 | + | |
| 9517 | + | |
| 9518 | + | |
| 9519 | + | |
| 9520 | + | |
| 9521 | + | |
| 9522 | + | |
| 9523 | + | |
9531 | 9524 |
| |
9532 | 9525 |
| |
9533 | 9526 |
| |
9534 | 9527 |
| |
9535 | 9528 |
| |
9536 | 9529 |
| |
| 9530 | + | |
9537 | 9531 |
| |
9538 | 9532 |
| |
9539 | 9533 |
| |
9540 | 9534 |
| |
9541 | 9535 |
| |
9542 | 9536 |
| |
9543 | 9537 |
| |
| 9538 | + | |
| 9539 | + | |
| 9540 | + | |
| 9541 | + | |
| 9542 | + | |
| 9543 | + | |
| 9544 | + | |
| 9545 | + | |
| 9546 | + | |
| 9547 | + | |
| 9548 | + | |
| 9549 | + | |
| 9550 | + | |
| 9551 | + | |
| 9552 | + | |
| 9553 | + | |
| 9554 | + | |
| 9555 | + | |
| 9556 | + | |
| 9557 | + | |
| 9558 | + | |
| 9559 | + | |
| 9560 | + | |
| 9561 | + | |
| 9562 | + | |
| 9563 | + | |
| 9564 | + | |
| 9565 | + | |
| 9566 | + | |
| 9567 | + | |
| 9568 | + | |
| 9569 | + | |
| 9570 | + | |
| 9571 | + | |
| 9572 | + | |
| 9573 | + | |
| 9574 | + | |
9544 | 9575 |
| |
9545 | 9576 |
| |
9546 | 9577 |
| |
|
Lines changed: 26 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1042 | 1042 |
| |
1043 | 1043 |
| |
1044 | 1044 |
| |
| 1045 | + | |
1045 | 1046 |
| |
1046 | 1047 |
| |
1047 | 1048 |
| |
| |||
1233 | 1234 |
| |
1234 | 1235 |
| |
1235 | 1236 |
| |
1236 |
| - | |
1237 |
| - | |
| 1237 | + | |
| 1238 | + | |
1238 | 1239 |
| |
1239 | 1240 |
| |
1240 | 1241 |
| |
| |||
1389 | 1390 |
| |
1390 | 1391 |
| |
1391 | 1392 |
| |
| 1393 | + | |
1392 | 1394 |
| |
1393 | 1395 |
| |
1394 |
| - | |
| 1396 | + | |
1395 | 1397 |
| |
1396 | 1398 |
| |
1397 | 1399 |
| |
1398 |
| - | |
1399 |
| - | |
| 1400 | + | |
| 1401 | + | |
1400 | 1402 |
| |
1401 | 1403 |
| |
1402 | 1404 |
| |
| |||
1502 | 1504 |
| |
1503 | 1505 |
| |
1504 | 1506 |
| |
1505 |
| - | |
| 1507 | + | |
1506 | 1508 |
| |
1507 | 1509 |
| |
1508 | 1510 |
| |
| |||
1567 | 1569 |
| |
1568 | 1570 |
| |
1569 | 1571 |
| |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
1570 | 1590 |
| |
1571 | 1591 |
| |
1572 | 1592 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2286 | 2286 |
| |
2287 | 2287 |
| |
2288 | 2288 |
| |
| 2289 | + | |
2289 | 2290 |
| |
2290 | 2291 |
| |
2291 | 2292 |
| |
| |||
2509 | 2510 |
| |
2510 | 2511 |
| |
2511 | 2512 |
| |
| 2513 | + | |
2512 | 2514 |
| |
2513 | 2515 |
| |
2514 | 2516 |
| |
| |||
2520 | 2522 |
| |
2521 | 2523 |
| |
2522 | 2524 |
| |
| 2525 | + | |
2523 | 2526 |
| |
2524 | 2527 |
| |
2525 | 2528 |
| |
|
Lines changed: 14 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
940 | 940 |
| |
941 | 941 |
| |
942 | 942 |
| |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
943 | 957 |
| |
944 | 958 |
| |
945 | 959 |
| |
|
0 commit comments
Comments
(0)