Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when indexHint() is used #58911

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Interpreters/ActionsDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2542,10 +2542,16 @@ ActionsDAGPtr ActionsDAG::buildFilterActionsDAG(
{
if (const auto * index_hint = typeid_cast<const FunctionIndexHint *>(adaptor->getFunction().get()))
{
auto index_hint_filter_dag = buildFilterActionsDAG(index_hint->getActions()->getOutputs(),
node_name_to_input_node_column,
context,
false /*single_output_condition_node*/);
ActionsDAGPtr index_hint_filter_dag;
const auto & index_hint_args = index_hint->getActions()->getOutputs();

if (index_hint_args.empty())
index_hint_filter_dag = std::make_shared<ActionsDAG>();
else
index_hint_filter_dag = buildFilterActionsDAG(index_hint_args,
node_name_to_input_node_column,
context,
false /*single_output_condition_node*/);

auto index_hint_function_clone = std::make_shared<FunctionIndexHint>();
index_hint_function_clone->setActions(std::move(index_hint_filter_dag));
Expand Down
6 changes: 6 additions & 0 deletions src/Storages/MergeTree/RPNBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ class RPNBuilder
rpn_elements.emplace_back(std::move(element));
}

if (arguments_size == 0 && function_node.getFunctionName() == "indexHint")
{
element.function = RPNElement::ALWAYS_TRUE;
rpn_elements.emplace_back(std::move(element));
}

return;
}
}
Expand Down
Empty file.
16 changes: 16 additions & 0 deletions tests/queries/0_stateless/02967_index_hint_crash.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE tab
(
`foo` Array(LowCardinality(String)),
INDEX idx foo TYPE bloom_filter GRANULARITY 1
)
ENGINE = MergeTree
PRIMARY KEY tuple();

INSERT INTO tab SELECT if(number % 2, ['value'], [])
FROM system.numbers
LIMIT 10000;

SELECT *
FROM tab
PREWHERE indexHint()
FORMAT Null;