[ 
https://issues.apache.org/jira/browse/CALCITE-6031?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

LakeShen updated CALCITE-6031:
------------------------------
    Description: 
The Filter could be pushed past the Sample.

For example:
{code:java}
select deptno from "scott".dept tablesample system(50) where  deptno > 10{code}
The plan tree is :
{code:java}
 LogicalProject(o_orderkey=[$0])
  LogicalFilter(condition=[>($0, 0)])
    Sample(mode=[system], rate=[0.5], repeatableSeed=[-])
      LogicalTableScan(table=[[tpch, ORDERS]]) {code}
Could be rewrite to :
{code:java}
  LogicalProject(o_orderkey=[$0])
    Sample(mode=[system], rate=[0.5], repeatableSeed=[-])
      LogicalFilter(condition=[>($0, 0)])      
        LogicalTableScan(table=[[tpch, ORDERS]]) {code}
The same logic could see Presto/Trino: 
[PredicatePushDown.Rewriter#visitSample|https://github.com/prestodb/presto/blob/597272cea3eb39c35ed40ffc100f830dd4ab055c/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/PredicatePushDown.java#L1670C9-L1674C10]

  was:
The Filter could be pushed past the Sample.

For example:
{code:java}
select deptno from "scott".dept tablesample system(50) where  deptno > 10{code}
The plan tree is :
{code:java}
 LogicalProject(o_orderkey=[$0])
  LogicalFilter(condition=[>($0, 0)])
    Sample(mode=[system], rate=[0.5], repeatableSeed=[-])
      LogicalTableScan(table=[[tpch, ORDERS]]) {code}
Could be rewrite to :

 
{code:java}
  LogicalProject(o_orderkey=[$0])
    Sample(mode=[system], rate=[0.5], repeatableSeed=[-])
      LogicalFilter(condition=[>($0, 0)])      
        LogicalTableScan(table=[[tpch, ORDERS]]) {code}
 

The same logic could see Presto/Trino: 
[PredicatePushDown.Rewriter#visitSample|https://github.com/prestodb/presto/blob/597272cea3eb39c35ed40ffc100f830dd4ab055c/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/PredicatePushDown.java#L1670C9-L1674C10]


> Add the RelRule that pushes the Filter past a Sample
> ----------------------------------------------------
>
>                 Key: CALCITE-6031
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6031
>             Project: Calcite
>          Issue Type: New Feature
>            Reporter: LakeShen
>            Priority: Major
>
> The Filter could be pushed past the Sample.
> For example:
> {code:java}
> select deptno from "scott".dept tablesample system(50) where  deptno > 
> 10{code}
> The plan tree is :
> {code:java}
>  LogicalProject(o_orderkey=[$0])
>   LogicalFilter(condition=[>($0, 0)])
>     Sample(mode=[system], rate=[0.5], repeatableSeed=[-])
>       LogicalTableScan(table=[[tpch, ORDERS]]) {code}
> Could be rewrite to :
> {code:java}
>   LogicalProject(o_orderkey=[$0])
>     Sample(mode=[system], rate=[0.5], repeatableSeed=[-])
>       LogicalFilter(condition=[>($0, 0)])      
>         LogicalTableScan(table=[[tpch, ORDERS]]) {code}
> The same logic could see Presto/Trino: 
> [PredicatePushDown.Rewriter#visitSample|https://github.com/prestodb/presto/blob/597272cea3eb39c35ed40ffc100f830dd4ab055c/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/PredicatePushDown.java#L1670C9-L1674C10]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to