alamb commented on code in PR #13032:
URL: https://github.com/apache/datafusion/pull/13032#discussion_r1809521444
##########
datafusion/sqllogictest/test_files/cse.slt:
##########
@@ -199,18 +199,18 @@ physical_plan
# Surely only once but also conditionally evaluated subexpressions
query TT
EXPLAIN SELECT
- (a = 1 OR random() = 0) AND (a = 1 OR random() = 1) AS c1,
- (a = 2 AND random() = 0) OR (a = 2 AND random() = 1) AS c2,
+ (a = 1 OR random() = 0) AND (a = 2 OR random() = 1) AS c1,
Review Comment:
Why this change?
I ran the test locally for the original and here it is
```sql
query TT
EXPLAIN SELECT
(a = 1 OR random() = 0) AND (a = 1 OR random() = 1) AS c1,
(a = 2 AND random() = 0) OR (a = 2 AND random() = 1) AS c2,
CASE WHEN a + 3 = 0 THEN a + 3 + random() ELSE 0 END AS c3,
CASE WHEN a + 4 = 0 THEN 0 ELSE a + 4 + random() END AS c4
FROM t1
----
logical_plan
01)Projection: (__common_expr_1 OR random() = Float64(0)) AND
(__common_expr_1 OR random() = Float64(1)) AS c1, t1.a = Float64(2) AND
(random() = Float64(0) OR random() = Float64(1)) AS c2, CASE WHEN
__common_expr_2 = Float64(0) THEN __common_expr_2 + random() ELSE Float64(0)
END AS c3, CASE WHEN __common_expr_3 = Float64(0) THEN Float64(0) ELSE
__common_expr_3 + random() END AS c4
02)--Projection: t1.a = Float64(1) AS __common_expr_1, t1.a + Float64(3) AS
__common_expr_2, t1.a + Float64(4) AS __common_expr_3, t1.a
03)----TableScan: t1 projection=[a]
physical_plan
01)ProjectionExec: expr=[(__common_expr_1@0 OR random() = 0) AND
(__common_expr_1@0 OR random() = 1) as c1, a@3 = 2 AND (random() = 0 OR
random() = 1) as c2, CASE WHEN __common_expr_2@1 = 0 THEN __common_expr_2@1 +
random() ELSE 0 END as c3, CASE WHEN __common_expr_3@2 = 0 THEN 0 ELSE
__common_expr_3@2 + random() END as c4]
02)--ProjectionExec: expr=[a@0 = 1 as __common_expr_1, a@0 + 3 as
__common_expr_2, a@0 + 4 as __common_expr_3, a@0 as a]
03)----MemoryExec: partitions=1, partition_sizes=[0]
```
@peter-toth does this look right to you?
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -850,6 +854,27 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for
Simplifier<'a, S> {
op: Or,
right,
}) if is_op_with(And, &left, &right) => Transformed::yes(*right),
+ // Elliminate common factors in conjunctions e.g
Review Comment:
```suggestion
// Eliminate common factors in conjunctions e.g
```
##########
datafusion/optimizer/src/optimizer.rs:
##########
@@ -255,7 +254,6 @@ impl Optimizer {
// run it again after running the optimizations that potentially
converted
// subqueries to joins
Arc::new(SimplifyExpressions::new()),
- Arc::new(RewriteDisjunctivePredicate::new()),
Review Comment:
🥳 -- thank you @eejbyfeldt
--
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]