avamingli commented on PR #1284:
URL: https://github.com/apache/cloudberry/pull/1284#issuecomment-3153580599

   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.
   
   Fixed at commit: [Correct parallel window function in CASE 
WHEN.](https://github.com/apache/cloudberry/pull/1284/commits/0791ff62b08743682e81da41e7458e7b39b92d7a)
   
   ```sql
   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)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to