- Notifications
You must be signed in to change notification settings - Fork28
Commit9ce77d7
committed
Reconsider the representation of join alias Vars.
The core idea of this patch is to make the parser generate join aliasVars (that is, ones with varno pointing to a JOIN RTE) only when thealias Var is actually different from any raw join input, that is a typecoercion and/or COALESCE is necessary to generate the join output value.Otherwise just generate varno/varattno pointing to the relevant joininput column.In effect, this means that the planner's flatten_join_alias_vars()transformation is already done in the parser, for all cases except(a) columns that are merged by JOIN USING and are transformed in theprocess, and (b) whole-row join Vars. In principle that would allowus to skip doing flatten_join_alias_vars() in many more queries thanwe do now, but we don't have quite enough infrastructure to know thatwe can do so --- in particular there's no cheap way to know whetherthere are any whole-row join Vars. I'm not sure if it's worth thetrouble to add a Query-level flag for that, and in any case it seemslike fit material for a separate patch. But even without skipping thework entirely, this should make flatten_join_alias_vars() faster,particularly where there are nested joins that it previously had toflatten recursively.An essential part of this change is to replace Var nodes'varnoold/varoattno fields with varnosyn/varattnosyn, which haveconsiderably more tightly-defined meanings than the old fields: whenthey differ from varno/varattno, they identify the Var's position inan aliased JOIN RTE, and the join alias is what ruleutils.c shouldprint for the Var. This is necessary because the varno changedestroyed ruleutils.c's ability to find the JOIN RTE from the Var'svarno.Another way in which this change broke ruleutils.c is that it's nolonger feasible to determine, from a JOIN RTE's joinaliasvars list,which join columns correspond to which columns of the join's immediateinput relations. (If those are sub-joins, the joinaliasvars entriesmay point to columns of their base relations, not the sub-joins.)But that was a horrid mess requiring a lot of fragile assumptionsalready, so let's just bite the bullet and add some more JOIN RTEfields to make it more straightforward to figure that out. I addedtwo integer-List fields containing the relevant column numbers fromthe left and right input rels, plus a count of how many merged columnsthere are.This patch depends on the ParseNamespaceColumn infrastructure thatI added in commit5815696. The biggest bit of code change isrestructuring transformFromClauseItem's handling of JOINs so thatthe ParseNamespaceColumn data is propagated upward correctly.Other than that and the ruleutils fixes, everything pretty muchjust works, though some processing is now inessential. I grabbedtwo pieces of low-hanging fruit in that line:1. In find_expr_references, we don't need to recurse into join aliasVars anymore. There aren't any except for references to merged USINGcolumns, which are more properly handled when we scan the join's RTE.This change actually fixes an edge-case issue: we will now record adependency on any type-coercion function present in a USING column'sjoinaliasvar, even if that join column has no references in the querytext. The odds of the missing dependency causing a problem seem quitesmall: you'd have to posit somebody dropping an implicit cast betweentwo data types, without removing the types themselves, and then havinga stored rule containing a whole-row Var for a join whose USING mergedepends on that cast. So I don't feel a great need to change this inthe back branches. But in theory this way is more correct.2. markRTEForSelectPriv and markTargetListOrigin don't need to recurseinto join alias Vars either, because the cases they care about don'tapply to alias Vars for USING columns that are semantically distinctfrom the underlying columns. This removes the only case in whichmarkVarForSelectPriv could be called with NULL for the RTE, so adjustthe comments to describe that hack as being strictly internal tomarkRTEForSelectPriv.catversion bump required due to changes in stored rules.Discussion:https://postgr.es/m/7115.1577986646@sss.pgh.pa.us1 parented10f32 commit9ce77d7
File tree
19 files changed
+421
-390
lines changed- src
- backend
- catalog
- nodes
- optimizer
- plan
- util
- parser
- rewrite
- utils/adt
- include
- catalog
- nodes
- parser
19 files changed
+421
-390
lines changedLines changed: 39 additions & 27 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1718 | 1718 |
| |
1719 | 1719 |
| |
1720 | 1720 |
| |
1721 |
| - | |
1722 |
| - | |
1723 |
| - | |
1724 |
| - | |
1725 |
| - | |
1726 |
| - | |
1727 | 1721 |
| |
1728 | 1722 |
| |
1729 | 1723 |
| |
| |||
1773 | 1767 |
| |
1774 | 1768 |
| |
1775 | 1769 |
| |
1776 |
| - | |
1777 |
| - | |
1778 |
| - | |
1779 |
| - | |
1780 |
| - | |
1781 |
| - | |
1782 |
| - | |
1783 |
| - | |
1784 |
| - | |
1785 |
| - | |
1786 |
| - | |
1787 |
| - | |
1788 |
| - | |
1789 |
| - | |
1790 |
| - | |
1791 |
| - | |
1792 |
| - | |
1793 |
| - | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
1794 | 1779 |
| |
1795 | 1780 |
| |
1796 | 1781 |
| |
| |||
2147 | 2132 |
| |
2148 | 2133 |
| |
2149 | 2134 |
| |
2150 |
| - | |
| 2135 | + | |
| 2136 | + | |
2151 | 2137 |
| |
2152 | 2138 |
| |
2153 |
| - | |
2154 |
| - | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
2155 | 2142 |
| |
2156 | 2143 |
| |
2157 | 2144 |
| |
| |||
2169 | 2156 |
| |
2170 | 2157 |
| |
2171 | 2158 |
| |
| 2159 | + | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
2172 | 2184 |
| |
2173 | 2185 |
| |
2174 | 2186 |
| |
|
Lines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1367 | 1367 |
| |
1368 | 1368 |
| |
1369 | 1369 |
| |
1370 |
| - | |
1371 |
| - | |
| 1370 | + | |
| 1371 | + | |
1372 | 1372 |
| |
1373 | 1373 |
| |
1374 | 1374 |
| |
| |||
2373 | 2373 |
| |
2374 | 2374 |
| |
2375 | 2375 |
| |
| 2376 | + | |
2376 | 2377 |
| |
| 2378 | + | |
| 2379 | + | |
2377 | 2380 |
| |
2378 | 2381 |
| |
2379 | 2382 |
| |
|
Lines changed: 9 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
168 | 168 |
| |
169 | 169 |
| |
170 | 170 |
| |
171 |
| - | |
172 |
| - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
173 | 177 |
| |
174 | 178 |
| |
175 | 179 |
| |
| |||
2657 | 2661 |
| |
2658 | 2662 |
| |
2659 | 2663 |
| |
| 2664 | + | |
2660 | 2665 |
| |
| 2666 | + | |
| 2667 | + | |
2661 | 2668 |
| |
2662 | 2669 |
| |
2663 | 2670 |
| |
|
Lines changed: 5 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
80 | 80 |
| |
81 | 81 |
| |
82 | 82 |
| |
83 |
| - | |
84 |
| - | |
85 |
| - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
86 | 86 |
| |
87 | 87 |
| |
88 |
| - | |
89 |
| - | |
| 88 | + | |
| 89 | + | |
90 | 90 |
| |
91 | 91 |
| |
92 | 92 |
| |
|
Lines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1074 | 1074 |
| |
1075 | 1075 |
| |
1076 | 1076 |
| |
1077 |
| - | |
1078 |
| - | |
| 1077 | + | |
| 1078 | + | |
1079 | 1079 |
| |
1080 | 1080 |
| |
1081 | 1081 |
| |
| |||
3071 | 3071 |
| |
3072 | 3072 |
| |
3073 | 3073 |
| |
| 3074 | + | |
3074 | 3075 |
| |
| 3076 | + | |
| 3077 | + | |
3075 | 3078 |
| |
3076 | 3079 |
| |
3077 | 3080 |
| |
|
Lines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
540 | 540 |
| |
541 | 541 |
| |
542 | 542 |
| |
543 |
| - | |
544 |
| - | |
| 543 | + | |
| 544 | + | |
545 | 545 |
| |
546 | 546 |
| |
547 | 547 |
| |
| |||
1400 | 1400 |
| |
1401 | 1401 |
| |
1402 | 1402 |
| |
| 1403 | + | |
1403 | 1404 |
| |
| 1405 | + | |
| 1406 | + | |
1404 | 1407 |
| |
1405 | 1408 |
| |
1406 | 1409 |
| |
|
Lines changed: 21 additions & 18 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
428 | 428 |
| |
429 | 429 |
| |
430 | 430 |
| |
| 431 | + | |
| 432 | + | |
431 | 433 |
| |
432 | 434 |
| |
433 | 435 |
| |
| |||
1681 | 1683 |
| |
1682 | 1684 |
| |
1683 | 1685 |
| |
1684 |
| - | |
1685 |
| - | |
| 1686 | + | |
| 1687 | + | |
1686 | 1688 |
| |
1687 | 1689 |
| |
1688 | 1690 |
| |
| |||
2110 | 2112 |
| |
2111 | 2113 |
| |
2112 | 2114 |
| |
2113 |
| - | |
| 2115 | + | |
| 2116 | + | |
2114 | 2117 |
| |
2115 |
| - | |
2116 |
| - | |
| 2118 | + | |
| 2119 | + | |
2117 | 2120 |
| |
2118 | 2121 |
| |
2119 | 2122 |
| |
2120 |
| - | |
2121 |
| - | |
| 2123 | + | |
| 2124 | + | |
2122 | 2125 |
| |
2123 | 2126 |
| |
2124 | 2127 |
| |
| |||
2242 | 2245 |
| |
2243 | 2246 |
| |
2244 | 2247 |
| |
2245 |
| - | |
| 2248 | + | |
2246 | 2249 |
| |
2247 | 2250 |
| |
2248 | 2251 |
| |
| |||
2265 | 2268 |
| |
2266 | 2269 |
| |
2267 | 2270 |
| |
2268 |
| - | |
2269 |
| - | |
| 2271 | + | |
| 2272 | + | |
2270 | 2273 |
| |
2271 | 2274 |
| |
2272 | 2275 |
| |
| |||
2308 | 2311 |
| |
2309 | 2312 |
| |
2310 | 2313 |
| |
2311 |
| - | |
2312 |
| - | |
| 2314 | + | |
| 2315 | + | |
2313 | 2316 |
| |
2314 | 2317 |
| |
2315 | 2318 |
| |
| |||
2345 | 2348 |
| |
2346 | 2349 |
| |
2347 | 2350 |
| |
2348 |
| - | |
2349 |
| - | |
| 2351 | + | |
| 2352 | + | |
2350 | 2353 |
| |
2351 | 2354 |
| |
2352 | 2355 |
| |
| |||
2384 | 2387 |
| |
2385 | 2388 |
| |
2386 | 2389 |
| |
2387 |
| - | |
| 2390 | + | |
2388 | 2391 |
| |
2389 | 2392 |
| |
2390 | 2393 |
| |
| |||
2445 | 2448 |
| |
2446 | 2449 |
| |
2447 | 2450 |
| |
2448 |
| - | |
2449 |
| - | |
| 2451 | + | |
| 2452 | + | |
2450 | 2453 |
| |
2451 | 2454 |
| |
2452 | 2455 |
| |
| |||
2528 | 2531 |
| |
2529 | 2532 |
| |
2530 | 2533 |
| |
2531 |
| - | |
| 2534 | + | |
2532 | 2535 |
| |
2533 | 2536 |
| |
2534 | 2537 |
| |
|
Lines changed: 7 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
255 | 255 |
| |
256 | 256 |
| |
257 | 257 |
| |
| 258 | + | |
| 259 | + | |
| 260 | + | |
258 | 261 |
| |
259 | 262 |
| |
260 | 263 |
| |
| |||
264 | 267 |
| |
265 | 268 |
| |
266 | 269 |
| |
267 |
| - | |
| 270 | + | |
268 | 271 |
| |
269 | 272 |
| |
270 |
| - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
271 | 276 |
| |
272 | 277 |
| |
273 | 278 |
| |
|
Lines changed: 3 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
83 | 83 |
| |
84 | 84 |
| |
85 | 85 |
| |
86 |
| - | |
| 86 | + | |
| 87 | + | |
87 | 88 |
| |
88 | 89 |
| |
89 | 90 |
| |
90 | 91 |
| |
91 | 92 |
| |
92 |
| - | |
93 |
| - | |
94 |
| - | |
| 93 | + | |
95 | 94 |
| |
96 | 95 |
| |
97 | 96 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1734 | 1734 |
| |
1735 | 1735 |
| |
1736 | 1736 |
| |
| 1737 | + | |
1737 | 1738 |
| |
| 1739 | + | |
| 1740 | + | |
1738 | 1741 |
| |
1739 | 1742 |
| |
1740 | 1743 |
| |
|
0 commit comments
Comments
(0)