silundong commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4318345704

   > To circumvent the bloat optimizations, it is necessary to provide the 
correlation variables (if they exist) to the builder.
   
   As I mentioned before, I create a temporary `Project` with 
`LogicalProject.create` before correlation detection, instead of using 
`RelBuilder.projectNamed`, just like:
   ```
   RelNode project =
       LogicalProject.create(bb.root(), ImmutableList.of(), exprs, 
uniqueFieldNames,
           ImmutableSet.of());
   
   final RelNode r;
   final CorrelationUse p = getCorrelationUse(bb, project);
   if (p != null) {
     assert p.r instanceof Project;
     // correlation variables have been normalized in p.r, we should use 
expressions
     // in p.r instead of the original exprs
     Project project1 = (Project) p.r;
     r = relBuilder.push(bb.root())
         .projectNamed(project1.getProjects(), uniqueFieldNames, true,
             ImmutableSet.of(p.id))
         .build();
   } else {
     r = relBuilder.push(bb.root()).projectNamed(exprs, uniqueFieldNames, 
true).build();
   }
   ```
   This approach resolves the issue without causing any other test regressions. 
IMO, it's not only effective but also simpler and more intuitive. Do you see 
any drawbacks to it?


-- 
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