Deneche A. Hakim created DRILL-4267:
---------------------------------------

             Summary: Multiple window function operators instead of one
                 Key: DRILL-4267
                 URL: https://issues.apache.org/jira/browse/DRILL-4267
             Project: Apache Drill
          Issue Type: Bug
          Components: Query Planning & Optimization
    Affects Versions: 1.5.0
            Reporter: Deneche A. Hakim
            Priority: Minor


Changing the order of window functions in a query changes the number of window 
function operators in the plan.

The following query generates a plan with a single window function operator:
{noformat}
0: jdbc:drill:zk=local> EXPLAIN PLAN FOR SELECT ROW_NUMBER() OVER w, COUNT(*) 
OVER w FROM cp.`employee.json` WINDOW w AS (PARTITION BY position_id ORDER BY 
salary);
+------+------+
| text | json |
+------+------+
| 00-00    Screen
00-01      Project(EXPR$0=[$0], EXPR$1=[$1])
00-02        Project(EXPR$0=[$0], EXPR$1=[$1])
00-03          Project($0=[$2], $1=[$3])
00-04            Window(window#0=[window(partition {0} order by [1] rows 
between UNBOUNDED PRECEDING and CURRENT ROW aggs [ROW_NUMBER(), COUNT()])])
00-05              SelectionVectorRemover
00-06                Sort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[ASC])
00-07                  Scan(groupscan=[EasyGroupScan 
[selectionRoot=classpath:/employee.json, numFiles=1, columns=[`position_id`, 
`salary`], files=[classpath:/employee.json]]])
{noformat}

But when we permute the window functions in the query we get 2 window function 
operators in the plan:
{noformat}
0: jdbc:drill:zk=local> EXPLAIN PLAN FOR SELECT COUNT(*) OVER w, ROW_NUMBER() 
OVER w FROM cp.`employee.json` WINDOW w AS (PARTITION BY position_id ORDER BY 
salary);
+------+------+
| text | json |
+------+------+
| 00-00    Screen
00-01      Project(EXPR$0=[$0], EXPR$1=[$1])
00-02        Project(EXPR$0=[$0], EXPR$1=[$1])
00-03          Project($0=[$2], $1=[$3])
00-04            Window(window#0=[window(partition {0} order by [1] rows 
between UNBOUNDED PRECEDING and CURRENT ROW aggs [ROW_NUMBER()])])
00-05              Window(window#0=[window(partition {0} order by [1] range 
between UNBOUNDED PRECEDING and CURRENT ROW aggs [COUNT()])])
00-06                SelectionVectorRemover
00-07                  Sort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[ASC])
00-08                    Scan(groupscan=[EasyGroupScan 
[selectionRoot=classpath:/employee.json, numFiles=1, columns=[`position_id`, 
`salary`], files=[classpath:/employee.json]]])
{noformat}




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to