summaryrefslogtreecommitdiff
path: root/sql/sql_class.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r--sql/sql_class.cc205
1 files changed, 195 insertions, 10 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 67a9312b6e6..3a3cf4520e1 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -426,7 +426,7 @@ void thd_set_mysys_var(THD *thd, st_my_thread_var *mysys_var)
*/
my_socket thd_get_fd(THD *thd)
{
- return thd->net.vio->sd;
+ return mysql_socket_getfd(thd->net.vio->mysql_socket);
}
/**
@@ -491,27 +491,74 @@ int thd_tablespace_op(const THD *thd)
return test(thd->tablespace_op);
}
-
extern "C"
-const char *set_thd_proc_info(THD *thd, const char *info,
+const char *set_thd_proc_info(THD *thd_arg, const char *info,
const char *calling_function,
const char *calling_file,
const unsigned int calling_line)
{
- if (!thd)
+ PSI_stage_info old_stage;
+ PSI_stage_info new_stage;
+
+ old_stage.m_key= 0;
+ old_stage.m_name= info;
+
+ set_thd_stage_info(thd_arg, & old_stage, & new_stage,
+ calling_function, calling_file, calling_line);
+
+ return new_stage.m_name;
+}
+
+extern "C"
+void set_thd_stage_info(void *opaque_thd,
+ const PSI_stage_info *new_stage,
+ PSI_stage_info *old_stage,
+ const char *calling_func,
+ const char *calling_file,
+ const unsigned int calling_line)
+{
+ THD *thd= (THD*) opaque_thd;
+ if (thd == NULL)
thd= current_thd;
- const char *old_info= thd->proc_info;
- DBUG_PRINT("proc_info", ("%s:%d %s", calling_file, calling_line, info));
+ thd->enter_stage(new_stage, old_stage, calling_func, calling_file,
+ calling_line);
+}
+
+void THD::enter_stage(const PSI_stage_info *new_stage,
+ PSI_stage_info *old_stage,
+ const char *calling_func,
+ const char *calling_file,
+ const unsigned int calling_line)
+{
+ DBUG_PRINT("THD::enter_stage", ("%s:%d", calling_file, calling_line));
+
+ if (old_stage != NULL)
+ {
+ old_stage->m_key= m_current_stage_key;
+ old_stage->m_name= proc_info;
+ }
+
+ if (new_stage != NULL)
+ {
+ const char *msg= new_stage->m_name;
#if defined(ENABLED_PROFILING)
- thd->profiling.status_change(info,
- calling_function, calling_file, calling_line);
+ profiling.status_change(msg, calling_func, calling_file, calling_line);
#endif
- thd->proc_info= info;
- return old_info;
+
+ m_current_stage_key= new_stage->m_key;
+ proc_info= msg;
+
+#ifdef HAVE_PSI_THREAD_INTERFACE
+ PSI_CALL(set_thread_state)(msg);
+ MYSQL_SET_STAGE(m_current_stage_key, calling_file, calling_line);
+#endif
+ }
+ return;
}
+
extern "C"
const char* thd_enter_cond(MYSQL_THD thd, mysql_cond_t *cond,
mysql_mutex_t *mutex, const char *msg)
@@ -746,6 +793,9 @@ THD::THD()
accessed_rows_and_keys(0),
warning_info(&main_warning_info),
stmt_da(&main_da),
+ m_statement_psi(NULL),
+ m_idle_psi(NULL),
+ m_server_idle(false),
global_disable_checkpoint(0),
is_fatal_error(0),
transaction_rollback_request(0),
@@ -4186,6 +4236,141 @@ void THD::set_statement(Statement *stmt)
mysql_mutex_unlock(&LOCK_thd_data);
}
+void THD::set_sent_row_count(ha_rows count)
+{
+ sent_row_count= count;
+ MYSQL_SET_STATEMENT_ROWS_SENT(m_statement_psi, sent_row_count);
+}
+
+void THD::set_examined_row_count(ha_rows count)
+{
+ examined_row_count= count;
+ MYSQL_SET_STATEMENT_ROWS_EXAMINED(m_statement_psi, examined_row_count);
+}
+
+void THD::inc_sent_row_count(ha_rows count)
+{
+ sent_row_count+= count;
+ MYSQL_SET_STATEMENT_ROWS_SENT(m_statement_psi, sent_row_count);
+}
+
+void THD::inc_examined_row_count(ha_rows count)
+{
+ examined_row_count+= count;
+ MYSQL_SET_STATEMENT_ROWS_EXAMINED(m_statement_psi, examined_row_count);
+}
+
+void THD::inc_status_created_tmp_disk_tables()
+{
+ status_var_increment(status_var.created_tmp_disk_tables);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_created_tmp_disk_tables)(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_created_tmp_tables()
+{
+ status_var_increment(status_var.created_tmp_tables);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_created_tmp_tables)(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_select_full_join()
+{
+ status_var_increment(status_var.select_full_join_count);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_select_full_join)(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_select_full_range_join()
+{
+ status_var_increment(status_var.select_full_range_join_count);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_select_full_range_join)(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_select_range()
+{
+ status_var_increment(status_var.select_range_count);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_select_range)(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_select_range_check()
+{
+ status_var_increment(status_var.select_range_check_count);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_select_range_check)(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_select_scan()
+{
+ status_var_increment(status_var.select_scan_count);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_select_scan)(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_sort_merge_passes()
+{
+ status_var_increment(status_var.filesort_merge_passes);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_sort_merge_passes)(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_sort_range()
+{
+ status_var_increment(status_var.filesort_range_count);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_sort_range)(m_statement_psi, 1);
+#endif
+}
+
+void THD::inc_status_sort_rows(ha_rows count)
+{
+ statistic_add(status_var.filesort_rows, count, &LOCK_status);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_sort_rows)(m_statement_psi, count);
+#endif
+}
+
+void THD::inc_status_sort_scan()
+{
+ status_var_increment(status_var.filesort_scan_count);
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(inc_statement_sort_scan)(m_statement_psi, 1);
+#endif
+}
+
+void THD::set_status_no_index_used()
+{
+ server_status|= SERVER_QUERY_NO_INDEX_USED;
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(set_statement_no_index_used)(m_statement_psi);
+#endif
+}
+
+void THD::set_status_no_good_index_used()
+{
+ server_status|= SERVER_QUERY_NO_GOOD_INDEX_USED;
+#ifdef HAVE_PSI_STATEMENT_INTERFACE
+ PSI_CALL(set_statement_no_good_index_used)(m_statement_psi);
+#endif
+}
+
+void THD::set_command(enum enum_server_command command_arg)
+{
+ command= command_arg;
+#ifdef HAVE_PSI_THREAD_INTERFACE
+ PSI_CALL(set_thread_command)(command);
+#endif
+}
/** Assign a new value to thd->query. */