1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

Merge 10.3 into 10.4

This commit is contained in:
Marko Mäkelä
2019-03-06 09:00:52 +02:00
89 changed files with 1636 additions and 550 deletions

View File

@ -1575,7 +1575,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->variables.log_slow_disabled_statements defines which statements
are logged to slow log
*/
thd->enable_slow_log= thd->variables.sql_log_slow;
thd->enable_slow_log= true;
thd->query_plan_flags= QPLAN_INIT;
thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
thd->reset_kill_query();
@ -2478,6 +2478,32 @@ dispatch_end:
}
static bool log_slow_enabled_statement(const THD *thd)
{
/*
TODO-10.4: Add classes Sql_cmd_create_index and Sql_cmd_drop_index
for symmetry with other admin commands, so these statements can be
handled by this command:
*/
if (thd->lex->m_sql_cmd)
return thd->lex->m_sql_cmd->log_slow_enabled_statement(thd);
/*
Currently CREATE INDEX or DROP INDEX cause a full table rebuild
and thus classify as slow administrative statements just like
ALTER TABLE.
*/
if ((thd->lex->sql_command == SQLCOM_CREATE_INDEX ||
thd->lex->sql_command == SQLCOM_DROP_INDEX) &&
MY_TEST(thd->variables.log_slow_disabled_statements &
LOG_SLOW_DISABLE_ADMIN))
return true;
return global_system_variables.sql_log_slow &&
thd->variables.sql_log_slow;
}
/*
Log query to slow queries, if it passes filtering
@ -2496,8 +2522,17 @@ void log_slow_statement(THD *thd)
*/
if (unlikely(thd->in_sub_stmt))
goto end; // Don't set time for sub stmt
if (!thd->enable_slow_log || !global_system_variables.sql_log_slow)
goto end;
/*
Skip both long_query_count increment and logging if the current
statement forces slow log suppression (e.g. an SP statement).
Note, we don't check for global_system_variables.sql_log_slow here.
According to the manual, the "Slow_queries" status variable does not require
sql_log_slow to be ON. So even if sql_log_slow is OFF, we still need to
continue and increment long_query_count (and skip only logging, see below):
*/
if (!thd->enable_slow_log)
goto end; // E.g. SP statement
if ((thd->server_status &
(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
@ -2510,15 +2545,14 @@ void log_slow_statement(THD *thd)
thd->server_status|= SERVER_QUERY_WAS_SLOW;
}
/* Follow the slow log filter configuration. */
if (thd->variables.log_slow_filter &&
!(thd->variables.log_slow_filter & thd->query_plan_flags))
goto end;
if ((thd->server_status & SERVER_QUERY_WAS_SLOW) &&
thd->get_examined_row_count() >= thd->variables.min_examined_row_limit)
{
thd->status_var.long_query_count++;
if (!log_slow_enabled_statement(thd))
goto end;
/*
If rate limiting of slow log writes is enabled, decide whether to log
this query to the log or not.
@ -2527,6 +2561,14 @@ void log_slow_statement(THD *thd)
(global_query_id % thd->variables.log_slow_rate_limit) != 0)
goto end;
/*
Follow the slow log filter configuration:
skip logging if the current statement matches the filter.
*/
if (thd->variables.log_slow_filter &&
!(thd->variables.log_slow_filter & thd->query_plan_flags))
goto end;
THD_STAGE_INFO(thd, stage_logging_slow_query);
slow_log_print(thd, thd->query(), thd->query_length(),
thd->utime_after_query);