Fix query comments in query_log and server log (w/ enable_global_with_statement)

Plus, I guess that enable_global_with_statement will be enabled by
default someday, so it may become significant.

The enable_global_with_statement had been introduced in #15451

Cc: @amosbird
This commit is contained in:
Azat Khuzhin 2020-10-20 21:10:24 +03:00
parent 75a02112bc
commit e76066718d
3 changed files with 24 additions and 10 deletions

View File

@ -338,28 +338,26 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
try
{
bool ast_modified = false;
/// Replace ASTQueryParameter with ASTLiteral for prepared statements.
if (context.hasQueryParameters())
{
ReplaceQueryParameterVisitor visitor(context.getQueryParameters());
visitor.visit(ast);
ast_modified = true;
query = serializeAST(*ast);
}
/// MUST goes before any modification (except for prepared statements,
/// since it substitute parameters and w/o them query does not contains
/// parameters), to keep query as-is in query_log and server log.
query_for_logging = prepareQueryForLogging(query, context);
logQuery(query_for_logging, context, internal);
/// Propagate WITH statement to children ASTSelect.
if (settings.enable_global_with_statement)
{
ApplyWithGlobalVisitor().visit(ast);
ast_modified = true;
}
if (ast_modified)
query = serializeAST(*ast);
query_for_logging = prepareQueryForLogging(query, context);
logQuery(query_for_logging, context, internal);
}
/// Check the limits.
checkASTSizeLimits(*ast, settings);

View File

@ -0,0 +1,4 @@
2
1
2
1

View File

@ -0,0 +1,12 @@
set log_queries=1;
set log_queries_min_type='QUERY_FINISH';
set enable_global_with_statement=1;
select /* test=01531, enable_global_with_statement=0 */ 2;
system flush logs;
select count() from system.query_log where event_time >= now() - interval 5 minute and query = 'select /* test=01531, enable_global_with_statement=0 */ 2;\n';
set enable_global_with_statement=1;
select /* test=01531 enable_global_with_statement=1 */ 2;
system flush logs;
select count() from system.query_log where event_time >= now() - interval 5 minute and query = 'select /* test=01531 enable_global_with_statement=1 */ 2;\n';