Fix DISTINCT with intersect/except

This commit is contained in:
Igor Nikonov 2023-02-01 13:06:34 +00:00
parent d3d5e67a36
commit fc71acc768

View File

@ -3,6 +3,7 @@
#include <Processors/QueryPlan/DistinctStep.h>
#include <Processors/QueryPlan/ExpressionStep.h>
#include <Processors/QueryPlan/FilterStep.h>
#include <Processors/QueryPlan/IntersectOrExceptStep.h>
#include <Processors/QueryPlan/JoinStep.h>
#include <Processors/QueryPlan/Optimizations/Optimizations.h>
#include <Processors/QueryPlan/UnionStep.h>
@ -44,13 +45,11 @@ size_t tryRemoveRedundantDistinct(QueryPlan::Node * parent_node, QueryPlan::Node
return 0;
/// check if it is preliminary distinct node
QueryPlan::Node * distinct_node = nullptr;
DistinctStep * distinct_step = typeid_cast<DistinctStep *>(parent_node->children.front()->step.get());
QueryPlan::Node * distinct_node = parent_node->children.front();
DistinctStep * distinct_step = typeid_cast<DistinctStep *>(distinct_node->step.get());
if (!distinct_step)
return 0;
distinct_node = parent_node->children.front();
std::vector<ActionsDAGPtr> dag_stack;
const DistinctStep * inner_distinct_step = nullptr;
QueryPlan::Node * node = distinct_node;
@ -59,7 +58,8 @@ size_t tryRemoveRedundantDistinct(QueryPlan::Node * parent_node, QueryPlan::Node
const IQueryPlanStep * current_step = node->step.get();
/// don't try to remove DISTINCT after union or join
if (typeid_cast<const UnionStep *>(current_step) || typeid_cast<const JoinStep *>(current_step))
if (typeid_cast<const UnionStep *>(current_step) || typeid_cast<const JoinStep *>(current_step)
|| typeid_cast<const IntersectOrExceptStep *>(current_step))
break;
if (const auto * const expr = typeid_cast<const ExpressionStep *>(current_step); expr)