From a80ebcdbc2b4ca6cda5afd64577b08f2bbe3a172 Mon Sep 17 00:00:00 2001 From: leozhang Date: Tue, 12 Sep 2017 18:10:25 +0800 Subject: [PATCH 1/5] fix union all bug #1059 --- .../Interpreters/InterpreterSelectQuery.cpp | 21 ++++++++++++++++++- .../src/Interpreters/InterpreterSelectQuery.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index dcbb35424db..b1eee8fc068 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -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(*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(); diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.h b/dbms/src/Interpreters/InterpreterSelectQuery.h index a7e8ea1445e..28e2226c916 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.h +++ b/dbms/src/Interpreters/InterpreterSelectQuery.h @@ -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(); From af323d4e168957f8e49ba4a72e337217adee59c4 Mon Sep 17 00:00:00 2001 From: alexey-milovidov Date: Tue, 12 Sep 2017 20:04:49 +0300 Subject: [PATCH 2/5] Update InterpreterSelectQuery.cpp --- .../Interpreters/InterpreterSelectQuery.cpp | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index b1eee8fc068..e9b5a12c0b2 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -100,7 +100,7 @@ void InterpreterSelectQuery::init(const BlockInputStreamPtr & input, const Names } } - if (is_first_select_inside_union_all && (hasAsterisk() || hasAggregation(&query))) + if (is_first_select_inside_union_all && (hasAsterisk() || hasAggregation(query))) { basicInit(input); @@ -126,22 +126,15 @@ 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(*head); - if(head_query.group_expression_list || head_query.having_expression) { +bool InterpreterSelectQuery::hasAggregation(const ASTSelectQuery & query_ptr) +{ + for (const IAST * head = query_ptr.get(); head; head = head->next_union_all.get()) + { + const ASTSelectQuery & head_query = static_cast(*head); + if (head_query.group_expression_list || head_query.having_expression) return true; - } - tail = head_query.next_union_all; } + return false; } From c4c8057a280f40fd80736e2ac830b8bd02bad1d2 Mon Sep 17 00:00:00 2001 From: alexey-milovidov Date: Tue, 12 Sep 2017 20:05:14 +0300 Subject: [PATCH 3/5] Update InterpreterSelectQuery.h --- dbms/src/Interpreters/InterpreterSelectQuery.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.h b/dbms/src/Interpreters/InterpreterSelectQuery.h index 28e2226c916..0a7c6227774 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.h +++ b/dbms/src/Interpreters/InterpreterSelectQuery.h @@ -96,7 +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); + bool hasAggregation(const ASTSelectQuery & query_ptr); /// Execute one SELECT query from the UNION ALL chain. void executeSingleQuery(); From 4bf1f39190366acc7d4c6bb1e36ed6453f2deb56 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 12 Sep 2017 20:21:02 +0300 Subject: [PATCH 4/5] Fixed build [#CLICKHOUSE-2]. --- dbms/src/Interpreters/InterpreterSelectQuery.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index e9b5a12c0b2..550213caefc 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -128,12 +128,9 @@ void InterpreterSelectQuery::init(const BlockInputStreamPtr & input, const Names bool InterpreterSelectQuery::hasAggregation(const ASTSelectQuery & query_ptr) { - for (const IAST * head = query_ptr.get(); head; head = head->next_union_all.get()) - { - const ASTSelectQuery & head_query = static_cast(*head); - if (head_query.group_expression_list || head_query.having_expression) + for (const ASTSelectQuery * elem = &query_ptr; elem; elem = static_cast(elem->next_union_all.get())) + if (elem->group_expression_list || elem->having_expression) return true; - } return false; } From 3db51ee3887854051eb8152c8e82f6056f575e0b Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 12 Sep 2017 20:50:32 +0300 Subject: [PATCH 5/5] Fixed typo on the website [#EDIT-25728]. --- website/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/index.html b/website/index.html index ca5364f0802..0a22c5a289e 100644 --- a/website/index.html +++ b/website/index.html @@ -165,7 +165,7 @@ on the market. It processes hundreds of millions to more than a billion rows and tens of gigabytes of data per single server per second.

-

ClickHouse uses all available hardware to it's full potential to process each query as fast as possible. The peak +

ClickHouse uses all available hardware to its full potential to process each query as fast as possible. The peak processing performance for a single query (after decompression, only used columns) stands at more than 2 terabytes per second.