From c0e3564ff58580893cfd314aafefda7b4c154672 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Fri, 27 Mar 2020 23:10:27 +0800 Subject: [PATCH] Fix scalar optimization in ALTER --- dbms/src/Interpreters/MutationsInterpreter.cpp | 4 ++++ dbms/src/Interpreters/MutationsInterpreter.h | 2 +- .../01220_scalar_optimization_in_alter.reference | 0 .../0_stateless/01220_scalar_optimization_in_alter.sql | 9 +++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 dbms/tests/queries/0_stateless/01220_scalar_optimization_in_alter.reference create mode 100644 dbms/tests/queries/0_stateless/01220_scalar_optimization_in_alter.sql diff --git a/dbms/src/Interpreters/MutationsInterpreter.cpp b/dbms/src/Interpreters/MutationsInterpreter.cpp index 311165066c9..669b72c6317 100644 --- a/dbms/src/Interpreters/MutationsInterpreter.cpp +++ b/dbms/src/Interpreters/MutationsInterpreter.cpp @@ -558,6 +558,10 @@ ASTPtr MutationsInterpreter::prepareInterpreterSelectQuery(std::vector & all_asts->children.push_back(std::make_shared(column)); auto syntax_result = SyntaxAnalyzer(context).analyze(all_asts, all_columns); + if (context.hasQueryContext()) + for (const auto & it : syntax_result->getScalars()) + context.getQueryContext().addScalar(it.first, it.second); + stage.analyzer = std::make_unique(all_asts, syntax_result, context); ExpressionActionsChain & actions_chain = stage.expressions_chain; diff --git a/dbms/src/Interpreters/MutationsInterpreter.h b/dbms/src/Interpreters/MutationsInterpreter.h index a36430e201b..9b12ce79e91 100644 --- a/dbms/src/Interpreters/MutationsInterpreter.h +++ b/dbms/src/Interpreters/MutationsInterpreter.h @@ -47,7 +47,7 @@ private: StoragePtr storage; MutationCommands commands; - const Context & context; + Context context; bool can_execute; ASTPtr mutation_ast; diff --git a/dbms/tests/queries/0_stateless/01220_scalar_optimization_in_alter.reference b/dbms/tests/queries/0_stateless/01220_scalar_optimization_in_alter.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dbms/tests/queries/0_stateless/01220_scalar_optimization_in_alter.sql b/dbms/tests/queries/0_stateless/01220_scalar_optimization_in_alter.sql new file mode 100644 index 00000000000..de92b29ce5d --- /dev/null +++ b/dbms/tests/queries/0_stateless/01220_scalar_optimization_in_alter.sql @@ -0,0 +1,9 @@ +drop table if exists cdp_segments; +drop table if exists cdp_customers; + +create table cdp_segments (seg_id String, mid_seqs AggregateFunction(groupBitmap, UInt32)) engine=ReplacingMergeTree() order by (seg_id); +create table cdp_customers (mid String, mid_seq UInt32) engine=ReplacingMergeTree() order by (mid_seq); +alter table cdp_segments update mid_seqs = bitmapOr(mid_seqs, (select groupBitmapState(mid_seq) from cdp_customers where mid in ('6bf3c2ee-2b33-3030-9dc2-25c6c618d141'))) where seg_id = '1234567890'; + +drop table cdp_segments; +drop table cdp_customers;