JiajunBernoulli commented on PR #3641:
URL: https://github.com/apache/calcite/pull/3641#issuecomment-1933283166

   > Another question I have is whether this should be as you wrote it in 
RelBuilder, or it should be a rewrite rule in the optimizer. It is a matter of 
design choice rather than of correctness.
   
   Thank you for your review.
   
   1. RelBuilder optimization can reuse subexpressions.
   - Using RelBuilder
   ```
   LogicalProject(DEPTNO=[$0], CDS=[$1], CS=[$2], SDS=[$3], SS=[$3]) -- SDS is 
same as SS
     LogicalAggregate(group=[{0}], CDS=[COUNT($1)], CS=[COUNT()], SDS=[SUM($1)])
       LogicalAggregate(group=[{0, 1}])
         LogicalProject(DEPTNO=[$7], SAL=[$5])
           LogicalTableScan(table=[[CATALOG, SALES, EMP]])
   ```
   - Using Rule
   ```
   LogicalProject(DEPTNO=[$0], CDS=[$1], CS=[$2], SDS=[$3], SS=[$4]) -- SDS is 
same as SS
     LogicalAggregate(group=[{0}], CDS=[COUNT($1)], CS=[COUNT()], 
SDS=[SUM($1)], SS=[SUM($1)])
       LogicalAggregate(group=[{0, 1}])
         LogicalProject(DEPTNO=[$7], SAL=[$5])
           LogicalTableScan(table=[[CATALOG, SALES, EMP]])
   ```
   We need other rules to remove same function.
   
   2. RelBuilder is easier to use than Rule.
   - RelBuilder: `withRedundantDistinct(flag)` to enable or disable.
   - Rule: Add or remove rule in programs.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to