Commit 519c515
committed
Correct parallel window function in CASE WHEN.
Previously, we attempted to disable window functions inside CASE WHEN
expressions due to concerns about unstable parallel results. However,
this was a misunderstanding. All expressions from the subquery are Var
columns, not the original expressions.
This issue was uncovered when we fixed the subquery row count
estimation, causing the cost to change in the upper plan.
EXPLAIN(COSTS OFF)
SELECT empno, depname, salary, bonus, depadj, MIN(bonus) OVER (ORDER BY
empno), MAX(depadj) OVER () FROM(
SELECT *,
CASE WHEN enroll_date < '2008-01-01' THEN 2008 -
extract(YEAR FROM enroll_date) END * 500 AS bonus,
CASE WHEN
AVG(salary) OVER (PARTITION BY depname) < salary
THEN 200 END AS depadj FROM empsalary
)s;
QUERY PLAN
--------------------------------------------------------------------------
WindowAgg
-> WindowAgg
Order By: s.empno
-> Gather Motion 6:1 (slice1; segments: 6)
Merge Key: s.empno
-> Sort
Sort Key: s.empno
-> Subquery Scan on s
-> WindowAgg
Partition By: empsalary.depname
-> Sort
Sort Key: empsalary.depname
-> Redistribute Motion 6:6
(slice2; segments: 6)
Hash Key: empsalary.depname
Hash Module: 3
-> Parallel Seq Scan on
empsalary
Optimizer: Postgres query optimizer
(17 rows)
Authored-by: Zhang Mingli avamingli@gmail.com1 parent 44195cc commit 519c515
File tree
4 files changed
+12
-70
lines changed- src
- backend/optimizer/plan
- test/regress
- expected
- sql
4 files changed
+12
-70
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | 303 | | |
310 | 304 | | |
311 | 305 | | |
| |||
9139 | 9133 | | |
9140 | 9134 | | |
9141 | 9135 | | |
9142 | | - | |
9143 | | - | |
9144 | | - | |
9145 | | - | |
9146 | | - | |
9147 | | - | |
9148 | | - | |
9149 | | - | |
9150 | | - | |
9151 | | - | |
9152 | | - | |
9153 | | - | |
9154 | | - | |
9155 | | - | |
9156 | | - | |
9157 | | - | |
9158 | | - | |
9159 | | - | |
9160 | | - | |
9161 | 9136 | | |
9162 | 9137 | | |
9163 | 9138 | | |
| |||
9176 | 9151 | | |
9177 | 9152 | | |
9178 | 9153 | | |
9179 | | - | |
9180 | 9154 | | |
9181 | 9155 | | |
9182 | 9156 | | |
9183 | | - | |
9184 | | - | |
9185 | | - | |
9186 | | - | |
9187 | | - | |
9188 | | - | |
9189 | | - | |
9190 | | - | |
9191 | | - | |
9192 | | - | |
9193 | | - | |
9194 | | - | |
9195 | | - | |
9196 | | - | |
9197 | | - | |
9198 | | - | |
9199 | | - | |
9200 | | - | |
9201 | | - | |
9202 | | - | |
9203 | | - | |
9204 | | - | |
9205 | | - | |
9206 | | - | |
9207 | | - | |
9208 | | - | |
9209 | | - | |
9210 | | - | |
9211 | | - | |
9212 | | - | |
9213 | | - | |
9214 | | - | |
9215 | | - | |
9216 | | - | |
9217 | | - | |
9218 | | - | |
9219 | | - | |
9220 | 9157 | | |
9221 | 9158 | | |
9222 | 9159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
501 | | - | |
| 501 | + | |
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
| |||
556 | 556 | | |
557 | 557 | | |
558 | 558 | | |
559 | | - | |
560 | | - | |
| 559 | + | |
| 560 | + | |
561 | 561 | | |
562 | 562 | | |
563 | 563 | | |
564 | | - | |
| 564 | + | |
565 | 565 | | |
566 | 566 | | |
567 | 567 | | |
| |||
570 | 570 | | |
571 | 571 | | |
572 | 572 | | |
573 | | - | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
574 | 577 | | |
575 | | - | |
| 578 | + | |
576 | 579 | | |
577 | 580 | | |
578 | 581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| |||
0 commit comments