MohamedAbdeen21 commented on code in PR #10868: URL: https://github.com/apache/datafusion/pull/10868#discussion_r1636695281
########## datafusion/optimizer/src/common_subexpr_eliminate.rs: ########## @@ -166,6 +166,15 @@ impl CommonSubexprEliminate { ) -> Result<(Vec<Vec<Expr>>, LogicalPlan)> { let mut common_exprs = IndexMap::new(); + input.schema().iter().for_each(|(qualifier, field)| { Review Comment: Both issues don't affect correctness. One thing I'd like to point out is that adding unused columns (all input's columns) in intermediate projection is the behavior of current CSE, it's not introduced in this PR. You can try copying the new test and running it against main. You'll get this output. ```rs let plan = LogicalPlanBuilder::from(table_scan.clone()) .project(vec![(col("a") + col("b")).alias("#1"), col("c")])? .project(vec![ (col("c") + lit(2)).alias("c3"), (col("c") + lit(2)).alias("c4"), ])? .build()?; ``` ``` Projection: {test.c + Int32(2)|{Int32(2)}|{test.c}} AS test.c + Int32(2) AS c3, {test.c + Int32(2)|{Int32(2)}|{test.c}} AS test.c + Int32(2) AS c4 Projection: test.c + Int32(2) AS {test.c + Int32(2)|{Int32(2)}|{test.c}}, #1, test.c Projection: test.a + test.b AS #1, test.c TableScan: test ``` Extra projections are removed by other rules, so the final plan doesn't contain these projections. Also, you may have noticed that extra projections make the aliases "out-of-sync" and to be honest I don't mind the `#2` instead of `#1` (as long as it's not something ridiculous like `#1023` for example), and I don't see a way to fix that without patching some hacky global state/counter or asking other rules to reuse aliases when removing the extra projections. -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org