Update after merge.

Use mutex when reading prepared_stmt_count global status variable.

Update test case for bug 16365 and bug 23159: add test for
prepared_stmt_count being decreased when some connection that had
prepared statements is closed.
parent 5ba9ab49
...@@ -898,6 +898,12 @@ show status like 'prepared_stmt_count'; ...@@ -898,6 +898,12 @@ show status like 'prepared_stmt_count';
Variable_name Value Variable_name Value
Prepared_stmt_count 3 Prepared_stmt_count 3
deallocate prepare stmt; deallocate prepare stmt;
select @@max_prepared_stmt_count;
@@max_prepared_stmt_count
3
show status like 'prepared_stmt_count';
Variable_name Value
Prepared_stmt_count 0
set global max_prepared_stmt_count= @old_max_prepared_stmt_count; set global max_prepared_stmt_count= @old_max_prepared_stmt_count;
drop table if exists t1; drop table if exists t1;
create temporary table if not exists t1 (a1 int); create temporary table if not exists t1 (a1 int);
......
...@@ -950,7 +950,18 @@ select @@max_prepared_stmt_count; ...@@ -950,7 +950,18 @@ select @@max_prepared_stmt_count;
show status like 'prepared_stmt_count'; show status like 'prepared_stmt_count';
disconnect con1; disconnect con1;
connection default; connection default;
# Wait for the connection to die: deal with a possible race
deallocate prepare stmt; deallocate prepare stmt;
let $query= select variable_value from information_schema.global_status
where variable_name = 'prepared_stmt_count';
let $count= `$query`;
if ($count)
{
--sleep 1
let $count= `$query`;
}
select @@max_prepared_stmt_count;
show status like 'prepared_stmt_count';
# #
# Restore the old value. # Restore the old value.
# #
......
...@@ -6337,6 +6337,16 @@ static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff) ...@@ -6337,6 +6337,16 @@ static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff)
{
var->type= SHOW_LONG;
var->value= buff;
pthread_mutex_lock(&LOCK_prepared_stmt_count);
*((long *)buff)= (long)prepared_stmt_count;
pthread_mutex_unlock(&LOCK_prepared_stmt_count);
return 0;
}
static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff) static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
...@@ -6747,7 +6757,7 @@ SHOW_VAR status_vars[]= { ...@@ -6747,7 +6757,7 @@ SHOW_VAR status_vars[]= {
{"Open_table_definitions", (char*) &show_table_definitions, SHOW_FUNC}, {"Open_table_definitions", (char*) &show_table_definitions, SHOW_FUNC},
{"Open_tables", (char*) &show_open_tables, SHOW_FUNC}, {"Open_tables", (char*) &show_open_tables, SHOW_FUNC},
{"Opened_tables", (char*) offsetof(STATUS_VAR, opened_tables), SHOW_LONG_STATUS}, {"Opened_tables", (char*) offsetof(STATUS_VAR, opened_tables), SHOW_LONG_STATUS},
{"Prepared_stmt_count", (char*) &prepared_stmt_count, SHOW_LONG_CONST}, {"Prepared_stmt_count", (char*) &show_prepared_stmt_count, SHOW_FUNC},
#ifdef HAVE_QUERY_CACHE #ifdef HAVE_QUERY_CACHE
{"Qcache_free_blocks", (char*) &query_cache.free_memory_blocks, SHOW_LONG_NOFLUSH}, {"Qcache_free_blocks", (char*) &query_cache.free_memory_blocks, SHOW_LONG_NOFLUSH},
{"Qcache_free_memory", (char*) &query_cache.free_memory, SHOW_LONG_NOFLUSH}, {"Qcache_free_memory", (char*) &query_cache.free_memory, SHOW_LONG_NOFLUSH},
......
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