forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit362e2dc
committed
Fix rewriter to set hasModifyingCTE correctly on rewritten queries.
If we copy data-modifying CTEs from the original query to a replacementquery (from a DO INSTEAD rule), we must set hasModifyingCTE properlyin the replacement query. Failure to do this can cause variousunpleasantness, such as unsafe usage of parallel plans. The code alsoneglected to propagate hasRecursive, though that's only cosmetic atthe moment.A difficulty arises if the rule action is an INSERT...SELECT. Weattach the original query's RTEs and CTEs to the sub-SELECT Query, butdata-modifying CTEs are only allowed to appear in the topmost Query.For the moment, throw an error in such cases. It would probably bepossible to avoid this error by attaching the CTEs to the top INSERTQuery instead; but that would require a bunch of new code to adjustctelevelsup references. Given the narrowness of the use-case, andthe need to back-patch this fix, it does not seem worth the troublefor now. We can revisit this if we get field complaints.Per report from Greg Nancarrow. Back-patch to all supported branches.(The test case added here does not fail before v10, but there areplenty of places checking top-level hasModifyingCTE in 9.6, so I haveno doubt that this code change is necessary there too.)Greg Nancarrow and Tom LaneDiscussion:https://postgr.es/m/CAJcOf-f68DT=26YAMz_i0+Au3TcLO5oiHY5=fL6Sfuits6r+_w@mail.gmail.comDiscussion:https://postgr.es/m/CAJcOf-fAdj=nDKMsRhQzndm-O13NY4dL6xGcEvdX5Xvbbi0V7g@mail.gmail.com1 parentf7c53bb commit362e2dc
File tree
3 files changed
+85
-2
lines changed- src
- backend/rewrite
- test/regress
- expected
- sql
3 files changed
+85
-2
lines changedLines changed: 23 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
535 | 535 |
| |
536 | 536 |
| |
537 | 537 |
| |
| 538 | + | |
| 539 | + | |
| 540 | + | |
538 | 541 |
| |
539 | 542 |
| |
540 | 543 |
| |
| |||
556 | 559 |
| |
557 | 560 |
| |
558 | 561 |
| |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
559 | 582 |
| |
560 | 583 |
| |
561 | 584 |
| |
|
Lines changed: 36 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2381 | 2381 |
| |
2382 | 2382 |
| |
2383 | 2383 |
| |
2384 |
| - | |
| 2384 | + | |
2385 | 2385 |
| |
2386 | 2386 |
| |
2387 | 2387 |
| |
| |||
2397 | 2397 |
| |
2398 | 2398 |
| |
2399 | 2399 |
| |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
2400 | 2435 |
| |
2401 | 2436 |
| |
2402 | 2437 |
| |
|
Lines changed: 26 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1118 | 1118 |
| |
1119 | 1119 |
| |
1120 | 1120 |
| |
1121 |
| - | |
| 1121 | + | |
1122 | 1122 |
| |
1123 | 1123 |
| |
1124 | 1124 |
| |
1125 | 1125 |
| |
1126 | 1126 |
| |
1127 | 1127 |
| |
1128 | 1128 |
| |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
1129 | 1154 |
| |
1130 | 1155 |
| |
1131 | 1156 |
| |
|
0 commit comments
Comments
(0)