pepijnve commented on code in PR #25456:
URL: https://github.com/apache/datafusion/pull/25456#discussion_r4045318003


##########
datafusion/optimizer/src/projection_inliner.rs:
##########
@@ -0,0 +1,497 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! A single, cost-aware check for rewriting expressions through a projection.
+//!
+//! Many rules move an expression that is written over the output of a
+//! projection below that projection, or merge it into the projection. To do
+//! this, they replace each column reference with the expression that defines
+//! the column. This is called *inlining*.
+//!
+//! Inlining can make the plan evaluate a definition more times than before:
+//!
+//! - The consumer can reference the column more than one time.
+//! - The projection can stay in the plan and still compute the definition.
+//!
+//! When the definition is volatile, this changes the query result. When the
+//! definition is expensive, this makes the query slower. A typical example is 
a
+//! column that [`CommonSubexprEliminate`] created on purpose, so that an
+//! expensive expression is computed one time only.
+//!
+//! [`ProjectionInliner`] is the one place that makes this decision. Rules call
+//! it instead of doing the substitution themselves.
+//!
+//! [`CommonSubexprEliminate`]: 
crate::common_subexpr_eliminate::CommonSubexprEliminate
+
+use std::collections::{HashMap, HashSet};
+
+use datafusion_common::tree_node::{
+    Transformed, TransformedResult, TreeNode, TreeNodeRecursion,
+};
+use datafusion_common::{Column, Result};
+use datafusion_expr::{Expr, ExpressionPlacement, Projection};
+
+/// The cost of one more evaluation of an expression.
+///
+/// The variants are in increasing order of cost.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
+pub(crate) enum DuplicationCost {

Review Comment:
   This enumeration seems to overlap largely with the existing expression 
placement enumeration. Are those two trying to express the same thing or is 
there a fundamental semantic difference?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to