forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit9c703c1
committed
Make queries' locking of indexes more consistent.
The assertions added by commitb04aeb0 exposed that there are somecode paths wherein the executor will try to open an index withoutholding any lock on it. We do have some lock on the index's table,so it seems likely that there's no fatal problem with this (forinstance, the index couldn't get dropped from under us). Still,it's bad practice and we should fix it.To do so, remove the optimizations in ExecInitIndexScan and friendsthat tried to avoid taking a lock on an index belonging to a targetrelation, and just take the lock always. In non-bug cases, thiswill result in no additional shared-memory access, since we'll findin the local lock table that we already have a lock of the desiredtype; hence, no significant performance degradation should occur.Also, adjust the planner and executor so that the type of lock takenon an index is always identical to the type of lock taken for its table,by relying on the recently added RangeTblEntry.rellockmode field.This avoids some corner cases where that might not have been truebefore (possibly resulting in extra locking overhead), and preventsfuture maintenance issues from having multiple bits of logic thatall needed to be in sync. In addition, this change removes all corecalls to ExecRelationIsTargetRelation, which avoids a possible O(N^2)startup penalty for queries with large numbers of target relations.(We'd probably remove that function altogether, were it not that weadvertise it as something that FDWs might want to use.)Also adjust some places in selfuncs.c to not take any lock on indexesthey are transiently opening, since we can assume that plancat.cdid that already.In passing, change gin_clean_pending_list() to take RowExclusiveLocknot AccessShareLock on its target index. Although it's not clear thatthat's actually a bug, it seemed very strange for a function that'sexplicitly going to modify the index to use only AccessShareLock.David Rowley, reviewed by Julien Rouhaud and Amit Langote,a bit of further tweaking by meDiscussion:https://postgr.es/m/19465.1541636036@sss.pgh.pa.us1 parenta96c41f commit9c703c1
File tree
8 files changed
+39
-59
lines changed- src/backend
- access/gin
- executor
- optimizer
- plan
- util
- utils/adt
8 files changed
+39
-59
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1031 | 1031 |
| |
1032 | 1032 |
| |
1033 | 1033 |
| |
1034 |
| - | |
| 1034 | + | |
1035 | 1035 |
| |
1036 | 1036 |
| |
1037 | 1037 |
| |
| |||
1068 | 1068 |
| |
1069 | 1069 |
| |
1070 | 1070 |
| |
1071 |
| - | |
| 1071 | + | |
1072 | 1072 |
| |
1073 | 1073 |
| |
1074 | 1074 |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
664 | 664 |
| |
665 | 665 |
| |
666 | 666 |
| |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
667 | 671 |
| |
668 | 672 |
| |
669 | 673 |
| |
|
Lines changed: 4 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
211 | 211 |
| |
212 | 212 |
| |
213 | 213 |
| |
214 |
| - | |
| 214 | + | |
215 | 215 |
| |
216 | 216 |
| |
217 | 217 |
| |
| |||
260 | 260 |
| |
261 | 261 |
| |
262 | 262 |
| |
263 |
| - | |
264 |
| - | |
265 |
| - | |
266 |
| - | |
267 |
| - | |
268 |
| - | |
269 |
| - | |
270 |
| - | |
271 |
| - | |
272 |
| - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
273 | 266 |
| |
274 | 267 |
| |
275 | 268 |
| |
|
Lines changed: 4 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
493 | 493 |
| |
494 | 494 |
| |
495 | 495 |
| |
496 |
| - | |
| 496 | + | |
497 | 497 |
| |
498 | 498 |
| |
499 | 499 |
| |
| |||
556 | 556 |
| |
557 | 557 |
| |
558 | 558 |
| |
559 |
| - | |
560 |
| - | |
561 |
| - | |
562 |
| - | |
563 |
| - | |
564 |
| - | |
565 |
| - | |
566 |
| - | |
567 |
| - | |
568 |
| - | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
569 | 562 |
| |
570 | 563 |
| |
571 | 564 |
| |
|
Lines changed: 4 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
901 | 901 |
| |
902 | 902 |
| |
903 | 903 |
| |
904 |
| - | |
| 904 | + | |
905 | 905 |
| |
906 | 906 |
| |
907 | 907 |
| |
| |||
964 | 964 |
| |
965 | 965 |
| |
966 | 966 |
| |
967 |
| - | |
968 |
| - | |
969 |
| - | |
970 |
| - | |
971 |
| - | |
972 |
| - | |
973 |
| - | |
974 |
| - | |
975 |
| - | |
976 |
| - | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
977 | 970 |
| |
978 | 971 |
| |
979 | 972 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6285 | 6285 |
| |
6286 | 6286 |
| |
6287 | 6287 |
| |
| 6288 | + | |
6288 | 6289 |
| |
6289 | 6290 |
| |
6290 | 6291 |
| |
|
Lines changed: 10 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
162 | 162 |
| |
163 | 163 |
| |
164 | 164 |
| |
165 |
| - | |
166 | 165 |
| |
| 166 | + | |
167 | 167 |
| |
168 | 168 |
| |
169 | 169 |
| |
| |||
172 | 172 |
| |
173 | 173 |
| |
174 | 174 |
| |
175 |
| - | |
176 |
| - | |
| 175 | + | |
| 176 | + | |
177 | 177 |
| |
178 |
| - | |
179 |
| - | |
180 |
| - | |
181 |
| - | |
| 178 | + | |
182 | 179 |
| |
183 | 180 |
| |
184 | 181 |
| |
| |||
592 | 589 |
| |
593 | 590 |
| |
594 | 591 |
| |
| 592 | + | |
595 | 593 |
| |
596 |
| - | |
597 | 594 |
| |
598 | 595 |
| |
599 | 596 |
| |
| |||
620 | 617 |
| |
621 | 618 |
| |
622 | 619 |
| |
623 |
| - | |
624 |
| - | |
| 620 | + | |
625 | 621 |
| |
626 |
| - | |
| 622 | + | |
627 | 623 |
| |
628 | 624 |
| |
629 | 625 |
| |
| |||
687 | 683 |
| |
688 | 684 |
| |
689 | 685 |
| |
690 |
| - | |
691 |
| - | |
692 |
| - | |
| 686 | + | |
| 687 | + | |
693 | 688 |
| |
694 | 689 |
| |
695 | 690 |
| |
696 | 691 |
| |
697 | 692 |
| |
698 |
| - | |
| 693 | + | |
699 | 694 |
| |
700 | 695 |
| |
701 | 696 |
| |
|
Lines changed: 10 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5187 | 5187 |
| |
5188 | 5188 |
| |
5189 | 5189 |
| |
5190 |
| - | |
5191 |
| - | |
| 5190 | + | |
5192 | 5191 |
| |
5193 | 5192 |
| |
5194 |
| - | |
| 5193 | + | |
5195 | 5194 |
| |
5196 | 5195 |
| |
5197 | 5196 |
| |
| |||
5305 | 5304 |
| |
5306 | 5305 |
| |
5307 | 5306 |
| |
5308 |
| - | |
| 5307 | + | |
5309 | 5308 |
| |
5310 | 5309 |
| |
5311 | 5310 |
| |
| |||
6472 | 6471 |
| |
6473 | 6472 |
| |
6474 | 6473 |
| |
6475 |
| - | |
| 6474 | + | |
| 6475 | + | |
6476 | 6476 |
| |
6477 |
| - | |
| 6477 | + | |
6478 | 6478 |
| |
6479 | 6479 |
| |
6480 | 6480 |
| |
| |||
6781 | 6781 |
| |
6782 | 6782 |
| |
6783 | 6783 |
| |
6784 |
| - | |
| 6784 | + | |
| 6785 | + | |
6785 | 6786 |
| |
6786 |
| - | |
| 6787 | + | |
6787 | 6788 |
| |
6788 |
| - | |
| 6789 | + | |
6789 | 6790 |
| |
6790 | 6791 |
| |
6791 | 6792 |
| |
|
0 commit comments
Comments
(0)