mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-13 09:52:38 +00:00
Fix review comments
This commit is contained in:
parent
7b922784e8
commit
82e50fc211
@ -2260,32 +2260,4 @@ ActionsDAGPtr ActionsDAG::buildFilterActionsDAG(
|
|||||||
return result_dag;
|
return result_dag;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ActionsDAG::Node * ActionsDAG::getOriginalNodeForOutputAlias(const String & output_name)
|
|
||||||
{
|
|
||||||
/// find alias in output
|
|
||||||
const Node * output_alias = nullptr;
|
|
||||||
for (const auto * node : outputs)
|
|
||||||
{
|
|
||||||
if (node->result_name == output_name && node->type == ActionsDAG::ActionType::ALIAS)
|
|
||||||
{
|
|
||||||
output_alias = node;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!output_alias)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
/// find original(non alias) node it refers to
|
|
||||||
const Node * node = output_alias;
|
|
||||||
while (node && node->type == ActionsDAG::ActionType::ALIAS)
|
|
||||||
{
|
|
||||||
chassert(!node->children.empty());
|
|
||||||
node = node->children.front();
|
|
||||||
}
|
|
||||||
if (node->type != ActionsDAG::ActionType::INPUT)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -347,9 +347,6 @@ public:
|
|||||||
const std::unordered_map<std::string, ColumnWithTypeAndName> & node_name_to_input_node_column,
|
const std::unordered_map<std::string, ColumnWithTypeAndName> & node_name_to_input_node_column,
|
||||||
const ContextPtr & context);
|
const ContextPtr & context);
|
||||||
|
|
||||||
/// Return original node (input) for alias in output if exists
|
|
||||||
const Node * getOriginalNodeForOutputAlias(const String & output_name);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NodeRawConstPtrs getParents(const Node * target) const;
|
NodeRawConstPtrs getParents(const Node * target) const;
|
||||||
|
|
||||||
|
@ -37,6 +37,34 @@ namespace
|
|||||||
return non_const_columns;
|
return non_const_columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ActionsDAG::Node * getOriginalNodeForOutputAlias(const ActionsDAGPtr & actions, const String & output_name)
|
||||||
|
{
|
||||||
|
/// find alias in output
|
||||||
|
const ActionsDAG::Node * output_alias = nullptr;
|
||||||
|
for (const auto * node : actions->getOutputs())
|
||||||
|
{
|
||||||
|
if (node->result_name == output_name && node->type == ActionsDAG::ActionType::ALIAS)
|
||||||
|
{
|
||||||
|
output_alias = node;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!output_alias)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
/// find original(non alias) node it refers to
|
||||||
|
const ActionsDAG::Node * node = output_alias;
|
||||||
|
while (node && node->type == ActionsDAG::ActionType::ALIAS)
|
||||||
|
{
|
||||||
|
chassert(!node->children.empty());
|
||||||
|
node = node->children.front();
|
||||||
|
}
|
||||||
|
if (node->type != ActionsDAG::ActionType::INPUT)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
bool canRemoveDistinct(const QueryPlan::Node * distinct_node)
|
bool canRemoveDistinct(const QueryPlan::Node * distinct_node)
|
||||||
{
|
{
|
||||||
const DistinctStep * distinct_step = typeid_cast<DistinctStep *>(distinct_node->step.get());
|
const DistinctStep * distinct_step = typeid_cast<DistinctStep *>(distinct_node->step.get());
|
||||||
@ -98,7 +126,7 @@ namespace
|
|||||||
/// compare columns of two DISTINCTs
|
/// compare columns of two DISTINCTs
|
||||||
for (const auto & column : distinct_columns)
|
for (const auto & column : distinct_columns)
|
||||||
{
|
{
|
||||||
const auto * alias_node = path_actions->getOriginalNodeForOutputAlias(String(column));
|
const auto * alias_node = getOriginalNodeForOutputAlias(path_actions, String(column));
|
||||||
if (!alias_node)
|
if (!alias_node)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -129,7 +157,7 @@ size_t tryRemoveRedundantDistinct(QueryPlan::Node * parent_node, QueryPlan::Node
|
|||||||
for (const auto * node : parent_node->children)
|
for (const auto * node : parent_node->children)
|
||||||
{
|
{
|
||||||
/// check if it is distinct node
|
/// check if it is distinct node
|
||||||
if (typeid_cast<const DistinctStep *>(node->step.get()))
|
if (typeid_cast<const DistinctStep *>(node->step.get()) == nullptr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (canRemoveDistinct(node))
|
if (canRemoveDistinct(node))
|
||||||
|
Loading…
Reference in New Issue
Block a user