fix union all bug #1059

This commit is contained in:
leozhang 2017-09-12 18:10:25 +08:00 committed by alexey-milovidov
parent e0a1e6982b
commit a80ebcdbc2
2 changed files with 21 additions and 1 deletions

View File

@ -100,7 +100,7 @@ void InterpreterSelectQuery::init(const BlockInputStreamPtr & input, const Names
}
}
if (is_first_select_inside_union_all && hasAsterisk())
if (is_first_select_inside_union_all && (hasAsterisk() || hasAggregation(&query)))
{
basicInit(input);
@ -126,6 +126,25 @@ void InterpreterSelectQuery::init(const BlockInputStreamPtr & input, const Names
}
}
bool InterpreterSelectQuery::hasAggregation(ASTSelectQuery * query_ptr){
if(!query_ptr) {
return false;
}
if(query_ptr->group_expression_list || query_ptr->having_expression) {
return true;
}
ASTPtr tail = query_ptr->next_union_all;
while(tail) {
ASTPtr head = tail;
ASTSelectQuery & head_query = static_cast<ASTSelectQuery &>(*head);
if(head_query.group_expression_list || head_query.having_expression) {
return true;
}
tail = head_query.next_union_all;
}
return false;
}
void InterpreterSelectQuery::basicInit(const BlockInputStreamPtr & input)
{
auto query_table = query.table();

View File

@ -96,6 +96,7 @@ private:
void init(const BlockInputStreamPtr & input, const Names & required_column_names = Names{});
void basicInit(const BlockInputStreamPtr & input);
void initQueryAnalyzer();
bool hasAggregation(ASTSelectQuery * query_ptr);
/// Execute one SELECT query from the UNION ALL chain.
void executeSingleQuery();