Commit 6eced1b8 authored by unknown's avatar unknown

Fix for bug #29131: SHOW VARIABLES reports variable 'log' but SET

doesn't recognize it

This is a 5.0 version of the patch, it will be null-merged to 5.1

Problem:

'log' and 'log_slow_queries' were "fixed" variables, i.e. they showed up
in SHOW VARIABLES, but could not be used in expressions like 
"select @@log". Also, using them in the SET statement produced an 
incorrect "unknown system variable" error.

Solution:

Make 'log' and 'log_slow_queries' read-only dynamic variables to make 
them available for use in expressions, and produce a correct error 
about the variable being read-only when used in the SET statement.


mysql-test/r/variables.result:
  Added a test case for bug #29131.
mysql-test/t/variables.test:
  Added a test case for bug #29131.
sql/mysql_priv.h:
  Changed the type of opt_log and opt_slow_log to my_bool to 
  align with the interfaces in set_var.cc
sql/mysqld.cc:
  Changed the type of opt_log and opt_slow_log to my_bool to 
  align with the interfaces in set_var.cc
sql/set_var.cc:
  Made 'log' and 'log_slow_queries' to be read-only dynamic system 
  variable, i.e. available for use in expressions with the @@var syntax.
sql/set_var.h:
  Added a new system variable class representing a read-only boolean
  variable.
parent 04311fab
......@@ -791,6 +791,22 @@ ERROR HY000: Variable 'hostname' is a read only variable
show variables like 'hostname';
Variable_name Value
hostname #
SHOW VARIABLES LIKE 'log';
Variable_name Value
log ON
SELECT @@log;
@@log
1
SET GLOBAL log=0;
ERROR HY000: Variable 'log' is a read only variable
SHOW VARIABLES LIKE 'log_slow_queries';
Variable_name Value
log_slow_queries ON
SELECT @@log_slow_queries;
@@log_slow_queries
1
SET GLOBAL log_slow_queries=0;
ERROR HY000: Variable 'log_slow_queries' is a read only variable
End of 5.0 tests
set global binlog_cache_size =@my_binlog_cache_size;
set global connect_timeout =@my_connect_timeout;
......
......@@ -674,6 +674,20 @@ set @@hostname= "anothername";
--replace_column 2 #
show variables like 'hostname';
#
# Bug #29131: SHOW VARIABLES reports variable 'log' but SET doesn't recognize it
#
SHOW VARIABLES LIKE 'log';
SELECT @@log;
--error 1238
SET GLOBAL log=0;
SHOW VARIABLES LIKE 'log_slow_queries';
SELECT @@log_slow_queries;
--error 1238
SET GLOBAL log_slow_queries=0;
--echo End of 5.0 tests
# This is at the very after the versioned tests, since it involves doing
......
......@@ -1306,8 +1306,8 @@ extern bool opt_endinfo, using_udf_functions;
extern my_bool locked_in_memory;
extern bool opt_using_transactions, mysqld_embedded;
extern bool using_update_log, opt_large_files, server_id_supplied;
extern bool opt_log, opt_update_log, opt_bin_log, opt_slow_log, opt_error_log;
extern my_bool opt_log_queries_not_using_indexes;
extern bool opt_update_log, opt_bin_log, opt_error_log;
extern my_bool opt_log, opt_slow_log, opt_log_queries_not_using_indexes;
extern bool opt_disable_networking, opt_skip_show_db;
extern my_bool opt_character_set_client_handshake;
extern bool volatile abort_loop, shutdown_in_progress, grant_option;
......
......@@ -339,8 +339,8 @@ static my_bool opt_sync_bdb_logs;
/* Global variables */
bool opt_log, opt_update_log, opt_bin_log, opt_slow_log;
my_bool opt_log_queries_not_using_indexes= 0;
bool opt_update_log, opt_bin_log;
my_bool opt_log, opt_slow_log, opt_log_queries_not_using_indexes= 0;
bool opt_error_log= IF_WIN(1,0);
bool opt_disable_networking=0, opt_skip_show_db=0;
my_bool opt_character_set_client_handshake= 1;
......
......@@ -201,6 +201,7 @@ sys_var_key_cache_long sys_key_cache_age_threshold("key_cache_age_threshold",
param_age_threshold));
sys_var_bool_ptr sys_local_infile("local_infile",
&opt_local_infile);
sys_var_bool_const_ptr sys_log("log", &opt_log);
sys_var_trust_routine_creators
sys_trust_routine_creators("log_bin_trust_routine_creators",
&trust_function_creators);
......@@ -213,6 +214,7 @@ sys_var_bool_ptr
sys_var_thd_ulong sys_log_warnings("log_warnings", &SV::log_warnings);
sys_var_thd_ulong sys_long_query_time("long_query_time",
&SV::long_query_time);
sys_var_bool_const_ptr sys_log_slow("log_slow_queries", &opt_slow_log);
sys_var_thd_bool sys_low_priority_updates("low_priority_updates",
&SV::low_priority_updates,
fix_low_priority_updates);
......@@ -665,9 +667,11 @@ sys_var *sys_variables[]=
&sys_lc_time_names,
&sys_license,
&sys_local_infile,
&sys_log,
&sys_log_binlog,
&sys_log_off,
&sys_log_queries_not_using_indexes,
&sys_log_slow,
&sys_log_update,
&sys_log_warnings,
&sys_long_query_time,
......@@ -946,7 +950,7 @@ struct show_var_st init_vars[]= {
#ifdef HAVE_MLOCKALL
{"locked_in_memory", (char*) &locked_in_memory, SHOW_BOOL},
#endif
{"log", (char*) &opt_log, SHOW_BOOL},
{sys_log.name, (char*) &sys_log, SHOW_SYS},
{"log_bin", (char*) &opt_bin_log, SHOW_BOOL},
{sys_trust_function_creators.name,(char*) &sys_trust_function_creators, SHOW_SYS},
{"log_error", (char*) log_error_file, SHOW_CHAR},
......@@ -955,7 +959,7 @@ struct show_var_st init_vars[]= {
#ifdef HAVE_REPLICATION
{"log_slave_updates", (char*) &opt_log_slave_updates, SHOW_MY_BOOL},
#endif
{"log_slow_queries", (char*) &opt_slow_log, SHOW_BOOL},
{sys_log_slow.name, (char*) &sys_log_slow, SHOW_SYS},
{sys_log_warnings.name, (char*) &sys_log_warnings, SHOW_SYS},
{sys_long_query_time.name, (char*) &sys_long_query_time, SHOW_SYS},
{sys_low_priority_updates.name, (char*) &sys_low_priority_updates, SHOW_SYS},
......
......@@ -160,6 +160,28 @@ public:
};
class sys_var_bool_const_ptr : public sys_var
{
public:
my_bool *value;
sys_var_bool_const_ptr(const char *name_arg, my_bool *value_arg)
:sys_var(name_arg),value(value_arg)
{}
bool check(THD *thd, set_var *var)
{
return 1;
}
bool update(THD *thd, set_var *var)
{
return 1;
}
SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
{ return (byte*) value; }
bool check_update_type(Item_result type) { return 0; }
bool is_readonly() const { return 1; }
};
class sys_var_str :public sys_var
{
public:
......
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