- Notifications
You must be signed in to change notification settings - Fork28
Commit2e668c5
committed
Avoid crash during EvalPlanQual recheck of an inner indexscan.
Commit09529a7 changed nodeIndexscan.c and nodeIndexonlyscan.c topostpone initialization of the indexscan proper until the first tuplefetch. It overlooked the question of mark/restore behavior, which meansthat if some caller attempts to mark the scan before the first tuple fetch,you get a null pointer dereference.The only existing user of mark/restore is nodeMergejoin.c, which (somewhataccidentally) will never attempt to set a mark before the first inner tupleunless the inner child node is a Material node. Hence the case can't arisenormally, so it seems sufficient to document the assumption at both ends.However, during an EvalPlanQual recheck, ExecScanFetch doesn't callIndexNext but just returns the jammed-in test tuple. Therefore, if we'redoing a recheck in a plan tree with a mergejoin with inner indexscan,it's possible to reach ExecIndexMarkPos with iss_ScanDesc still null,as reported by Guo Xiang Tan in bug #15032.Really, when there's a test tuple supplied during an EPQ recheck, touchingthe index at all is the wrong thing: rather, the behavior of mark/restoreought to amount to saving and restoring the es_epqScanDone flag. We canavoid finding a place to actually save the flag, for the moment, becausegiven the assumption that no caller will set a mark before fetching atuple, es_epqScanDone must always be set by the time we try to mark.So the actual behavior change required is just to not reach the indexaccess if a test tuple is supplied.The set of plan node types that need to consider this issue are thosethat support EPQ test tuples (i.e., call ExecScan()) and also supportmark/restore; which is to say, IndexScan, IndexOnlyScan, and perhapsCustomScan. It's tempting to try to fix the problem in one place byteaching ExecMarkPos() itself about EPQ; but ExecMarkPos supports someplan types that aren't Scans, and also it seems risky to make assumptionsabout what a CustomScan wants to do here. Also, the most likely futurechange here is to decide that we do need to support marks placed beforethe first tuple, which would require additional work in IndexScan andIndexOnlyScan in any case. Hence, fix the EPQ issue in nodeIndexscan.cand nodeIndexonlyscan.c, accepting the small amount of code duplicatedthereby, and leave it to CustomScan providers to fix this bug if theyhave it.Back-patch to v10 where commit09529a7 came in. In earlier branches,the index_markpos() call is a waste of cycles when EPQ is active, butno more than that, so it doesn't seem appropriate to back-patch further.Discussion:https://postgr.es/m/20180126074932.3098.97815@wrigleys.postgresql.org1 parentba8c2df commit2e668c5
File tree
5 files changed
+144
-1
lines changed- src
- backend/executor
- test/isolation
- expected
- specs
5 files changed
+144
-1
lines changedLines changed: 45 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
421 | 421 |
| |
422 | 422 |
| |
423 | 423 |
| |
| 424 | + | |
| 425 | + | |
| 426 | + | |
424 | 427 |
| |
425 | 428 |
| |
426 | 429 |
| |
427 | 430 |
| |
428 | 431 |
| |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
429 | 457 |
| |
430 | 458 |
| |
431 | 459 |
| |
| |||
436 | 464 |
| |
437 | 465 |
| |
438 | 466 |
| |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
439 | 484 |
| |
440 | 485 |
| |
441 | 486 |
| |
|
Lines changed: 45 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
849 | 849 |
| |
850 | 850 |
| |
851 | 851 |
| |
| 852 | + | |
| 853 | + | |
| 854 | + | |
852 | 855 |
| |
853 | 856 |
| |
854 | 857 |
| |
855 | 858 |
| |
856 | 859 |
| |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
857 | 885 |
| |
858 | 886 |
| |
859 | 887 |
| |
| |||
864 | 892 |
| |
865 | 893 |
| |
866 | 894 |
| |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
867 | 912 |
| |
868 | 913 |
| |
869 | 914 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1502 | 1502 |
| |
1503 | 1503 |
| |
1504 | 1504 |
| |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
1505 | 1509 |
| |
1506 | 1510 |
| |
1507 | 1511 |
| |
|
Lines changed: 33 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
184 | 184 |
| |
185 | 185 |
| |
186 | 186 |
| |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + |
Lines changed: 17 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
21 | 21 |
| |
22 | 22 |
| |
23 | 23 |
| |
| 24 | + | |
| 25 | + | |
| 26 | + | |
24 | 27 |
| |
25 | 28 |
| |
26 | 29 |
| |
27 | 30 |
| |
28 | 31 |
| |
29 | 32 |
| |
30 |
| - | |
| 33 | + | |
31 | 34 |
| |
32 | 35 |
| |
33 | 36 |
| |
| |||
78 | 81 |
| |
79 | 82 |
| |
80 | 83 |
| |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
81 | 95 |
| |
82 | 96 |
| |
83 | 97 |
| |
| |||
104 | 118 |
| |
105 | 119 |
| |
106 | 120 |
| |
| 121 | + | |
107 | 122 |
| |
108 | 123 |
| |
109 | 124 |
| |
| |||
135 | 150 |
| |
136 | 151 |
| |
137 | 152 |
| |
| 153 | + |
0 commit comments
Comments
(0)