Skip to content

Commit ae7ff13

Browse files
author
Christopher Powers
committed
Bug#21788887 HANDLER_EXTERNAL_LOCK, CREATED_TMP_TABLES SHOW ACTUAL VALUE +1
Use status var snapshot from before the start of the SHOW STATUS query to avoid status counter updates caused by the query itself.
1 parent 86c19fe commit ae7ff13

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

mysql-test/suite/perfschema/r/show_misc.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ select 2;
3232
SHOW STATUS LIKE 'Last_query_cost';
3333
Variable_name Value
3434
Last_query_cost 0.000000
35+
================================================================================
36+
SHOW_COMPATIBILITY_56 = ON
37+
================================================================================
38+
flush status;
39+
set global show_compatibility_56 = on;
40+
SHOW STATUS LIKE 'Created_tmp_tables';
41+
Variable_name Value
42+
Created_tmp_tables 0
43+
44+
================================================================================
45+
SHOW_COMPATIBILITY_56 = OFF
46+
================================================================================
47+
set global show_compatibility_56 = off;
48+
SHOW STATUS LIKE 'Created_tmp_tables';
49+
Variable_name Value
50+
Created_tmp_tables 0
3551

3652
================================================================================
3753
CLEAN UP

mysql-test/suite/perfschema/t/show_misc.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ SHOW STATUS LIKE 'Last_query_partial_plans';
2626
select 2;
2727
SHOW STATUS LIKE 'Last_query_cost';
2828

29+
30+
--echo ================================================================================
31+
--echo SHOW_COMPATIBILITY_56 = ON
32+
--echo ================================================================================
33+
flush status;
34+
set global show_compatibility_56 = on;
35+
SHOW STATUS LIKE 'Created_tmp_tables';
36+
37+
--echo
38+
--echo ================================================================================
39+
--echo SHOW_COMPATIBILITY_56 = OFF
40+
--echo ================================================================================
41+
set global show_compatibility_56 = off;
42+
43+
SHOW STATUS LIKE 'Created_tmp_tables';
44+
2945
--echo
3046
--echo ================================================================================
3147
--echo CLEAN UP

storage/perfschema/pfs_variable.cc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,20 @@ bool PFS_status_variable_cache::do_initialize_session(void)
889889
return ret;
890890
}
891891

892+
/**
893+
For the current THD, use initial_status_vars taken from before the query start.
894+
*/
895+
STATUS_VAR *PFS_status_variable_cache::set_status_vars(void)
896+
{
897+
STATUS_VAR *status_vars;
898+
if (m_safe_thd == m_current_thd && m_current_thd->initial_status_var != NULL)
899+
status_vars= m_current_thd->initial_status_var;
900+
else
901+
status_vars= &m_safe_thd->status_var;
902+
903+
return status_vars;
904+
}
905+
892906
/**
893907
Build cache for GLOBAL status variables using values totaled from all threads.
894908
*/
@@ -967,8 +981,9 @@ int PFS_status_variable_cache::do_materialize_all(THD* unsafe_thd)
967981
/*
968982
Build the status variable cache using the SHOW_VAR array as a reference.
969983
Use the status values from the THD protected by the thread manager lock.
970-
*/
971-
manifest(m_safe_thd, m_show_var_array.begin(), &m_safe_thd->status_var, "", false, false);
984+
*/
985+
STATUS_VAR *status_vars= set_status_vars();
986+
manifest(m_safe_thd, m_show_var_array.begin(), status_vars, "", false, false);
972987

973988
/* Release lock taken in get_THD(). */
974989
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_data);
@@ -1012,8 +1027,9 @@ int PFS_status_variable_cache::do_materialize_session(THD* unsafe_thd)
10121027
/*
10131028
Build the status variable cache using the SHOW_VAR array as a reference.
10141029
Use the status values from the THD protected by the thread manager lock.
1015-
*/
1016-
manifest(m_safe_thd, m_show_var_array.begin(), &m_safe_thd->status_var, "", false, true);
1030+
*/
1031+
STATUS_VAR *status_vars= set_status_vars();
1032+
manifest(m_safe_thd, m_show_var_array.begin(), status_vars, "", false, true);
10171033

10181034
/* Release lock taken in get_THD(). */
10191035
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_data);
@@ -1054,7 +1070,8 @@ int PFS_status_variable_cache::do_materialize_session(PFS_thread *pfs_thread)
10541070
Build the status variable cache using the SHOW_VAR array as a reference.
10551071
Use the status values from the THD protected by the thread manager lock.
10561072
*/
1057-
manifest(m_safe_thd, m_show_var_array.begin(), &m_safe_thd->status_var, "", false, true);
1073+
STATUS_VAR *status_vars= set_status_vars();
1074+
manifest(m_safe_thd, m_show_var_array.begin(), status_vars, "", false, true);
10581075

10591076
/* Release lock taken in get_THD(). */
10601077
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_data);

storage/perfschema/pfs_variable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@ class PFS_status_variable_cache : public PFS_variable_cache<Status_variable>
678678
/* Build status variable name with prefix. Return copy of the string. */
679679
char *make_show_var_name(const char* prefix, const char* name);
680680

681+
/* For the current THD, use initial_status_vars taken from before the query start. */
682+
STATUS_VAR *set_status_vars(void);
683+
681684
/* Build the list of status variables from SHOW_VAR array. */
682685
void manifest(THD *thd, const SHOW_VAR *show_var_array,
683686
STATUS_VAR *status_var_array, const char *prefix, bool nested_array, bool strict);

0 commit comments

Comments
 (0)