1. I think so. 2. In my view, as long as we ensure the top-level Project is restored after Planner (some Calcite users might output RelNode), it should be fine.
3. RelBuilder#Project will optimize identity nodes. You can set force=true to force building a Project or directly call LogicalProject#create. I think we can add this utility method in Calcite: 1. When the top level is a Project, merge the Project to preserve aliases 2. When the top level is a Sort, call this method on its input 3. For other cases, directly add a Project to restore aliases On 2025/06/26 07:24:48 Yanjing Wang wrote: > > > > > > Dear Julian and Mihai, Thank you both for your detailed and insightful > > responses. I'd like to confirm my understanding: 1. Regarding column name > > preservation approach: - If I understand correctly, using RelRoot to get a > > projected rel node of the best rel would be the recommended way to preserve > > column names of rel after optimization? 2. About subquery generation: - I > > see that subquery generation is controlled by RelToSqlConverter, so I > > should focus on making adjustments there to control the subquery generation > > behavior for Project <- Sort rel pattern. 3. One observation I'd like to > > share: - I noticed that when I tried using a rel builder to add a project > > to the best rel (specifically when the best rel is a sort), adding a > > project to the sort input rel doesn't seem to make a difference in the > > outcome. Could you please confirm if my understanding aligns with your > > suggestions? This would help ensure I'm moving in the right direction with > > the implementation. Best regards, Yanjing >