Skip to content

Commit

Permalink
Merge pull request duckdb#12189 from gitccl/issue_12181
Browse files Browse the repository at this point in the history
Fix move constants optimization
  • Loading branch information
Mytherin authored May 22, 2024
2 parents 70fd6a8 + b7c4d95 commit 9584ad0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/optimizer/rule/move_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ unique_ptr<Expression> MoveConstantsRule::Apply(LogicalOperator &op, vector<refe
D_ASSERT(arithmetic.return_type.IsIntegral());
D_ASSERT(arithmetic.children[0]->return_type.IsIntegral());
if (inner_constant.value.IsNull() || outer_constant.value.IsNull()) {
if (comparison.type == ExpressionType::COMPARE_DISTINCT_FROM ||
comparison.type == ExpressionType::COMPARE_NOT_DISTINCT_FROM) {
return nullptr;
}
return make_uniq<BoundConstantExpression>(Value(comparison.return_type));
}
auto &constant_type = outer_constant.return_type;
Expand Down
22 changes: 22 additions & 0 deletions test/optimizer/issue_12181.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# name: test/optimizer/issue_12181.test
# description: Test move constants optimization involving DISTINCT FROM comparison
# group: [optimizer]

statement ok
CREATE TABLE t0(c0 INT)

statement ok
CREATE TABLE t1(c0 INT, c1 INT)

statement ok
INSERT INTO t1(c0, c1) VALUES (0, 1)

query I
SELECT NULL IS DISTINCT FROM (1 + t1.c1) FROM t1 NATURAL LEFT JOIN t0
----
true

query II
SELECT * FROM t0 NATURAL RIGHT JOIN t1 WHERE (CASE t0.c0 WHEN t0.c0 THEN 1 ELSE NULL END) IS DISTINCT FROM (1 + (CASE t1.c1 WHEN t1.c1 THEN 2 ELSE NULL END))
----
0 1

0 comments on commit 9584ad0

Please sign in to comment.