• Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.4.2, 3.5.0
    • 3.5.0
    • SQL
    • None


      Current LCA resolution has a limitation, that it can't resolve the query, when it satisfies all the following criteria:

      1. the main (outer) query has having clause
      2. there is a window expression in the query
      3. in the same SELECT list as the window expression in 2), there is an lca

      This is because LCA won't rewrite plan until UNRESOLVED_HAVING is resolved; window expressions won't be extracted until LCA in the same SELECT lists are rewritten; however UNRESOLVED_HAVING depends on the child to be resolved, which could include the Window. It becomes a deadlock.

      We should ease some limitation on the LCA resolution regarding to having, to break the deadlock for most cases.

      For example, for the following query:

      create table t (col boolean) using orc;
      with w AS (
        select min(col) over () as min_alias,
        min_alias as col_alias
        FROM t
      select col_alias
      from w
      having count > 0;

      It now throws confusing error message:

      [UNRESOLVED_COLUMN.WITH_SUGGESTION] A column or function parameter with name `col_alias` 
      cannot be resolved. Did you mean one of the following? [`col_alias`, `min_alias`].

      The LCA and window is in a CTE that is completely unrelated to the having. LCA should resolve in this case.




            xyyu Xinyi Yu
            xyyu Xinyi Yu
            0 Vote for this issue
            3 Start watching this issue