forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit1d33858
committed
Fix handling of targetlist SRFs when scan/join relation is known empty.
When we introduced separate ProjectSetPath nodes for application ofset-returning functions in v10, we inadvertently broke some cases wherewe're supposed to recognize that the result of a subquery is known to beempty (contain zero rows). That's because IS_DUMMY_REL was just lookingfor a childless AppendPath without allowing for a ProjectSetPath beingpossibly stuck on top. In itself, this didn't do anything much worsethan produce slightly worse plans for some corner cases.Then in v11, commit11cf92f rearranged things to allow the scan/jointargetlist to be applied directly to partial paths before they getgathered. But it inserted a short-circuit path for dummy relationsthat was a little too short: it failed to insert a ProjectSetPath nodeat all for a targetlist containing set-returning functions, resulting inbogus "set-valued function called in context that cannot accept a set"errors, as reported in bug #15669 from Madelaine Thibaut.The best way to fix this mess seems to be to reimplement IS_DUMMY_RELso that it drills down through any ProjectSetPath nodes that might bethere (and it seems like we'd better allow for ProjectionPath as well).While we're at it, make it look at rel->pathlist not cheapest_total_path,so that it gives the right answer independently of whether set_cheapesthas been done lately. That dependency looks pretty shaky in the contextof code like apply_scanjoin_target_to_paths, and even if it's not brokentoday it'd certainly bite us at some point. (Nastily, unsafe use of theold coding would almost always work; the hazard comes down to possiblylooking through a dangling pointer, and only once in a blue moon wouldyou find something there that resulted in the wrong answer.)It now looks like it was a mistake for IS_DUMMY_REL to be a macro: ifthere are any extensions using it, they'll continue to use the oldinadequate logic until they're recompiled, after which they'll failto load into server versions predating this fix. Hopefully there arefew such extensions.Having fixed IS_DUMMY_REL, the special path for dummy rels inapply_scanjoin_target_to_paths is unnecessary as well as being wrong,so we can just drop it.Also change a few places that were testing for partitioned-ness of aplanner relation but not using IS_PARTITIONED_REL for the purpose; thatseems unsafe as well as inconsistent, plus it required an ugly hack inapply_scanjoin_target_to_paths.In passing, save a few cycles in apply_scanjoin_target_to_paths byskipping processing of pre-existing paths for partitioned rels,and do some cosmetic cleanup and comment adjustment in that function.I renamed IS_DUMMY_PATH to IS_DUMMY_APPEND with the intention of breakingany code that might be using it, since in almost every case that wouldbe wrong; IS_DUMMY_REL is what to be using instead.In HEAD, also make set_dummy_rel_pathlist static (since it's no longerused from outside allpaths.c), and delete is_dummy_plan, since it's nolonger used anywhere.Back-patch as appropriate into v11 and v10.Tom Lane and Julien RouhaudDiscussion:https://postgr.es/m/15669-02fb3296cca26203@postgresql.org1 parent898e5e3 commit1d33858
File tree
9 files changed
+182
-139
lines changed- src
- backend/optimizer
- path
- plan
- include
- nodes
- optimizer
- test/regress
- expected
- sql
9 files changed
+182
-139
lines changedLines changed: 14 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
105 | 105 |
| |
106 | 106 |
| |
107 | 107 |
| |
| 108 | + | |
108 | 109 |
| |
109 | 110 |
| |
110 | 111 |
| |
| |||
1557 | 1558 |
| |
1558 | 1559 |
| |
1559 | 1560 |
| |
1560 |
| - | |
| 1561 | + | |
1561 | 1562 |
| |
1562 | 1563 |
| |
1563 | 1564 |
| |
| |||
1954 | 1955 |
| |
1955 | 1956 |
| |
1956 | 1957 |
| |
1957 |
| - | |
| 1958 | + | |
1958 | 1959 |
| |
1959 |
| - | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
1960 | 1963 |
| |
1961 |
| - | |
| 1964 | + | |
1962 | 1965 |
| |
1963 | 1966 |
| |
1964 | 1967 |
| |
| |||
1969 | 1972 |
| |
1970 | 1973 |
| |
1971 | 1974 |
| |
| 1975 | + | |
1972 | 1976 |
| |
1973 | 1977 |
| |
1974 | 1978 |
| |
1975 | 1979 |
| |
1976 |
| - | |
1977 |
| - | |
1978 |
| - | |
1979 |
| - | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
1980 | 1984 |
| |
1981 | 1985 |
| |
1982 | 1986 |
| |
| |||
3532 | 3536 |
| |
3533 | 3537 |
| |
3534 | 3538 |
| |
| 3539 | + | |
| 3540 | + | |
3535 | 3541 |
| |
3536 | 3542 |
| |
3537 | 3543 |
| |
3538 | 3544 |
| |
3539 |
| - | |
3540 |
| - | |
3541 | 3545 |
| |
3542 | 3546 |
| |
3543 | 3547 |
| |
|
Lines changed: 30 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
34 | 34 |
| |
35 | 35 |
| |
36 | 36 |
| |
37 |
| - | |
38 | 37 |
| |
39 | 38 |
| |
40 | 39 |
| |
| |||
1196 | 1195 |
| |
1197 | 1196 |
| |
1198 | 1197 |
| |
1199 |
| - | |
| 1198 | + | |
1200 | 1199 |
| |
1201 | 1200 |
| |
1202 |
| - | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
1203 | 1230 |
| |
1204 | 1231 |
| |
1205 | 1232 |
| |
|
Lines changed: 5 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1072 | 1072 |
| |
1073 | 1073 |
| |
1074 | 1074 |
| |
1075 |
| - | |
| 1075 | + | |
1076 | 1076 |
| |
1077 | 1077 |
| |
1078 | 1078 |
| |
| |||
6585 | 6585 |
| |
6586 | 6586 |
| |
6587 | 6587 |
| |
6588 |
| - | |
6589 |
| - | |
6590 |
| - | |
6591 |
| - | |
| 6588 | + | |
| 6589 | + | |
| 6590 | + | |
6592 | 6591 |
| |
6593 |
| - | |
| 6592 | + | |
6594 | 6593 |
| |
6595 | 6594 |
| |
6596 | 6595 |
| |
|
0 commit comments
Comments
(0)