Merge pull request #58875 from ClickHouse/fix-indexhint-rpn-builder

Fix RPN construction for indexHint
This commit is contained in:
Dmitry Novik 2024-01-17 12:24:28 +01:00 committed by GitHub
commit a5e0be484a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 40 additions and 0 deletions

View File

@ -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>
@ -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();
}
}
@ -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);
}
}

View File

@ -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);