Agree with Julian, RexProgram could do this work.

I did this before in physical codegen based on Calc's RexProgram, and it
works very well.

Julian Hyde <jhyde.apa...@gmail.com> 于2022年7月14日周四 23:21写道:

> It seems that you are tackling common scalar expressions (RexNodes)
> whereas, based on the name the other rule is dealing with common relational
> expressions (RelNode).
>
> For your rule, consider using RexProgram, RexProgramBuilder, and Calc.
> They already convert a list of expressions to a DAG, so that no expression
> is calculated more than once.
>
> Julian
>
> > On Jul 14, 2022, at 06:31, Jiajun Xie <jiajunbernou...@gmail.com> wrote:
> >
> > Hello, all~
> >  I am writing an RelOptRule that is for CommonSubExpressions. Here is an
> > example that I completed.
> >    sql:  `select sal, sal * 12, sal * 3, sal * 12 + sal * 3 from emp`
> >    planBefore: ```LogicalProject(SAL=[$5], EXPR$1=[*($5, 12)],
> > EXPR$2=[*($5, 3)], EXPR$3=[+(*($5, 12), *($5, 3))])
> >  LogicalTableScan(table=[[CATALOG, SALES, EMP]])```
> >    planAfter: ```LogicalProject(SAL=[$0], EXPR$1=[$1], EXPR$2=[$2],
> > EXPR$3=[+($1, $2)])
> > LogicalProject(SAL=[$5], CSE$0=[*($5, 12)], CSE$1=[*($5, 3)])
> >   LogicalTableScan(table=[[CATALOG, SALES, EMP]])```
> >  I found a RelOptRule that is named as CommonRelSubExprRule, but it is
> > abstract. I wonder if anyone has implemented it? Is it the same as what I
> > am doing?
> >  Thanks very much~
>


-- 

Best,
Benchao Li

Reply via email to