diff --git a/src/Storages/MergeTree/KeyCondition.cpp b/src/Storages/MergeTree/KeyCondition.cpp index 996c6bc01ee..07298593abb 100644 --- a/src/Storages/MergeTree/KeyCondition.cpp +++ b/src/Storages/MergeTree/KeyCondition.cpp @@ -683,7 +683,7 @@ static const ActionsDAG::Node & cloneASTWithInversionPushDown( return arg; } - if (isLogicalOperator(name)) + if (isLogicalOperator(name) && need_inversion) { ActionsDAG::NodeRawConstPtrs children(node.children); @@ -869,6 +869,8 @@ KeyCondition::KeyCondition( { auto inverted_dag = cloneASTWithInversionPushDown(std::move(dag_nodes.nodes), context); + // std::cerr << "========== inverted dag: " << inverted_dag->dumpDAG() << std::endl; + Block empty; for (const auto * node : inverted_dag->getIndex()) traverseAST(Tree(node), context, empty); diff --git a/tests/queries/0_stateless/00160_merge_and_index_in_in.sql b/tests/queries/0_stateless/00160_merge_and_index_in_in.sql index bdab3f7640d..3ed829c4d59 100644 --- a/tests/queries/0_stateless/00160_merge_and_index_in_in.sql +++ b/tests/queries/0_stateless/00160_merge_and_index_in_in.sql @@ -9,6 +9,7 @@ SET max_block_size = 1000000; INSERT INTO mt_00160 (x) SELECT number AS x FROM system.numbers LIMIT 100000; SELECT *, b FROM mt_00160 WHERE x IN (12345, 67890) AND NOT ignore(blockSize() < 10 AS b) ORDER BY x; +SET query_plan_optimize_primary_key = 0; -- Need separate query plan step for merge SELECT *, b FROM merge_00160 WHERE x IN (12345, 67890) AND NOT ignore(blockSize() < 10 AS b) ORDER BY x; DROP TABLE merge_00160;