From 83062698fd25eeea9291b6317502b1564d96eeb8 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 May 2005 05:39:10 +0200 Subject: [PATCH 1/2] Change Last_query_cost status variable from global to thread-local. sql/mysql_priv.h: Changed last_query_cost status variable from global to thread-local. sql/mysqld.cc: Changed last_query_cost status variable from global to thread-local. sql/sql_class.cc: Changed last_query_cost status variable from global to thread-local. sql/sql_class.h: Changed last_query_cost status variable from global to thread-local. sql/sql_select.cc: Changed last_query_cost status variable from global to thread-local. sql/sql_show.cc: All SHOW_DOUBLE-type status variables are now assumed to be thread-local (there is only one currently, last_query_cost, and this cset makes it thread-local) --- sql/mysql_priv.h | 1 - sql/mysqld.cc | 3 +-- sql/sql_class.cc | 1 + sql/sql_class.h | 2 ++ sql/sql_select.cc | 3 +-- sql/sql_show.cc | 1 + 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 36fc315c3c0..312f665e22f 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1048,7 +1048,6 @@ extern char language[FN_REFLEN], reg_ext[FN_EXTLEN]; extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN]; extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file; extern char log_error_file[FN_REFLEN], *opt_tc_log_file; -extern double last_query_cost; extern double log_10[32]; extern ulonglong log_10_int[20]; extern ulonglong keybuff_size; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 90d4f9b9a99..e45a61b0c04 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -345,7 +345,6 @@ ulong expire_logs_days = 0; ulong rpl_recovery_rank=0; ulong my_bind_addr; /* the address we bind to */ volatile ulong cached_thread_count= 0; -double last_query_cost= -1; /* -1 denotes that no query was compiled yet */ double log_10[32]; /* 10 potences */ time_t start_time; @@ -5714,7 +5713,7 @@ struct show_var_st status_vars[]= { {"Key_reads", (char*) &dflt_key_cache_var.global_cache_read, SHOW_KEY_CACHE_LONG}, {"Key_write_requests", (char*) &dflt_key_cache_var.global_cache_w_requests, SHOW_KEY_CACHE_LONG}, {"Key_writes", (char*) &dflt_key_cache_var.global_cache_write, SHOW_KEY_CACHE_LONG}, - {"Last_query_cost", (char*) &last_query_cost, SHOW_DOUBLE}, + {"Last_query_cost", (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE}, {"Max_used_connections", (char*) &max_used_connections, SHOW_LONG}, #ifdef HAVE_NDBCLUSTER_DB {"Ndb_", (char*) &ndb_status_variables, SHOW_VARS}, diff --git a/sql/sql_class.cc b/sql/sql_class.cc index a6a1f4d60ef..8a43d80ba52 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -444,6 +444,7 @@ void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var) while (to != end) *(to++)+= *(from++); + /* it doesn't make sense to add last_query_cost values */ } diff --git a/sql/sql_class.h b/sql/sql_class.h index 4393da6df2a..f1f0cc2bde5 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -635,6 +635,8 @@ typedef struct system_status_var ulong filesort_range_count; ulong filesort_rows; ulong filesort_scan_count; + + double last_query_cost; } STATUS_VAR; /* diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 25bd99ee194..7ccb67be9d3 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3739,8 +3739,7 @@ choose_plan(JOIN *join, table_map join_tables) Don't update last_query_cost for 'show status' command */ if (join->thd->lex->orig_sql_command != SQLCOM_SHOW_STATUS) - last_query_cost= join->best_read; - + join->thd->status_var.last_query_cost= join->best_read; DBUG_VOID_RETURN; } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 9e3f82f9fd6..a5d12dffc4b 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1358,6 +1358,7 @@ static bool show_status_array(THD *thd, const char *wild, } case SHOW_DOUBLE: { + value= ((char *) status_var + (ulong) value); end= buff + sprintf(buff, "%f", *(double*) value); break; } From 48e0630d2f71b47a12ef85124bba570d73ff7b65 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 May 2005 20:54:02 +0200 Subject: [PATCH 2/2] Post-review fixes: rename SHOW_DOUBLE to SHOW_DOUBLE_STATUS --- sql/mysqld.cc | 2 +- sql/sql_show.cc | 2 +- sql/structs.h | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e45a61b0c04..b6e80402114 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5713,7 +5713,7 @@ struct show_var_st status_vars[]= { {"Key_reads", (char*) &dflt_key_cache_var.global_cache_read, SHOW_KEY_CACHE_LONG}, {"Key_write_requests", (char*) &dflt_key_cache_var.global_cache_w_requests, SHOW_KEY_CACHE_LONG}, {"Key_writes", (char*) &dflt_key_cache_var.global_cache_write, SHOW_KEY_CACHE_LONG}, - {"Last_query_cost", (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE}, + {"Last_query_cost", (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS}, {"Max_used_connections", (char*) &max_used_connections, SHOW_LONG}, #ifdef HAVE_NDBCLUSTER_DB {"Ndb_", (char*) &ndb_status_variables, SHOW_VARS}, diff --git a/sql/sql_show.cc b/sql/sql_show.cc index a5d12dffc4b..3d23e22c590 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1356,7 +1356,7 @@ static bool show_status_array(THD *thd, const char *wild, end= strend(pos); break; } - case SHOW_DOUBLE: + case SHOW_DOUBLE_STATUS: { value= ((char *) status_var + (ulong) value); end= buff + sprintf(buff, "%f", *(double*) value); diff --git a/sql/structs.h b/sql/structs.h index 7a70bfc0f4f..306089016bc 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -164,7 +164,8 @@ typedef struct st_known_date_time_format { enum SHOW_TYPE { SHOW_UNDEF, - SHOW_LONG, SHOW_LONGLONG, SHOW_INT, SHOW_CHAR, SHOW_CHAR_PTR, SHOW_DOUBLE, + SHOW_LONG, SHOW_LONGLONG, SHOW_INT, SHOW_CHAR, SHOW_CHAR_PTR, + SHOW_DOUBLE_STATUS, SHOW_BOOL, SHOW_MY_BOOL, SHOW_OPENTABLES, SHOW_STARTTIME, SHOW_QUESTION, SHOW_LONG_CONST, SHOW_INT_CONST, SHOW_HAVE, SHOW_SYS, SHOW_HA_ROWS, SHOW_VARS,