Commit dda2e940 authored by Sergei Golubchik's avatar Sergei Golubchik

pass the slow logging information in thd->query_plan_flags

This solves the following issues:

* unlike lex->m_sql_cmd and lex->sql_command, thd->query_plan_flags
  is not reset in Prepared_statement::execute, it survives
  till the log_slow_statement(), so slow logging behaves correctly in --ps

* using thd->query_plan_flags for both slow_log_filter and
  log_slow_admin_statements means the definition of "admin" statements
  for the slow log is the same no matter how it is filtered out.
parent bc8ae50e
......@@ -34,4 +34,5 @@
#define QPLAN_FILESORT_PRIORITY_QUEUE (1U << 9)
/* ... */
#define QPLAN_STATUS (1U << 31) /* not in the slow_log_filter */
#define QPLAN_MAX (1U << 31) /* reserved as placeholder */
......@@ -28,7 +28,7 @@ int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
/**
Sql_cmd_analyze_table represents the ANALYZE TABLE statement.
*/
class Sql_cmd_analyze_table : public Sql_cmd_admin
class Sql_cmd_analyze_table : public Sql_cmd
{
public:
/**
......@@ -53,7 +53,7 @@ class Sql_cmd_analyze_table : public Sql_cmd_admin
/**
Sql_cmd_check_table represents the CHECK TABLE statement.
*/
class Sql_cmd_check_table : public Sql_cmd_admin
class Sql_cmd_check_table : public Sql_cmd
{
public:
/**
......@@ -77,7 +77,7 @@ class Sql_cmd_check_table : public Sql_cmd_admin
/**
Sql_cmd_optimize_table represents the OPTIMIZE TABLE statement.
*/
class Sql_cmd_optimize_table : public Sql_cmd_admin
class Sql_cmd_optimize_table : public Sql_cmd
{
public:
/**
......@@ -102,7 +102,7 @@ class Sql_cmd_optimize_table : public Sql_cmd_admin
/**
Sql_cmd_repair_table represents the REPAIR TABLE statement.
*/
class Sql_cmd_repair_table : public Sql_cmd_admin
class Sql_cmd_repair_table : public Sql_cmd
{
public:
/**
......
......@@ -363,7 +363,7 @@ class Alter_table_ctx
statements.
@todo move Alter_info and other ALTER generic structures from Lex here.
*/
class Sql_cmd_common_alter_table : public Sql_cmd_admin
class Sql_cmd_common_alter_table : public Sql_cmd
{
protected:
/**
......
......@@ -5458,6 +5458,11 @@ class select_dumpvar :public select_result_interceptor {
*/
#define CF_UPDATES_DATA (1U << 18)
/**
Not logged into slow log as "admin commands"
*/
#define CF_ADMIN_COMMAND (1U << 19)
/* Bits in server_command_flags */
/**
......
......@@ -145,8 +145,6 @@ class Sql_cmd : public Sql_alloc
*/
virtual bool execute(THD *thd) = 0;
virtual bool log_slow_enabled_statement(const THD *thd) const;
protected:
Sql_cmd()
{}
......@@ -163,17 +161,4 @@ class Sql_cmd : public Sql_alloc
}
};
class Sql_cmd_admin: public Sql_cmd
{
public:
Sql_cmd_admin()
{}
~Sql_cmd_admin()
{}
bool log_slow_enabled_statement(const THD *thd) const;
};
#endif // SQL_CMD_INCLUDED
......@@ -4720,19 +4720,6 @@ bool LEX::is_partition_management() const
}
bool Sql_cmd::log_slow_enabled_statement(const THD *thd) const
{
return global_system_variables.sql_log_slow && thd->variables.sql_log_slow;
}
bool Sql_cmd_admin::log_slow_enabled_statement(const THD *thd) const
{
return opt_log_slow_admin_statements &&
Sql_cmd::log_slow_enabled_statement(thd);
}
#ifdef MYSQL_SERVER
uint binlog_unsafe_map[256];
......
......@@ -309,10 +309,11 @@ void init_update_queries(void)
sql_command_flags[SQLCOM_CREATE_TABLE]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS |
CF_CAN_GENERATE_ROW_EVENTS;
sql_command_flags[SQLCOM_CREATE_INDEX]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
sql_command_flags[SQLCOM_CREATE_INDEX]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS |
CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_ALTER_TABLE]= CF_CHANGES_DATA | CF_WRITE_LOGS_COMMAND |
CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS |
CF_INSERTS_DATA;
CF_INSERTS_DATA | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_TRUNCATE]= CF_CHANGES_DATA | CF_WRITE_LOGS_COMMAND |
CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_TABLE]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
......@@ -324,7 +325,8 @@ void init_update_queries(void)
sql_command_flags[SQLCOM_ALTER_DB_UPGRADE]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_DB]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_RENAME_TABLE]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_INDEX]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
sql_command_flags[SQLCOM_DROP_INDEX]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS |
CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_CREATE_VIEW]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_VIEW]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
......@@ -492,10 +494,14 @@ void init_update_queries(void)
The following admin table operations are allowed
on log tables.
*/
sql_command_flags[SQLCOM_REPAIR]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
sql_command_flags[SQLCOM_OPTIMIZE]|= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
sql_command_flags[SQLCOM_ANALYZE]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
sql_command_flags[SQLCOM_CHECK]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
sql_command_flags[SQLCOM_REPAIR]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS |
CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_OPTIMIZE]|= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS |
CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_ANALYZE]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS |
CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_CHECK]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS |
CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_CHECKSUM]= CF_REPORT_PROGRESS;
sql_command_flags[SQLCOM_CREATE_USER]|= CF_AUTO_COMMIT_TRANS;
......@@ -1304,10 +1310,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
m_key);
thd->set_command(command);
/*
Commands which always take a long time are logged into
the slow log only if opt_log_slow_admin_statements is set.
*/
thd->enable_slow_log= true;
thd->query_plan_flags= QPLAN_INIT;
thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
......@@ -1718,7 +1720,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
status_var_increment(thd->status_var.com_other);
thd->enable_slow_log&= opt_log_slow_admin_statements;
thd->query_plan_flags|= QPLAN_ADMIN;
if (check_global_access(thd, REPL_SLAVE_ACL))
break;
......@@ -2018,31 +2019,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
}
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) &&
!opt_log_slow_admin_statements)
return true;
return global_system_variables.sql_log_slow &&
thd->variables.sql_log_slow;
}
/*
@note
This function must call delete_explain_query().
......@@ -2075,12 +2051,20 @@ void log_slow_statement(THD *thd)
((thd->server_status &
(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
opt_log_queries_not_using_indexes &&
!(sql_command_flags[thd->lex->sql_command] & CF_STATUS_COMMAND))) &&
!(thd->query_plan_flags & QPLAN_STATUS))) &&
thd->get_examined_row_count() >= thd->variables.min_examined_row_limit)
{
thd->status_var.long_query_count++;
if (!log_slow_enabled_statement(thd))
/*
until opt_log_slow_admin_statements is removed, it
duplicates slow_log_filter=admin
*/
if ((thd->query_plan_flags & QPLAN_ADMIN) &&
!opt_log_slow_admin_statements)
goto end;
if (!global_system_variables.sql_log_slow || !thd->variables.sql_log_slow)
goto end;
/*
......@@ -2953,6 +2937,11 @@ mysql_execute_command(THD *thd)
goto error;
}
if (sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND)
thd->query_plan_flags|= QPLAN_STATUS;
if (sql_command_flags[lex->sql_command] & CF_ADMIN_COMMAND)
thd->query_plan_flags|= QPLAN_ADMIN;
/* Start timeouts */
thd->set_query_timer();
......@@ -3574,7 +3563,6 @@ mysql_execute_command(THD *thd)
if (check_one_table_access(thd, INDEX_ACL, all_tables))
goto error; /* purecov: inspected */
WSREP_TO_ISOLATION_BEGIN(first_table->db, first_table->table_name, NULL)
thd->query_plan_flags|= QPLAN_ADMIN;
bzero((char*) &create_info, sizeof(create_info));
create_info.db_type= 0;
......@@ -5732,7 +5720,6 @@ mysql_execute_command(THD *thd)
case SQLCOM_REPAIR:
case SQLCOM_TRUNCATE:
case SQLCOM_ALTER_TABLE:
thd->query_plan_flags|= QPLAN_ADMIN;
DBUG_ASSERT(first_table == all_tables && first_table != 0);
/* fall through */
case SQLCOM_SIGNAL:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment