Skip to content

Commit

Permalink
Fix infinite recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
al13n321 committed May 28, 2024
1 parent 0b9ccbe commit 478aa31
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/Interpreters/ActionsDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2894,6 +2894,7 @@ ActionsDAGPtr ActionsDAG::buildFilterActionsDAG(

FunctionOverloadResolverPtr function_overload_resolver;

String result_name;
if (node->function_base->getName() == "indexHint")
{
ActionsDAG::NodeRawConstPtrs children;
Expand All @@ -2914,6 +2915,11 @@ ActionsDAGPtr ActionsDAG::buildFilterActionsDAG(
auto index_hint_function_clone = std::make_shared<FunctionIndexHint>();
index_hint_function_clone->setActions(std::move(index_hint_filter_dag));
function_overload_resolver = std::make_shared<FunctionToOverloadResolverAdaptor>(std::move(index_hint_function_clone));
/// Keep the unique name like "indexHint(foo)" instead of replacing it
/// with "indexHint()". Otherwise index analysis (which does look at
/// indexHint arguments that we're hiding here) will get confused by the
/// multiple substantially different nodes with the same result name.
result_name = node->result_name;
}
}
}
Expand All @@ -2928,7 +2934,7 @@ ActionsDAGPtr ActionsDAG::buildFilterActionsDAG(
function_base,
std::move(function_children),
std::move(arguments),
{},
result_name,
node->result_type,
all_const);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/Storages/MergeTree/MergeTreeIndexSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ const ActionsDAG::Node * MergeTreeIndexConditionSet::operatorFromDAG(const Actio
return nullptr;

auto function_name = node_to_check->function->getName();
ActionsDAG::NodeRawConstPtrs temp_arguments;
const auto & arguments = getArguments(*node_to_check, result_dag, &temp_arguments);
ActionsDAG::NodeRawConstPtrs temp_ptrs_to_argument;
const auto & arguments = getArguments(*node_to_check, result_dag, &temp_ptrs_to_argument);
size_t arguments_size = arguments.size();

if (function_name == "not")
Expand Down
1 change: 1 addition & 0 deletions tests/queries/0_stateless/03033_set_index_in.reference
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
32768
49152
32768
5 changes: 4 additions & 1 deletion tests/queries/0_stateless/03033_set_index_in.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ insert into a select number, intDiv(number, 4096) from numbers(1000000);
select sum(1+ignore(*)) from a where indexHint(v in (20, 40));
select sum(1+ignore(*)) from a where indexHint(v in (select 20 union all select 40 union all select 60));

SELECT 1 FROM a PREWHERE v IN (SELECT 1) WHERE v IN (SELECT 2);
SELECT 1 FROM a PREWHERE v IN (SELECT 1) WHERE v IN (SELECT 2);

select 1 from a where indexHint(indexHint(materialize(0)));
select sum(1+ignore(*)) from a where indexHint(indexHint(v in (20, 40)));

0 comments on commit 478aa31

Please sign in to comment.