From 2c81a35b4ea92d625ebe4c604b838323da2b2bd8 Mon Sep 17 00:00:00 2001 From: Nikolay Degterinsky Date: Wed, 25 Aug 2021 17:41:21 +0300 Subject: [PATCH] Add setting --- src/Core/Settings.h | 1 + src/Interpreters/executeQuery.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/Core/Settings.h b/src/Core/Settings.h index fb1f2ad9001..c33bb2afdd7 100644 --- a/src/Core/Settings.h +++ b/src/Core/Settings.h @@ -176,6 +176,7 @@ class IColumn; M(LogQueriesType, log_queries_min_type, QueryLogElementType::QUERY_START, "Minimal type in query_log to log, possible values (from low to high): QUERY_START, QUERY_FINISH, EXCEPTION_BEFORE_START, EXCEPTION_WHILE_PROCESSING.", 0) \ M(Milliseconds, log_queries_min_query_duration_ms, 0, "Minimal time for the query to run, to get to the query_log/query_thread_log/query_views_log.", 0) \ M(UInt64, log_queries_cut_to_length, 100000, "If query length is greater than specified threshold (in bytes), then cut query when writing to query log. Also limit length of printed query in ordinary text log.", 0) \ + M(Float, log_queries_probability, 1., "Log queries with the specified probabality.", 0) \ \ M(DistributedProductMode, distributed_product_mode, DistributedProductMode::DENY, "How are distributed subqueries performed inside IN or JOIN sections?", IMPORTANT) \ \ diff --git a/src/Interpreters/executeQuery.cpp b/src/Interpreters/executeQuery.cpp index 23fb35deee3..9705360293f 100644 --- a/src/Interpreters/executeQuery.cpp +++ b/src/Interpreters/executeQuery.cpp @@ -56,6 +56,8 @@ #include #include +#include + namespace ProfileEvents { @@ -659,6 +661,11 @@ static std::tuple executeQueryImpl( elem.client_info = client_info; + std::bernoulli_distribution should_write_log{ + settings.log_queries_probability}; + + context->setSetting("log_queries", should_write_log(thread_local_rng)); + bool log_queries = settings.log_queries && !internal; /// Log into system table start of query execution, if need.