Fix #10437, CR fixes

This commit is contained in:
Mikhail Filimonov 2020-07-06 19:24:33 +02:00
parent 6e599533a7
commit 8038383f06
5 changed files with 52 additions and 6 deletions

View File

@ -161,7 +161,6 @@ protected:
private: private:
/* Saving thread data */ /* Saving thread data */
Context & context; Context & context;
Context insert_context;
const StorageID table_id; const StorageID table_id;
const String storage_def; const String storage_def;
StoragePtr table; StoragePtr table;
@ -208,13 +207,11 @@ SystemLog<LogElement>::SystemLog(Context & context_,
const String & storage_def_, const String & storage_def_,
size_t flush_interval_milliseconds_) size_t flush_interval_milliseconds_)
: context(context_) : context(context_)
, insert_context(Context(context_))
, table_id(database_name_, table_name_) , table_id(database_name_, table_name_)
, storage_def(storage_def_) , storage_def(storage_def_)
, flush_interval_milliseconds(flush_interval_milliseconds_) , flush_interval_milliseconds(flush_interval_milliseconds_)
{ {
assert(database_name_ == DatabaseCatalog::SYSTEM_DATABASE); assert(database_name_ == DatabaseCatalog::SYSTEM_DATABASE);
insert_context.makeQueryContext(); // we need query context to do inserts to target table with MV containing subqueries or joins
log = &Poco::Logger::get("SystemLog (" + database_name_ + "." + table_name_ + ")"); log = &Poco::Logger::get("SystemLog (" + database_name_ + "." + table_name_ + ")");
} }
@ -428,6 +425,10 @@ void SystemLog<LogElement>::flushImpl(const std::vector<LogElement> & to_flush,
insert->table_id = table_id; insert->table_id = table_id;
ASTPtr query_ptr(insert.release()); ASTPtr query_ptr(insert.release());
// we need query context to do inserts to target table with MV containing subqueries or joins
auto insert_context = Context(context);
insert_context.makeQueryContext();
InterpreterInsertQuery interpreter(query_ptr, insert_context); InterpreterInsertQuery interpreter(query_ptr, insert_context);
BlockIO io = interpreter.execute(); BlockIO io = interpreter.execute();

View File

@ -713,7 +713,10 @@ void StorageBuffer::writeBlockToDestination(const Block & block, StoragePtr tabl
for (const auto & column : block_to_write) for (const auto & column : block_to_write)
list_of_columns->children.push_back(std::make_shared<ASTIdentifier>(column.name)); list_of_columns->children.push_back(std::make_shared<ASTIdentifier>(column.name));
InterpreterInsertQuery interpreter{insert, global_context, allow_materialized}; auto insert_context = Context(global_context);
insert_context.makeQueryContext();
InterpreterInsertQuery interpreter{insert, insert_context, allow_materialized};
auto block_io = interpreter.execute(); auto block_io = interpreter.execute();
block_io.out->writePrefix(); block_io.out->writePrefix();

View File

@ -4,6 +4,10 @@ DROP TABLE IF EXISTS expected_times;
CREATE TABLE expected_times (QUERY_GROUP_ID String, max_query_duration_ms UInt64) Engine=Memory; CREATE TABLE expected_times (QUERY_GROUP_ID String, max_query_duration_ms UInt64) Engine=Memory;
INSERT INTO expected_times VALUES('main_dashboard_top_query', 100), ('main_dashboard_bottom_query', 100); INSERT INTO expected_times VALUES('main_dashboard_top_query', 100), ('main_dashboard_bottom_query', 100);
SET log_queries=1;
SELECT 1;
SYSTEM FLUSH LOGS;
CREATE MATERIALIZED VIEW slow_log Engine=Memory AS CREATE MATERIALIZED VIEW slow_log Engine=Memory AS
( (
SELECT * FROM SELECT * FROM
@ -18,8 +22,6 @@ CREATE MATERIALIZED VIEW slow_log Engine=Memory AS
WHERE query_duration_ms > max_query_duration_ms WHERE query_duration_ms > max_query_duration_ms
); );
SET log_queries=1;
SELECT 1 /* QUERY_GROUP_ID:main_dashboard_top_query */; SELECT 1 /* QUERY_GROUP_ID:main_dashboard_top_query */;
SELECT 1 /* QUERY_GROUP_ID:main_dashboard_bottom_query */; SELECT 1 /* QUERY_GROUP_ID:main_dashboard_bottom_query */;

View File

@ -0,0 +1,37 @@
DROP TABLE IF EXISTS t1_01361;
DROP TABLE IF EXISTS t2_01361;
DROP TABLE IF EXISTS mv1_01361;
DROP TABLE IF EXISTS b1_01361;
CREATE TABLE t1_01361 (
i UInt32,
time DateTime
) ENGINE = MergeTree()
PARTITION BY time
ORDER BY time;
CREATE TABLE t2_01361 (
i UInt32,
time DateTime
) ENGINE = MergeTree()
PARTITION BY time
ORDER BY time;
CREATE MATERIALIZED VIEW mv1_01361
TO t2_01361
AS SELECT * FROM (SELECT * FROM t1_01361);
CREATE TABLE b1_01361 AS t1_01361
ENGINE = Buffer(currentDatabase(), t1_01361, 1, 0, 0, 1, 1, 1, 1);
INSERT INTO b1_01361 VALUES (1, now());
INSERT INTO b1_01361 VALUES (2, now());
SELECT count() FROM b1_01361;
SELECT count() FROM t1_01361;
SELECT count() FROM t2_01361;
DROP TABLE IF EXISTS t1_01361;
DROP TABLE IF EXISTS t2_01361;
DROP TABLE IF EXISTS mv1_01361;
DROP TABLE IF EXISTS b1_01361;