summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2019-03-11 16:45:38 +0100
committerSergei Golubchik <serg@mariadb.org>2019-03-12 13:10:49 +0100
commitdda2e940fb035d41852e95a1c2f513ab1534b041 (patch)
tree1f0a9a90a727be8350cbbec077eb24c2ff2405ff /sql
parentbc8ae50e7c1dd56ceb7fc39e05f87a104d3ce632 (diff)
downloadmariadb-git-dda2e940fb035d41852e95a1c2f513ab1534b041.tar.gz
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.
Diffstat (limited to 'sql')
-rw-r--r--sql/log_slow.h1
-rw-r--r--sql/sql_admin.h8
-rw-r--r--sql/sql_alter.h2
-rw-r--r--sql/sql_class.h5
-rw-r--r--sql/sql_cmd.h15
-rw-r--r--sql/sql_lex.cc13
-rw-r--r--sql/sql_parse.cc69
7 files changed, 39 insertions, 74 deletions
diff --git a/sql/log_slow.h b/sql/log_slow.h
index 3b6dbd1b2ac..5092e8332ed 100644
--- a/sql/log_slow.h
+++ b/sql/log_slow.h
@@ -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 */
diff --git a/sql/sql_admin.h b/sql/sql_admin.h
index ce7308434c5..96594fad0cb 100644
--- a/sql/sql_admin.h
+++ b/sql/sql_admin.h
@@ -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 @@ public:
/**
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 @@ public:
/**
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 @@ public:
/**
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:
/**
diff --git a/sql/sql_alter.h b/sql/sql_alter.h
index 74dd8b0e5d8..a4505f1d6c1 100644
--- a/sql/sql_alter.h
+++ b/sql/sql_alter.h
@@ -363,7 +363,7 @@ private:
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:
/**
diff --git a/sql/sql_class.h b/sql/sql_class.h
index e93bd00eec0..db9a3742fc0 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -5458,6 +5458,11 @@ public:
*/
#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 */
/**
diff --git a/sql/sql_cmd.h b/sql/sql_cmd.h
index 9cb2a728f41..904578134b4 100644
--- a/sql/sql_cmd.h
+++ b/sql/sql_cmd.h
@@ -145,8 +145,6 @@ public:
*/
virtual bool execute(THD *thd) = 0;
- virtual bool log_slow_enabled_statement(const THD *thd) const;
-
protected:
Sql_cmd()
{}
@@ -163,17 +161,4 @@ protected:
}
};
-
-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
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 7c330151545..df868d0321f 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -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];
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 8da2a257df7..c9651e1038b 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -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 @@ end_with_restore_list:
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 @@ end_with_restore_list:
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: