Skip to content

Commit

Permalink
Fix filtering by tuple (some conditions was lost during analyzing)
Browse files Browse the repository at this point in the history
Fixes: ClickHouse#29281
Fixes: test_cluster_copier/test_three_nodes.py::test
  • Loading branch information
azat committed Oct 10, 2021
1 parent a95c28e commit 6c33eae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Storages/MergeTree/MergeTreeWhereOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool MergeTreeWhereOptimizer::tryAnalyzeTuple(Conditions & res, const ASTFunctio
else if (const auto * child_ident = child->as<ASTIdentifier>())
fetch_sign_column = std::make_shared<ASTIdentifier>(child_ident->name());
else
continue;
return false;

ASTPtr fetch_sign_value = std::make_shared<ASTLiteral>(tuple_lit.at(i));
ASTPtr func_node = makeASTFunction("equals", fetch_sign_column, fetch_sign_value);
Expand Down
1 change: 0 additions & 1 deletion tests/queries/0_stateless/02030_tuple_filter.reference
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
1 A 2021-01-01
1 A 2021-01-01
1 A 2021-01-01
1 A 2021-01-01
7 changes: 6 additions & 1 deletion tests/queries/0_stateless/02030_tuple_filter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ SELECT * FROM test_tuple_filter WHERE (1, 'A') = (id, value);
SELECT * FROM test_tuple_filter WHERE (id, value) = (1, 'A') AND (id, log_date) = (1, '2021-01-01');
SELECT * FROM test_tuple_filter WHERE ((id, value), id * 2) = ((1, 'A'), 2);
SELECT * FROM test_tuple_filter WHERE ((id, value), log_date) = ((1, 'A'), '2021-01-01');
SELECT * FROM test_tuple_filter WHERE (1, (1, (1, (1, (id, value))))) = (1, (1, (1, (1, (1, 'A')))));

-- not supported functions (concat) do not lost
SELECT * FROM test_tuple_filter WHERE (id, value, value||'foo') = ('1', 'A', 'A');

-- Condition fully moved to PREWHERE and such conditions does not supported yet.
SELECT * FROM test_tuple_filter WHERE (1, (1, (1, (1, (id, value))))) = (1, (1, (1, (1, (1, 'A'))))); -- { serverError INDEX_NOT_USED }

-- not implemented yet
SELECT * FROM test_tuple_filter WHERE (1, value) = (id, 'A'); -- { serverError INDEX_NOT_USED }
Expand Down

0 comments on commit 6c33eae

Please sign in to comment.