Only apply transformGroupedWindows() with ORCA. (#10306)
* Only apply transformGroupedWindows() with ORCA. The Postgres planner doesn't need it. Move the code to do it, so that it's only used before passing a tree to ORCA. This doesn't change anything with ORCA, but with the Postgres planner, it has some benefits: * Some cases before this patch do not give correct results and now they run correctly (e.g. case `regress/olap_window_seq`) * Fixes github issue #10143. * Make transformGroupedWindows walk the entire tree The transformGroupedWindows function now recursively transforms any Query node in the tree that has both window functions and groupby or aggregates. Also fixed a pre-existing bug where we put a subquery in the target list of such a Query node into the upper query, Q'. This meant that any outer references to the scope of Q' no longer had the correct varattno. The fix is to place the subquery into the target list of the lower query, Q'' instead, which has the same range table as the original query Q. Therefore, the varattnos to outer references to the scope of Q (now Q'') don't need to be updated. Note that varlevelsup to scopes above Q still need to be adjusted, since we inserted a new scope Q'. (See comments in code for explanations of Q, Q', Q''). Co-authored-by: NHeikki Linnakangas <hlinnakangas@pivotal.io> Co-authored-by: NHans Zeller <hzeller@vmware.com> Co-authored-by: NAbhijit Subramanya <asubramanya@pivotal.io>
Showing
想要评论请 注册 或 登录