forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf330a6d
committed
Fix mishandling of FieldSelect-on-whole-row-Var in nested lateral queries.
If an inline-able SQL function taking a composite argument is used in aLATERAL subselect, and the composite argument is a lateral reference,the planner could fail with "variable not found in subplan target list",as seen in bug #11703 from Karl Bartel. (The outer function call used inthe bug report and in the committed regression test is not really necessaryto provoke the bug --- you can get it if you manually expand the outerfunction into "LATERAL (SELECT inner_function(outer_relation))", too.)The cause of this is that we generate the reltargetlist for the referencedrelation before doing eval_const_expressions() on the lateral sub-select'sexpressions (cf find_lateral_references()), so what's scheduled to beemitted by the referenced relation is a whole-row Var, not the simplifiedsingle-column Var produced by optimizing the function's FieldSelect on thewhole-row Var. Then setrefs.c fails to match up that lateral reference towhat's available from the outer scan.Preserving the FieldSelect optimization in such cases would require eithermajor planner restructuring (to recursively do expression simplificationon sub-selects much earlier) or some amazingly ugly kluge to change thereltargetlist of a possibly-already-planned relation. It seems betterjust to skip the optimization when the Var is from an upper query level;the case is not so common that it's likely anyone will notice a fewwasted cycles.AFAICT this problem only occurs for uplevel LATERAL references, soback-patch to 9.3 where LATERAL was added.1 parent488a7c9 commitf330a6d
File tree
3 files changed
+87
-5
lines changed- src
- backend/optimizer/util
- test/regress
- expected
- sql
3 files changed
+87
-5
lines changedLines changed: 15 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3196 | 3196 |
| |
3197 | 3197 |
| |
3198 | 3198 |
| |
3199 |
| - | |
3200 |
| - | |
3201 |
| - | |
3202 |
| - | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
| 3205 | + | |
| 3206 | + | |
| 3207 | + | |
| 3208 | + | |
| 3209 | + | |
| 3210 | + | |
| 3211 | + | |
3203 | 3212 |
| |
3204 | 3213 |
| |
3205 | 3214 |
| |
| |||
3208 | 3217 |
| |
3209 | 3218 |
| |
3210 | 3219 |
| |
3211 |
| - | |
| 3220 | + | |
| 3221 | + | |
3212 | 3222 |
| |
3213 | 3223 |
| |
3214 | 3224 |
| |
|
Lines changed: 52 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2006 | 2006 |
| |
2007 | 2007 |
| |
2008 | 2008 |
| |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + |
Lines changed: 20 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
608 | 608 |
| |
609 | 609 |
| |
610 | 610 |
| |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + |
0 commit comments
Comments
(0)