Skip to content

Commit

Permalink
Merge pull request ClickHouse#58875 from ClickHouse/fix-indexhint-rpn…
Browse files Browse the repository at this point in the history
…-builder

Fix RPN construction for indexHint
  • Loading branch information
novikd authored Jan 17, 2024
2 parents 2f68086 + 80291ec commit a5e0be4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Storages/MergeTree/RPNBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#include <Columns/ColumnConst.h>
#include <Columns/ColumnSet.h>

#include <Functions/indexHint.h>
#include <Functions/IFunction.h>
#include <Functions/IFunctionAdaptors.h>

#include <Storages/KeyDescription.h>

Expand Down Expand Up @@ -390,6 +392,15 @@ size_t RPNBuilderFunctionTreeNode::getArgumentsSize() const
}
else
{
// indexHint arguments are stored inside of `FunctionIndexHint` class,
// because they are used only for index analysis.
if (dag_node->function_base->getName() == "indexHint")
{
const auto * adaptor = typeid_cast<const FunctionToFunctionBaseAdaptor *>(dag_node->function_base.get());
const auto * index_hint = typeid_cast<const FunctionIndexHint *>(adaptor->getFunction().get());
return index_hint->getActions()->getOutputs().size();
}

return dag_node->children.size();
}
}
Expand All @@ -409,6 +420,15 @@ RPNBuilderTreeNode RPNBuilderFunctionTreeNode::getArgumentAt(size_t index) const
}
else
{
// indexHint arguments are stored inside of `FunctionIndexHint` class,
// because they are used only for index analysis.
if (dag_node->function_base->getName() == "indexHint")
{
const auto * adaptor = typeid_cast<const FunctionToFunctionBaseAdaptor *>(dag_node->function_base.get());
const auto * index_hint = typeid_cast<const FunctionIndexHint *>(adaptor->getFunction().get());
return RPNBuilderTreeNode(index_hint->getActions()->getOutputs()[index], tree_context);
}

return RPNBuilderTreeNode(dag_node->children[index], tree_context);
}
}
Expand Down
Empty file.
20 changes: 20 additions & 0 deletions tests/queries/0_stateless/02962_indexHint_rpn_construction.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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(indexHint(-1, 0.))
WHERE has(foo, 'b');

SELECT *
FROM tab
PREWHERE indexHint(0);

0 comments on commit a5e0be4

Please sign in to comment.