forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitff0b18c
committed
Fix PARAM_EXEC assignment mechanism to be safe in the presence of WITH.
The planner previously assumed that parameter Vars having the same absolutequery level, varno, and varattno could safely be assigned the same runtimePARAM_EXEC slot, even though they might be different Vars appearing indifferent subqueries. This was (probably) safe before the introduction ofCTEs, but the lazy-evalution mechanism used for CTEs means that a CTE canbe executed during execution of some other subquery, causing the lifespanof Params at the same syntactic nesting level as the CTE to overlap withuse of the same slots inside the CTE. In 9.1 we created additional hazardsby using the same parameter-assignment technology for nestloop inner scanparameters, but it was broken before that, as illustrated by the addedregression test.To fix, restructure the planner's management of PlannerParamItems so thatitems having different semantic lifespans are kept rigorously separated.This will probably result in complex queries using more runtime PARAM_EXECslots than before, but the slots are cheap enough that this hardly matters.Also, stop generating PlannerParamItems containing Params for subqueryoutputs: all we really need to do is reserve the PARAM_EXEC slot number,and that now only takes incrementing a counter. The planning code issimpler and probably faster than before, as well as being more correct.Per report from Vik Reykja.Back-patch of commit46c508f into allbranches that support WITH.1 parente40b20a commitff0b18c
File tree
10 files changed
+247
-179
lines changed- src
- backend
- nodes
- optimizer
- path
- plan
- prep
- include/nodes
- test/regress
- expected
- sql
10 files changed
+247
-179
lines changedLines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1659 | 1659 |
| |
1660 | 1660 |
| |
1661 | 1661 |
| |
1662 |
| - | |
1663 | 1662 |
| |
1664 | 1663 |
| |
1665 | 1664 |
| |
| |||
1669 | 1668 |
| |
1670 | 1669 |
| |
1671 | 1670 |
| |
| 1671 | + | |
1672 | 1672 |
| |
1673 | 1673 |
| |
1674 | 1674 |
| |
| |||
1683 | 1683 |
| |
1684 | 1684 |
| |
1685 | 1685 |
| |
| 1686 | + | |
1686 | 1687 |
| |
1687 | 1688 |
| |
1688 | 1689 |
| |
| |||
1927 | 1928 |
| |
1928 | 1929 |
| |
1929 | 1930 |
| |
1930 |
| - | |
| 1931 | + | |
1931 | 1932 |
| |
1932 | 1933 |
| |
1933 | 1934 |
| |
|
Lines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
786 | 786 |
| |
787 | 787 |
| |
788 | 788 |
| |
| 789 | + | |
| 790 | + | |
| 791 | + | |
789 | 792 |
| |
790 | 793 |
| |
791 | 794 |
| |
| |||
794 | 797 |
| |
795 | 798 |
| |
796 | 799 |
| |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
797 | 807 |
| |
798 | 808 |
| |
799 | 809 |
| |
|
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
185 | 185 |
| |
186 | 186 |
| |
187 | 187 |
| |
| 188 | + | |
| 189 | + | |
| 190 | + | |
188 | 191 |
| |
189 | 192 |
| |
190 | 193 |
| |
| |||
196 | 199 |
| |
197 | 200 |
| |
198 | 201 |
| |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
199 | 208 |
| |
200 | 209 |
| |
201 | 210 |
| |
|
Lines changed: 4 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
156 | 156 |
| |
157 | 157 |
| |
158 | 158 |
| |
159 |
| - | |
160 | 159 |
| |
161 | 160 |
| |
162 | 161 |
| |
| |||
166 | 165 |
| |
167 | 166 |
| |
168 | 167 |
| |
| 168 | + | |
169 | 169 |
| |
170 | 170 |
| |
171 | 171 |
| |
| |||
254 | 254 |
| |
255 | 255 |
| |
256 | 256 |
| |
257 |
| - | |
| 257 | + | |
258 | 258 |
| |
259 | 259 |
| |
260 | 260 |
| |
| |||
306 | 306 |
| |
307 | 307 |
| |
308 | 308 |
| |
| 309 | + | |
309 | 310 |
| |
310 | 311 |
| |
311 | 312 |
| |
| |||
577 | 578 |
| |
578 | 579 |
| |
579 | 580 |
| |
580 |
| - | |
| 581 | + | |
581 | 582 |
| |
582 | 583 |
| |
583 | 584 |
| |
|
0 commit comments
Comments
(0)