[ https://issues.apache.org/jira/browse/CALCITE-6011?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stamatis Zampetakis resolved CALCITE-6011. ------------------------------------------ Resolution: Fixed Fixed in [bdafeec27c529d0089434a4d8b0fc7a1e49efcd1|https://github.com/apache/calcite/commit/bdafeec27c529d0089434a4d8b0fc7a1e49efcd1]. Thanks for the PR [~shenlang]! > Add the planner rule that pushes the Filter past a Window > --------------------------------------------------------- > > Key: CALCITE-6011 > URL: https://issues.apache.org/jira/browse/CALCITE-6011 > Project: Calcite > Issue Type: New Feature > Components: core > Reporter: LakeShen > Assignee: LakeShen > Priority: Major > Labels: pull-request-available > Fix For: 1.36.0 > > > The Filter condition could be pushed past the Window when condition used > columns is window partition columns. > For example: > {code:java} > SELECT > * > FROM > ( > SELECT > custkey, > orderkey, > rank() OVER ( > PARTITION BY custkey > ORDER BY > orderdate ASC > ) > FROM > orders > ) > WHERE > custkey = 0 > AND orderkey > 0 {code} > The plan tree: > {code:java} > LogicalProject(custkey=[0], orderkey=[$1], EXPR$2=[$2]) > LogicalFilter(condition=[AND(=($0, 0), >($1, 0))]) > LogicalProject(custkey=[$1], orderkey=[$0], EXPR$2=[$3]) > LogicalWindow(window#0=[window(partition {1} order by [2] aggs > [RANK()])]) > LogicalProject(ORDERKEY=[$0], CUSTKEY=[$1], ORDERDATE=[$4]) > LogicalTableScan(table=[[tpch, ORDERS]]) {code} > Because the window partition columns is custkey,so the condition `custkey = 0 > ` could be pushed down the LogicalWindow. > After that,the plan is : > {code:java} > > LogicalProject(custkey=[0], orderkey=[$1], EXPR$2=[$2]) > LogicalFilter(condition=[>($1, 0)]) > LogicalProject(custkey=[$1], orderkey=[$0], EXPR$2=[$3]) > LogicalWindow(window#0=[window(partition {1} order by [2] aggs > [RANK()])]) > LogicalFilter(condition=[=($1, 0)]) > LogicalProject(ORDERKEY=[$0], CUSTKEY=[$1], ORDERDATE=[$4]) > LogicalTableScan(table=[[tpch, ORDERS]]) > {code} > > > -- This message was sent by Atlassian Jira (v8.20.10#820010)