Skip to content

Commit

Permalink
Fix an isssue with constants being wrapped in nullables
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-hildred committed Apr 10, 2024
1 parent 626b7b1 commit dfa7a97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Analyzer/Passes/LogicalExpressionOptimizerPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,18 @@ class LogicalExpressionOptimizerVisitor : public InDepthQueryTreeVisitorWithCont
}
}

void leaveImpl(QueryTreeNodePtr & node)
{
if (!need_rerun_resolve)
return;

if (auto * function_node = node->as<FunctionNode>())
rerunFunctionResolve(function_node, getContext());
}

private:
bool need_rerun_resolve = false;

void tryOptimizeAndEqualsNotEqualsChain(QueryTreeNodePtr & node)
{
auto & function_node = node->as<FunctionNode &>();
Expand Down Expand Up @@ -615,6 +626,10 @@ class LogicalExpressionOptimizerVisitor : public InDepthQueryTreeVisitorWithCont

if (!child_function || !isBooleanFunction(child_function->getFunctionName()))
return;

if (function_node.getResultType()->isNullable() && !child_function->getResultType()->isNullable())
need_rerun_resolve = true;

if (maybe_invert)
{
auto not_resolver = FunctionFactory::instance().get("not", getContext());
Expand Down
2 changes: 2 additions & 0 deletions tests/queries/0_stateless/03032_redundant_equals.reference
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
100
101
100
100
101
1
1
1
Expand Down
2 changes: 2 additions & 0 deletions tests/queries/0_stateless/03032_redundant_equals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ SELECT * FROM test_table WHERE (NOT ((k not in (100) = 0) OR (k in (100) = 1)))
SELECT * FROM test_table WHERE (NOT ((k in (101) = 0) OR (k in (100) = 1))) = 1;
SELECT * FROM test_table WHERE ((k not in (101) = 0) OR (k in (100) = 1)) = 1;
SELECT * FROM test_table WHERE ((k not in (99) = 1) AND (k in (100) = 1)) = 1;
SELECT * FROM test_table WHERE ((k not in (101) = toNullable(0)) OR (k in (100) = toNullable(1))) = toNullable(1);


SELECT count()
FROM
Expand Down

0 comments on commit dfa7a97

Please sign in to comment.