Commit 4e065c34 authored by kroki/tomash@moonlight.intranet's avatar kroki/tomash@moonlight.intranet

Merge moonlight.intranet:/home/tomash/src/mysql_ab/mysql-5.1

into  moonlight.intranet:/home/tomash/src/mysql_ab/mysql-5.1-bug23159
parents 1efc8620 f6235bc5
...@@ -796,12 +796,12 @@ set @old_max_prepared_stmt_count= @@max_prepared_stmt_count; ...@@ -796,12 +796,12 @@ set @old_max_prepared_stmt_count= @@max_prepared_stmt_count;
show variables like 'max_prepared_stmt_count'; show variables like 'max_prepared_stmt_count';
Variable_name Value Variable_name Value
max_prepared_stmt_count 16382 max_prepared_stmt_count 16382
show variables like 'prepared_stmt_count'; show status like 'prepared_stmt_count';
Variable_name Value Variable_name Value
prepared_stmt_count 0 Prepared_stmt_count 0
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count;
@@max_prepared_stmt_count @@prepared_stmt_count @@max_prepared_stmt_count
16382 0 16382
set global max_prepared_stmt_count=-1; set global max_prepared_stmt_count=-1;
select @@max_prepared_stmt_count; select @@max_prepared_stmt_count;
@@max_prepared_stmt_count @@max_prepared_stmt_count
...@@ -820,67 +820,70 @@ set max_prepared_stmt_count=1; ...@@ -820,67 +820,70 @@ set max_prepared_stmt_count=1;
ERROR HY000: Variable 'max_prepared_stmt_count' is a GLOBAL variable and should be set with SET GLOBAL ERROR HY000: Variable 'max_prepared_stmt_count' is a GLOBAL variable and should be set with SET GLOBAL
set local max_prepared_stmt_count=1; set local max_prepared_stmt_count=1;
ERROR HY000: Variable 'max_prepared_stmt_count' is a GLOBAL variable and should be set with SET GLOBAL ERROR HY000: Variable 'max_prepared_stmt_count' is a GLOBAL variable and should be set with SET GLOBAL
set local prepared_stmt_count=0;
ERROR HY000: Variable 'prepared_stmt_count' is a read only variable
set @@prepared_stmt_count=0;
ERROR HY000: Variable 'prepared_stmt_count' is a read only variable
set global prepared_stmt_count=1;
ERROR HY000: Variable 'prepared_stmt_count' is a read only variable
set global max_prepared_stmt_count=1; set global max_prepared_stmt_count=1;
select @@max_prepared_stmt_count; select @@max_prepared_stmt_count;
@@max_prepared_stmt_count @@max_prepared_stmt_count
1 1
set global max_prepared_stmt_count=0; set global max_prepared_stmt_count=0;
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count;
@@max_prepared_stmt_count @@prepared_stmt_count @@max_prepared_stmt_count
0 0 0
show status like 'prepared_stmt_count';
Variable_name Value
Prepared_stmt_count 0
prepare stmt from "select 1"; prepare stmt from "select 1";
ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 0) ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 0)
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
@@prepared_stmt_count Variable_name Value
0 Prepared_stmt_count 0
set global max_prepared_stmt_count=1; set global max_prepared_stmt_count=1;
prepare stmt from "select 1"; prepare stmt from "select 1";
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
@@prepared_stmt_count Variable_name Value
1 Prepared_stmt_count 1
prepare stmt1 from "select 1"; prepare stmt1 from "select 1";
ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 1) ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 1)
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
@@prepared_stmt_count Variable_name Value
1 Prepared_stmt_count 1
deallocate prepare stmt; deallocate prepare stmt;
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
@@prepared_stmt_count Variable_name Value
0 Prepared_stmt_count 0
prepare stmt from "select 1"; prepare stmt from "select 1";
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
@@prepared_stmt_count Variable_name Value
1 Prepared_stmt_count 1
prepare stmt from "select 2"; prepare stmt from "select 2";
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
@@prepared_stmt_count Variable_name Value
Prepared_stmt_count 1
show status like 'prepared_stmt_count';
Variable_name Value
Prepared_stmt_count 1
select @@max_prepared_stmt_count;
@@max_prepared_stmt_count
1 1
select @@prepared_stmt_count, @@max_prepared_stmt_count;
@@prepared_stmt_count @@max_prepared_stmt_count
1 1
set global max_prepared_stmt_count=0; set global max_prepared_stmt_count=0;
prepare stmt from "select 1"; prepare stmt from "select 1";
ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 0) ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 0)
execute stmt; execute stmt;
ERROR HY000: Unknown prepared statement handler (stmt) given to EXECUTE ERROR HY000: Unknown prepared statement handler (stmt) given to EXECUTE
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
@@prepared_stmt_count Variable_name Value
0 Prepared_stmt_count 0
prepare stmt from "select 1"; prepare stmt from "select 1";
ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 0) ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 0)
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
@@prepared_stmt_count Variable_name Value
0 Prepared_stmt_count 0
set global max_prepared_stmt_count=3; set global max_prepared_stmt_count=3;
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count;
@@max_prepared_stmt_count @@prepared_stmt_count @@max_prepared_stmt_count
3 0 3
show status like 'prepared_stmt_count';
Variable_name Value
Prepared_stmt_count 0
prepare stmt from "select 1"; prepare stmt from "select 1";
prepare stmt from "select 2"; prepare stmt from "select 2";
prepare stmt1 from "select 3"; prepare stmt1 from "select 3";
...@@ -888,13 +891,19 @@ prepare stmt2 from "select 4"; ...@@ -888,13 +891,19 @@ prepare stmt2 from "select 4";
ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 3) ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 3)
prepare stmt2 from "select 4"; prepare stmt2 from "select 4";
ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 3) ERROR 42000: Can't create more than max_prepared_stmt_count statements (current value: 3)
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count;
@@max_prepared_stmt_count @@prepared_stmt_count @@max_prepared_stmt_count
3 3 3
show status like 'prepared_stmt_count';
Variable_name Value
Prepared_stmt_count 3
deallocate prepare stmt; deallocate prepare stmt;
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count;
@@max_prepared_stmt_count @@prepared_stmt_count @@max_prepared_stmt_count
3 0 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);
......
...@@ -849,6 +849,9 @@ drop table t1; ...@@ -849,6 +849,9 @@ drop table t1;
# Bug#16365 Prepared Statements: DoS with too many open statements # Bug#16365 Prepared Statements: DoS with too many open statements
# Check that the limit @@max_prpeared_stmt_count works. # Check that the limit @@max_prpeared_stmt_count works.
# #
# This is also the test for bug#23159 prepared_stmt_count should be
# status variable.
#
# Save the old value # Save the old value
set @old_max_prepared_stmt_count= @@max_prepared_stmt_count; set @old_max_prepared_stmt_count= @@max_prepared_stmt_count;
# #
...@@ -858,17 +861,17 @@ set @old_max_prepared_stmt_count= @@max_prepared_stmt_count; ...@@ -858,17 +861,17 @@ set @old_max_prepared_stmt_count= @@max_prepared_stmt_count;
# #
--disable_ps_protocol --disable_ps_protocol
# #
# A. Check that the new variables are present in SHOW VARIABLES list. # A. Check that the new variables are present in SHOW VARIABLES and
# SHOW STATUS lists.
# #
show variables like 'max_prepared_stmt_count'; show variables like 'max_prepared_stmt_count';
show variables like 'prepared_stmt_count'; show status like 'prepared_stmt_count';
# #
# B. Check that the new variables are selectable. # B. Check that the new system variable is selectable.
# #
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count;
# #
# C. Check that max_prepared_stmt_count is settable (global only), # C. Check that max_prepared_stmt_count is settable (global only).
# whereas prepared_stmt_count is readonly.
# #
set global max_prepared_stmt_count=-1; set global max_prepared_stmt_count=-1;
select @@max_prepared_stmt_count; select @@max_prepared_stmt_count;
...@@ -882,12 +885,6 @@ set @@max_prepared_stmt_count=1; ...@@ -882,12 +885,6 @@ set @@max_prepared_stmt_count=1;
set max_prepared_stmt_count=1; set max_prepared_stmt_count=1;
--error ER_GLOBAL_VARIABLE --error ER_GLOBAL_VARIABLE
set local max_prepared_stmt_count=1; set local max_prepared_stmt_count=1;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
set local prepared_stmt_count=0;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
set @@prepared_stmt_count=0;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
set global prepared_stmt_count=1;
# set to a reasonable limit works # set to a reasonable limit works
set global max_prepared_stmt_count=1; set global max_prepared_stmt_count=1;
select @@max_prepared_stmt_count; select @@max_prepared_stmt_count;
...@@ -895,47 +892,50 @@ select @@max_prepared_stmt_count; ...@@ -895,47 +892,50 @@ select @@max_prepared_stmt_count;
# D. Check that the variables actually work. # D. Check that the variables actually work.
# #
set global max_prepared_stmt_count=0; set global max_prepared_stmt_count=0;
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count;
show status like 'prepared_stmt_count';
--error ER_MAX_PREPARED_STMT_COUNT_REACHED --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt from "select 1"; prepare stmt from "select 1";
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
set global max_prepared_stmt_count=1; set global max_prepared_stmt_count=1;
prepare stmt from "select 1"; prepare stmt from "select 1";
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
--error ER_MAX_PREPARED_STMT_COUNT_REACHED --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt1 from "select 1"; prepare stmt1 from "select 1";
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
deallocate prepare stmt; deallocate prepare stmt;
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
# #
# E. Check that we can prepare a statement with the same name # E. Check that we can prepare a statement with the same name
# successfully, without hitting the limit. # successfully, without hitting the limit.
# #
prepare stmt from "select 1"; prepare stmt from "select 1";
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
prepare stmt from "select 2"; prepare stmt from "select 2";
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
# #
# F. We can set the max below the current count. In this case no new # F. We can set the max below the current count. In this case no new
# statements should be allowed to prepare. # statements should be allowed to prepare.
# #
select @@prepared_stmt_count, @@max_prepared_stmt_count; show status like 'prepared_stmt_count';
select @@max_prepared_stmt_count;
set global max_prepared_stmt_count=0; set global max_prepared_stmt_count=0;
--error ER_MAX_PREPARED_STMT_COUNT_REACHED --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt from "select 1"; prepare stmt from "select 1";
# Result: the old statement is deallocated, the new is not created. # Result: the old statement is deallocated, the new is not created.
--error 1243 # ER_UNKNOWN_STMT_HANDLER --error ER_UNKNOWN_STMT_HANDLER
execute stmt; execute stmt;
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
--error ER_MAX_PREPARED_STMT_COUNT_REACHED --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt from "select 1"; prepare stmt from "select 1";
select @@prepared_stmt_count; show status like 'prepared_stmt_count';
# #
# G. Show that the variables are up to date even after a connection with all # G. Show that the variables are up to date even after a connection with all
# statements in it was terminated. # statements in it was terminated.
# #
set global max_prepared_stmt_count=3; set global max_prepared_stmt_count=3;
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count;
show status like 'prepared_stmt_count';
prepare stmt from "select 1"; prepare stmt from "select 1";
connect (con1,localhost,root,,); connect (con1,localhost,root,,);
connection con1; connection con1;
...@@ -944,26 +944,31 @@ prepare stmt1 from "select 3"; ...@@ -944,26 +944,31 @@ prepare stmt1 from "select 3";
--error ER_MAX_PREPARED_STMT_COUNT_REACHED --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt2 from "select 4"; prepare stmt2 from "select 4";
connection default; connection default;
--error ER_MAX_PREPARED_STMT_COUNT_REACHED --error ER_MAX_PREPARED_STMT_COUNT_REACHED
prepare stmt2 from "select 4"; prepare stmt2 from "select 4";
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_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 # Wait for the connection to die: deal with a possible race
deallocate prepare stmt; deallocate prepare stmt;
let $count= `select @@prepared_stmt_count`; let $query= select variable_value from information_schema.global_status
where variable_name = 'prepared_stmt_count';
let $count= `$query`;
if ($count) if ($count)
{ {
--sleep 2 --sleep 1
let $count= `select @@prepared_stmt_count`; let $count= `$query`;
} }
select @@max_prepared_stmt_count, @@prepared_stmt_count; select @@max_prepared_stmt_count;
show status like 'prepared_stmt_count';
# #
# Restore the old value. # Restore the old value.
# #
set global max_prepared_stmt_count= @old_max_prepared_stmt_count; set global max_prepared_stmt_count= @old_max_prepared_stmt_count;
--enable_ps_protocol --enable_ps_protocol
# #
# Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating # Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating
# tables" # tables"
......
...@@ -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,6 +6757,7 @@ SHOW_VAR status_vars[]= { ...@@ -6747,6 +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*) &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},
...@@ -6926,6 +6937,7 @@ static void mysql_init_variables(void) ...@@ -6926,6 +6937,7 @@ static void mysql_init_variables(void)
binlog_cache_use= binlog_cache_disk_use= 0; binlog_cache_use= binlog_cache_disk_use= 0;
max_used_connections= slow_launch_threads = 0; max_used_connections= slow_launch_threads = 0;
mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0; mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0;
prepared_stmt_count= 0;
errmesg= 0; errmesg= 0;
mysqld_unix_port= opt_mysql_tmpdir= my_bind_addr_str= NullS; mysqld_unix_port= opt_mysql_tmpdir= my_bind_addr_str= NullS;
bzero((gptr) &mysql_tmpdir_list, sizeof(mysql_tmpdir_list)); bzero((gptr) &mysql_tmpdir_list, sizeof(mysql_tmpdir_list));
......
...@@ -155,7 +155,6 @@ static KEY_CACHE *create_key_cache(const char *name, uint length); ...@@ -155,7 +155,6 @@ static KEY_CACHE *create_key_cache(const char *name, uint length);
void fix_sql_mode_var(THD *thd, enum_var_type type); void fix_sql_mode_var(THD *thd, enum_var_type type);
static byte *get_error_count(THD *thd); static byte *get_error_count(THD *thd);
static byte *get_warning_count(THD *thd); static byte *get_warning_count(THD *thd);
static byte *get_prepared_stmt_count(THD *thd);
static byte *get_tmpdir(THD *thd); static byte *get_tmpdir(THD *thd);
static int sys_check_log_path(THD *thd, set_var *var); static int sys_check_log_path(THD *thd, set_var *var);
static bool sys_update_general_log_path(THD *thd, set_var * var); static bool sys_update_general_log_path(THD *thd, set_var * var);
...@@ -639,9 +638,6 @@ static sys_var_readonly sys_warning_count("warning_count", ...@@ -639,9 +638,6 @@ static sys_var_readonly sys_warning_count("warning_count",
OPT_SESSION, OPT_SESSION,
SHOW_LONG, SHOW_LONG,
get_warning_count); get_warning_count);
static sys_var_readonly sys_prepared_stmt_count("prepared_stmt_count",
OPT_GLOBAL, SHOW_LONG,
get_prepared_stmt_count);
/* alias for last_insert_id() to be compatible with Sybase */ /* alias for last_insert_id() to be compatible with Sybase */
#ifdef HAVE_REPLICATION #ifdef HAVE_REPLICATION
...@@ -956,7 +952,6 @@ SHOW_VAR init_vars[]= { ...@@ -956,7 +952,6 @@ SHOW_VAR init_vars[]= {
{"plugin_dir", (char*) opt_plugin_dir, SHOW_CHAR}, {"plugin_dir", (char*) opt_plugin_dir, SHOW_CHAR},
{"port", (char*) &mysqld_port, SHOW_INT}, {"port", (char*) &mysqld_port, SHOW_INT},
{sys_preload_buff_size.name, (char*) &sys_preload_buff_size, SHOW_SYS}, {sys_preload_buff_size.name, (char*) &sys_preload_buff_size, SHOW_SYS},
{sys_prepared_stmt_count.name, (char*) &sys_prepared_stmt_count, SHOW_SYS},
{"protocol_version", (char*) &protocol_version, SHOW_INT}, {"protocol_version", (char*) &protocol_version, SHOW_INT},
{sys_query_alloc_block_size.name, (char*) &sys_query_alloc_block_size, {sys_query_alloc_block_size.name, (char*) &sys_query_alloc_block_size,
SHOW_SYS}, SHOW_SYS},
...@@ -3151,14 +3146,6 @@ static byte *get_error_count(THD *thd) ...@@ -3151,14 +3146,6 @@ static byte *get_error_count(THD *thd)
return (byte*) &thd->sys_var_tmp.long_value; return (byte*) &thd->sys_var_tmp.long_value;
} }
static byte *get_prepared_stmt_count(THD *thd)
{
pthread_mutex_lock(&LOCK_prepared_stmt_count);
thd->sys_var_tmp.ulong_value= prepared_stmt_count;
pthread_mutex_unlock(&LOCK_prepared_stmt_count);
return (byte*) &thd->sys_var_tmp.ulong_value;
}
/* /*
Get the tmpdir that was specified or chosen by default Get the tmpdir that was specified or chosen by default
......
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