[ 
https://issues.apache.org/jira/browse/CALCITE-4803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17437136#comment-17437136
 ] 

Julian Hyde edited comment on CALCITE-4803 at 11/2/21, 4:48 AM:
----------------------------------------------------------------

Should or must? That's the big question.

For example, suppose I apply {{FilterMergeRule}} to {{Filter(x > 1, Filter(x > 
5, R))}}. The top filter is removed (because its condition is already satisfied 
by all rows coming from the middle filter). The middle filter has different 
field names. Is the rule supposed to add another {{Project}}, just to keep the 
field names the same? I think that would be ridiculous.

You all know about {{RelRoot}}?


was (Author: julianhyde):
Should or must? That's the big question.

> RelNode lost alias after remove Project operator
> ------------------------------------------------
>
>                 Key: CALCITE-4803
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4803
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: xzh_dz
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
>  In my project, I often use `RelOptRule` to optimize relational algebra. In 
> the process of materialized view optimization, after removing the `Project 
> operator`, I found that RelNode lost its alias and their relational algebra 
> is not equivalent.Examples can be reproduced as follows.
>  
> {code:java}
> // code placeholder
> org.apache.calcite.test.SqlToRelConverterTest
> @Test void testLoseAlias() {
>   final String sql = "select ename as e, deptno as d, count(distinct empno) 
> from emp group by ename, deptno";
>   final RelNode rel = tester.convertSqlToRel(sql).rel;
>   // LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT(DISTINCT $2)])
>   //  LogicalProject(E=[$1], D=[$7], EMPNO=[$0])
>   //    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>   System.out.println(RelOptUtil.toString(rel));
>   final HepProgramBuilder programBuilder = HepProgram.builder();
>   programBuilder.addRuleInstance(CoreRules.AGGREGATE_PROJECT_MERGE);
>   final HepPlanner planner = new HepPlanner(programBuilder.build());
>   planner.setRoot(rel);
>   final RelNode relOpt = planner.findBestExp();
>   //LogicalAggregate(group=[{1, 7}], EXPR$2=[COUNT(DISTINCT $0)])
>   //  LogicalTableScan(table=[[CATALOG, SALES, EMP]])
>   System.out.println(RelOptUtil.toString(relOpt));
>   // [ENAME, DEPTNO, EXPR$2]
>   System.out.println(relOpt.getRowType().getFieldNames());
> }
> {code}
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to