Merge pull request #51205 from ClickHouse/set-index-nullable-atoms

Fix Set index with constant nullable comparison.
This commit is contained in:
Nikolai Kochetov 2023-06-26 16:33:36 +02:00 committed by GitHub
commit b10bcbc7f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -554,7 +554,10 @@ void MergeTreeIndexConditionSet::traverseAST(ASTPtr & node) const
if (atomFromAST(node))
{
if (node->as<ASTIdentifier>() || node->as<ASTFunction>())
node = makeASTFunction("__bitWrapperFunc", node);
/// __bitWrapperFunc* uses default implementation for Nullable types
/// Here we additionally convert Null to 0,
/// otherwise condition 'something OR NULL' will always return Null and filter everything.
node = makeASTFunction("__bitWrapperFunc", makeASTFunction("ifNull", node, std::make_shared<ASTLiteral>(Field(0))));
}
else
node = std::make_shared<ASTLiteral>(UNKNOWN_FIELD);

View File

@ -0,0 +1,15 @@
drop table if exists test_table;
CREATE TABLE test_table
(
col1 String,
col2 String,
INDEX test_table_col2_idx col2 TYPE set(0) GRANULARITY 1
) ENGINE = MergeTree()
ORDER BY col1
AS SELECT 'v1', 'v2';
SELECT * FROM test_table
WHERE 1 == 1 AND col1 == col1 OR
0 AND col2 == NULL;
drop table if exists test_table;