[Commits] f69bf1e: MDEV-7006 MDEV-7007: SET STATEMENT and slow log

sanja at mariadb.com sanja at mariadb.com
Mon Feb 16 15:29:03 EET 2015


revision-id: f69bf1ead4c27126457ec50f869c992e7ba0437d
parent(s): cbc318fcf3680c01dca1320b87f625124a497528
committer: Oleksandr Byelkin
branch nick: work-maria-10.1-MDEV-6997
timestamp: 2015-02-16 14:28:05 +0100
message:

MDEV-7006 MDEV-7007: SET STATEMENT and slow log
fixed embedded server tests
MDEV-7009: SET STATEMENT min_examined_row_limit has no effect
MDEV-6948:SET STATEMENT gtid_domain_id = ... FOR has no effect (same for gtid_seq_no and server_id)

old values of SET STATENENT variables now saved in its own Query_arena and restored later

---
 mysql-test/r/set_statement.result                  | 120 ++++++++++++++-------
 mysql-test/r/set_statement_notembedded.result      |  21 ++++
 .../r/set_statement_notembedded_binlog.result      |  19 ++++
 mysql-test/t/set_statement.test                    |  83 +++++++++-----
 mysql-test/t/set_statement_notembedded.test        |  17 +++
 mysql-test/t/set_statement_notembedded_binlog.test |  22 ++++
 sql/log_event.cc                                   |   1 +
 sql/sp_head.cc                                     |   1 +
 sql/sql_class.h                                    |   1 +
 sql/sql_cursor.cc                                  |   1 +
 sql/sql_lex.cc                                     |  52 ++++++++-
 sql/sql_lex.h                                      |   8 ++
 sql/sql_parse.cc                                   |  13 ++-
 sql/sql_prepare.cc                                 |   4 +-
 sql/sys_vars.cc                                    |  14 +--
 15 files changed, 303 insertions(+), 74 deletions(-)

diff --git a/mysql-test/r/set_statement.result b/mysql-test/r/set_statement.result
index efe5286..641052b 100644
--- a/mysql-test/r/set_statement.result
+++ b/mysql-test/r/set_statement.result
@@ -1020,24 +1020,6 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 SET @@default_storage_engine=@save_dfs;
-SELECT @@MAX_STATEMENT_TIME;
-@@MAX_STATEMENT_TIME
-0.000000
-SET STATEMENT MAX_STATEMENT_TIME=2 FOR SELECT SLEEP(1);
-SLEEP(1)
-0
-SHOW STATUS LIKE "max_statement_time_exceeded";
-Variable_name	Value
-Max_statement_time_exceeded	0
-SET STATEMENT MAX_STATEMENT_TIME=2 FOR SELECT SLEEP(3);
-SLEEP(3)
-1
-SHOW STATUS LIKE "max_statement_time_exceeded";
-Variable_name	Value
-Max_statement_time_exceeded	1
-SELECT @@MAX_STATEMENT_TIME;
-@@MAX_STATEMENT_TIME
-0.000000
 SET STATEMENT keycache1.key_buffer_size=1024 FOR SELECT 1;
 ERROR HY000: Variable 'key_buffer_size' is a GLOBAL variable and should be set with SET GLOBAL
 set @save_general_log=@@global.general_log;
@@ -1052,10 +1034,92 @@ set statement lock_wait_timeout=1 for select @@lock_wait_timeout;
 @@lock_wait_timeout
 1
 set global general_log=@save_general_log;
+# MDEV-7006 MDEV-7007: SET statement and slow log
+set @save_long_query_time= @@long_query_time;
+set @save_slow_query_log= @@slow_query_log;
+set @save_log_output= @@log_output;
+set statement long_query_time=default for select @@long_query_time;
+@@long_query_time
+10.000000
+set statement log_slow_filter=default for select @@log_slow_filter;
+@@log_slow_filter
+admin,filesort,filesort_on_disk,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk
+set statement log_slow_verbosity=default for select @@log_slow_verbosity;
+@@log_slow_verbosity
+
+set statement log_slow_rate_limit=default for select @@log_slow_rate_limit;
+@@log_slow_rate_limit
+1
+set statement slow_query_log=default for select @@slow_query_log;
+@@slow_query_log
+1
+truncate table mysql.slow_log;
+set slow_query_log= 1;
+set global log_output='TABLE';
+select sql_text from mysql.slow_log;
+sql_text
+set @@long_query_time=0.01;
+#should be written
+select sleep(0.1);
+sleep(0.1)
+0
+set @@long_query_time=@save_long_query_time;
+select sql_text from mysql.slow_log;
+sql_text
+select sleep(0.1)
+#---
+#should be written
+set statement long_query_time=0.01 for select sleep(0.1);
+sleep(0.1)
+0
+select sql_text from mysql.slow_log;
+sql_text
+select sleep(0.1)
+set statement long_query_time=0.01 for select sleep(0.1)
+#---
+set @@long_query_time=0.01;
+#should NOT be written
+set statement slow_query_log=0 for select sleep(0.1);
+sleep(0.1)
+0
+set @@long_query_time=@save_long_query_time;
+select sql_text from mysql.slow_log;
+sql_text
+select sleep(0.1)
+set statement long_query_time=0.01 for select sleep(0.1)
+#---
+#should NOT be written
+set statement long_query_time=0.01,log_slow_filter='full_scan' for select sleep(0.1);
+sleep(0.1)
+0
+select sql_text from mysql.slow_log;
+sql_text
+select sleep(0.1)
+set statement long_query_time=0.01 for select sleep(0.1)
+#---
+#should NOT be written
+set statement long_query_time=0.01,log_slow_rate_limit=9999 for select sleep(0.1);
+sleep(0.1)
+0
+select sql_text from mysql.slow_log;
+sql_text
+select sleep(0.1)
+set statement long_query_time=0.01 for select sleep(0.1)
+#---
+#should NOT be written
+set statement long_query_time=0.01,min_examined_row_limit=50 for select sleep(0.1);
+sleep(0.1)
+0
+select sql_text from mysql.slow_log;
+sql_text
+select sleep(0.1)
+set statement long_query_time=0.01 for select sleep(0.1)
+#---
+set global log_output= @save_log_output;
+set @@slow_query_log= @save_slow_query_log;
+set @@long_query_time= @save_long_query_time;
 set statement autocommit=default for select 1;
 ERROR 42000: The system variable autocommit cannot be set in SET STATEMENT.
-set statement gtid_domain_id=default for select 1;
-ERROR 42000: The system variable gtid_domain_id cannot be set in SET STATEMENT.
 set statement tx_isolation=default for select 1;
 ERROR 42000: The system variable tx_isolation cannot be set in SET STATEMENT.
 set statement rand_seed1=default for select 1;
@@ -1064,26 +1128,10 @@ set statement rand_seed2=default for select 1;
 ERROR 42000: The system variable rand_seed2 cannot be set in SET STATEMENT.
 set statement skip_replication=default for select 1;
 ERROR 42000: The system variable skip_replication cannot be set in SET STATEMENT.
-set statement default_master_connection=default for select 1;
-ERROR 42000: The system variable default_master_connection cannot be set in SET STATEMENT.
-set statement default_master_connection=default for select 1;
-ERROR 42000: The system variable default_master_connection cannot be set in SET STATEMENT.
 set statement last_insert_id=1 for select 1;
 ERROR 42000: The system variable last_insert_id cannot be set in SET STATEMENT.
 set statement sql_log_off=default for select 1;
 ERROR 42000: The system variable sql_log_off cannot be set in SET STATEMENT.
-set statement long_query_time=default for select 1;
-ERROR 42000: The system variable long_query_time cannot be set in SET STATEMENT.
-set statement log_slow_filter=default for select 1;
-ERROR 42000: The system variable log_slow_filter cannot be set in SET STATEMENT.
-set statement log_slow_verbosity=default for select 1;
-ERROR 42000: The system variable log_slow_verbosity cannot be set in SET STATEMENT.
-set statement log_slow_rate_limit=default for select 1;
-ERROR 42000: The system variable log_slow_rate_limit cannot be set in SET STATEMENT.
-set statement slow_query_log=default for select 1;
-ERROR 42000: The system variable slow_query_log cannot be set in SET STATEMENT.
-set statement min_examined_row_limit=default for select 1;
-ERROR 42000: The system variable min_examined_row_limit cannot be set in SET STATEMENT.
 set statement character_set_client=default for select 1;
 ERROR 42000: The system variable character_set_client cannot be set in SET STATEMENT.
 set statement character_set_connection=default for select 1;
diff --git a/mysql-test/r/set_statement_notembedded.result b/mysql-test/r/set_statement_notembedded.result
new file mode 100644
index 0000000..866ebf5
--- /dev/null
+++ b/mysql-test/r/set_statement_notembedded.result
@@ -0,0 +1,21 @@
+flush status;
+SELECT @@MAX_STATEMENT_TIME;
+@@MAX_STATEMENT_TIME
+0.000000
+SET STATEMENT MAX_STATEMENT_TIME=2 FOR SELECT SLEEP(1);
+SLEEP(1)
+0
+SHOW STATUS LIKE "max_statement_time_exceeded";
+Variable_name	Value
+Max_statement_time_exceeded	0
+SET STATEMENT MAX_STATEMENT_TIME=2 FOR SELECT SLEEP(3);
+SLEEP(3)
+1
+SHOW STATUS LIKE "max_statement_time_exceeded";
+Variable_name	Value
+Max_statement_time_exceeded	1
+SELECT @@MAX_STATEMENT_TIME;
+@@MAX_STATEMENT_TIME
+0.000000
+set statement default_master_connection=default for select 1;
+ERROR 42000: The system variable default_master_connection cannot be set in SET STATEMENT.
diff --git a/mysql-test/r/set_statement_notembedded_binlog.result b/mysql-test/r/set_statement_notembedded_binlog.result
new file mode 100644
index 0000000..03c4915
--- /dev/null
+++ b/mysql-test/r/set_statement_notembedded_binlog.result
@@ -0,0 +1,19 @@
+drop table if exists t1;
+drop view if exists t1;
+#
+# MDEV-6948: SET STATEMENT gtid_domain_id = ... FOR has no effect
+# (same for gtid_seq_no and server_id)
+#
+PURGE BINARY LOGS before now();
+create table t1 (i int);
+set gtid_domain_id = 10;
+insert into t1 values (1),(2);
+set statement gtid_domain_id = 20 for insert into t1 values (3),(4);
+show binlog events limit 9,5;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+x	x	x	x	x	BEGIN GTID 10-1-1
+x	x	x	x	x	use `test`; insert into t1 values (1),(2)
+x	x	x	x	x	COMMIT
+x	x	x	x	x	BEGIN GTID 20-1-1
+x	x	x	x	x	use `test`; set statement gtid_domain_id = 20 for insert into t1 values (3),(4)
+drop table t1;
diff --git a/mysql-test/t/set_statement.test b/mysql-test/t/set_statement.test
index a658071..951a36e 100644
--- a/mysql-test/t/set_statement.test
+++ b/mysql-test/t/set_statement.test
@@ -966,16 +966,6 @@ drop table t1;
 SET @@default_storage_engine=@save_dfs;
 
 #
-# statement timeout
-#
-SELECT @@MAX_STATEMENT_TIME;
-SET STATEMENT MAX_STATEMENT_TIME=2 FOR SELECT SLEEP(1);
-SHOW STATUS LIKE "max_statement_time_exceeded";
-SET STATEMENT MAX_STATEMENT_TIME=2 FOR SELECT SLEEP(3);
-SHOW STATUS LIKE "max_statement_time_exceeded";
-SELECT @@MAX_STATEMENT_TIME;
-
-#
 # MDEV-6946:Assertion `0' failed in mysql_execute_command on SET STATEMENT
 # keycache1.key_buffer_size=.. FOR
 #
@@ -995,14 +985,67 @@ set global general_log=0;
 set statement lock_wait_timeout=1 for select @@lock_wait_timeout;
 set global general_log=@save_general_log;
 
+--echo # MDEV-7006 MDEV-7007: SET statement and slow log
+
+set @save_long_query_time= @@long_query_time;
+set @save_slow_query_log= @@slow_query_log;
+set @save_log_output= @@log_output;
+
+set statement long_query_time=default for select @@long_query_time;
+set statement log_slow_filter=default for select @@log_slow_filter;
+set statement log_slow_verbosity=default for select @@log_slow_verbosity;
+set statement log_slow_rate_limit=default for select @@log_slow_rate_limit;
+set statement slow_query_log=default for select @@slow_query_log;
+
+truncate table mysql.slow_log;
+set slow_query_log= 1;
+set global log_output='TABLE';
+
+select sql_text from mysql.slow_log;
+set @@long_query_time=0.01;
+--echo #should be written
+select sleep(0.1);
+set @@long_query_time=@save_long_query_time;
+select sql_text from mysql.slow_log;
+--echo #---
+--echo #should be written
+set statement long_query_time=0.01 for select sleep(0.1);
+select sql_text from mysql.slow_log;
+--echo #---
+set @@long_query_time=0.01;
+--echo #should NOT be written
+set statement slow_query_log=0 for select sleep(0.1);
+set @@long_query_time=@save_long_query_time;
+select sql_text from mysql.slow_log;
+--echo #---
+--echo #should NOT be written
+set statement long_query_time=0.01,log_slow_filter='full_scan' for select sleep(0.1);
+select sql_text from mysql.slow_log;
+--echo #---
+--echo #should NOT be written
+set statement long_query_time=0.01,log_slow_rate_limit=9999 for select sleep(0.1);
+select sql_text from mysql.slow_log;
+--echo #---
+--echo #should NOT be written
+set statement long_query_time=0.01,min_examined_row_limit=50 for select sleep(0.1);
+select sql_text from mysql.slow_log;
+--echo #---
+#
+# log_slow_verbosity is impossible to check because results are not written
+# in TABLE mode
+#
+
+set global log_output= @save_log_output;
+set @@slow_query_log= @save_slow_query_log;
+set @@long_query_time= @save_long_query_time;
+
+
 #
 # Prohibited Variables
 #
 --error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement autocommit=default for select 1;
 --error ER_SET_STATEMENT_NOT_SUPPORTED
-set statement gtid_domain_id=default for select 1;
---error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement tx_isolation=default for select 1;
 --error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement rand_seed1=default for select 1;
@@ -1011,26 +1054,10 @@ set statement rand_seed2=default for select 1;
 --error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement skip_replication=default for select 1;
 --error ER_SET_STATEMENT_NOT_SUPPORTED
-set statement default_master_connection=default for select 1;
---error ER_SET_STATEMENT_NOT_SUPPORTED
-set statement default_master_connection=default for select 1;
---error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement last_insert_id=1 for select 1;
 --error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement sql_log_off=default for select 1;
 --error ER_SET_STATEMENT_NOT_SUPPORTED
-set statement long_query_time=default for select 1;
---error ER_SET_STATEMENT_NOT_SUPPORTED
-set statement log_slow_filter=default for select 1;
---error ER_SET_STATEMENT_NOT_SUPPORTED
-set statement log_slow_verbosity=default for select 1;
---error ER_SET_STATEMENT_NOT_SUPPORTED
-set statement log_slow_rate_limit=default for select 1;
---error ER_SET_STATEMENT_NOT_SUPPORTED
-set statement slow_query_log=default for select 1;
---error ER_SET_STATEMENT_NOT_SUPPORTED
-set statement min_examined_row_limit=default for select 1;
---error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement character_set_client=default for select 1;
 --error ER_SET_STATEMENT_NOT_SUPPORTED
 set statement character_set_connection=default for select 1;
diff --git a/mysql-test/t/set_statement_notembedded.test b/mysql-test/t/set_statement_notembedded.test
new file mode 100644
index 0000000..b7d5a72
--- /dev/null
+++ b/mysql-test/t/set_statement_notembedded.test
@@ -0,0 +1,17 @@
+
+source include/not_embedded.inc;
+
+#
+# statement timeout
+#
+flush status;
+SELECT @@MAX_STATEMENT_TIME;
+SET STATEMENT MAX_STATEMENT_TIME=2 FOR SELECT SLEEP(1);
+SHOW STATUS LIKE "max_statement_time_exceeded";
+SET STATEMENT MAX_STATEMENT_TIME=2 FOR SELECT SLEEP(3);
+SHOW STATUS LIKE "max_statement_time_exceeded";
+SELECT @@MAX_STATEMENT_TIME;
+
+# Prohibited Variables
+--error ER_SET_STATEMENT_NOT_SUPPORTED
+set statement default_master_connection=default for select 1;
diff --git a/mysql-test/t/set_statement_notembedded_binlog.test b/mysql-test/t/set_statement_notembedded_binlog.test
new file mode 100644
index 0000000..70d7ef7
--- /dev/null
+++ b/mysql-test/t/set_statement_notembedded_binlog.test
@@ -0,0 +1,22 @@
+--source include/have_log_bin.inc
+--source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1;
+drop view if exists t1;
+--enable_warnings
+
+--echo #
+--echo # MDEV-6948: SET STATEMENT gtid_domain_id = ... FOR has no effect
+--echo # (same for gtid_seq_no and server_id)
+--echo #
+PURGE BINARY LOGS before now();
+create table t1 (i int);
+set gtid_domain_id = 10;
+insert into t1 values (1),(2);
+set statement gtid_domain_id = 20 for insert into t1 values (3),(4);
+
+--replace_column 1 x 2 x 3 x 4 x 5 x
+show binlog events limit 9,5;
+
+drop table t1;
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 7617077..bb4c517 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -4290,6 +4290,7 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi,
 
         thd->enable_slow_log= thd->variables.sql_log_slow;
         mysql_parse(thd, thd->query(), thd->query_length(), &parser_state);
+        thd->lex->restore_set_statement_var();
         /* Finalize server status flags after executing a statement. */
         thd->update_server_status();
         log_slow_statement(thd);
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 296135c..391b274 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -3013,6 +3013,7 @@ void sp_head::add_mark_lead(uint ip, List<sp_instr> *leads)
 
     cleanup_items() is called in sp_head::execute()
   */
+  thd->lex->restore_set_statement_var();
   DBUG_RETURN(res || thd->is_error());
 }
 
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 7a34960..d289840 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3647,6 +3647,7 @@ class THD :public Statement,
     return backup;
   }
 
+
   void clear_wakeup_ready() { wakeup_ready= false; }
   /*
     Sleep waiting for others to wake us up with signal_wakeup_ready().
diff --git a/sql/sql_cursor.cc b/sql/sql_cursor.cc
index a38077c..b1293b1 100644
--- a/sql/sql_cursor.cc
+++ b/sql/sql_cursor.cc
@@ -121,6 +121,7 @@ int mysql_open_cursor(THD *thd, select_result *result,
   /* Mark that we can't use query cache with cursors */
   thd->query_cache_is_applicable= 0;
   rc= mysql_execute_command(thd);
+  thd->lex->restore_set_statement_var();
   thd->m_statement_psi= parent_locker;
   MYSQL_QUERY_EXEC_DONE(rc);
 
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 6432e19..08094ce 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -2640,7 +2640,8 @@ void Query_tables_list::destroy_query_tables_list()
 
 LEX::LEX()
   : explain(NULL),
-    result(0), option_type(OPT_DEFAULT), sphead(0),
+    result(0), arena_for_set_stmt(0),
+    option_type(OPT_DEFAULT), sphead(0),
     is_lex_started(0), limit_rows_examined_cnt(ULONGLONG_MAX)
 {
 
@@ -4235,6 +4236,53 @@ int LEX::print_explain(select_result_sink *output, uint8 explain_flags,
   return res;
 }
 
+void LEX::set_arena_for_set_stmt(Query_arena *backup)
+{
+  DBUG_ENTER("LEX::set_arena_for_set_stmt");
+  DBUG_ASSERT(arena_for_set_stmt== 0);
+  MEM_ROOT *mem_root= new MEM_ROOT();
+  if (!(mem_root))
+    DBUG_VOID_RETURN;
+  init_sql_alloc(mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0,
+                 MYF(MY_THREAD_SPECIFIC));
+  if (!(arena_for_set_stmt= new Query_arena(mem_root,
+                                            Query_arena::STMT_INITIALIZED)))
+    DBUG_VOID_RETURN;
+  DBUG_PRINT("info", ("mem_root: 0x%lx  arena: 0x%lx",
+                      (ulong) mem_root, (ulong) arena_for_set_stmt));
+  thd->set_n_backup_active_arena(arena_for_set_stmt, backup);
+  DBUG_VOID_RETURN;
+}
+
+
+void LEX::reset_arena_for_set_stmt(Query_arena *backup)
+{
+  DBUG_ENTER("LEX::reset_arena_for_set_stmt");
+  DBUG_ASSERT(arena_for_set_stmt);
+  thd->restore_active_arena(arena_for_set_stmt, backup);
+  DBUG_PRINT("info", ("mem_root: 0x%lx  arena: 0x%lx",
+                      (ulong) arena_for_set_stmt->mem_root,
+                      (ulong) arena_for_set_stmt));
+  DBUG_VOID_RETURN;
+}
+
+
+void LEX::free_arena_for_set_stmt()
+{
+  DBUG_ENTER("LEX::free_arena_for_set_stmt");
+  if (!arena_for_set_stmt)
+    return;
+  DBUG_PRINT("info", ("mem_root: 0x%lx  arena: 0x%lx",
+                      (ulong) arena_for_set_stmt->mem_root,
+                      (ulong) arena_for_set_stmt));
+  arena_for_set_stmt->free_items();
+  free_root(arena_for_set_stmt->mem_root, MYF(0));
+  delete(arena_for_set_stmt->mem_root);
+  delete(arena_for_set_stmt);
+  arena_for_set_stmt= 0;
+  DBUG_VOID_RETURN;
+}
+
 void LEX::restore_set_statement_var()
 {
   DBUG_ENTER("LEX::restore_set_statement_var");
@@ -4243,7 +4291,9 @@ void LEX::restore_set_statement_var()
     DBUG_PRINT("info", ("vars: %d", old_var_list.elements));
     sql_set_variables(thd, &old_var_list, false);
     old_var_list.empty();
+    free_arena_for_set_stmt();
   }
+  DBUG_ASSERT(!is_arena_for_set_stmt());
   DBUG_VOID_RETURN;
 }
 
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 6c631e2..224e7d0 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -2403,6 +2403,14 @@ struct LEX: public Query_tables_list
   List<set_var_base>  var_list;
   List<set_var_base>  stmt_var_list; //SET_STATEMENT values
   List<set_var_base>  old_var_list; // SET STATEMENT old values
+private:
+  Query_arena *arena_for_set_stmt;
+public:
+  inline bool is_arena_for_set_stmt() {return arena_for_set_stmt != 0;}
+  void set_arena_for_set_stmt(Query_arena *backup);
+  void reset_arena_for_set_stmt(Query_arena *backup);
+  void free_arena_for_set_stmt();
+
   List<Item_func_set_user_var> set_var_list; // in-query assignment list
   List<Item_param>    param_list;
   List<LEX_STRING>    view_list; // view list (list of field names in view)
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 5af700b..ae831d0 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -805,6 +805,7 @@ static void handle_bootstrap_impl(THD *thd)
 
     free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
     free_root(&thd->transaction.mem_root,MYF(MY_KEEP_PREALLOC));
+    thd->lex->restore_set_statement_var();
   }
 
   DBUG_VOID_RETURN;
@@ -1126,6 +1127,7 @@ bool do_command(THD *thd)
   DBUG_ASSERT(!thd->apc_target.is_enabled());
 
 out:
+  thd->lex->restore_set_statement_var();
   /* The statement instrumentation must be closed in all cases. */
   DBUG_ASSERT(thd->m_statement_psi == NULL);
   DBUG_RETURN(return_value);
@@ -1956,6 +1958,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
 
   /* Check that some variables are reset properly */
   DBUG_ASSERT(thd->abort_on_warning == 0);
+  thd->lex->restore_set_statement_var();
   DBUG_RETURN(error);
 }
 
@@ -2637,11 +2640,13 @@ static bool do_execute_sp(THD *thd, sp_head *sp)
 
   if (!lex->stmt_var_list.is_empty() && !thd->slave_thread)
   {
+    Query_arena backup;
     DBUG_PRINT("info", ("SET STATEMENT %d vars", lex->stmt_var_list.elements));
 
     lex->old_var_list.empty();
     List_iterator_fast<set_var_base> it(lex->stmt_var_list);
     set_var_base *var;
+    lex->set_arena_for_set_stmt(&backup);
     while ((var=it++))
     {
       DBUG_ASSERT(var->is_system());
@@ -2649,6 +2654,9 @@ static bool do_execute_sp(THD *thd, sp_head *sp)
       if (!v->var->is_set_stmt_ok())
       {
         my_error(ER_SET_STATEMENT_NOT_SUPPORTED, MYF(0), v->var->name.str);
+        lex->reset_arena_for_set_stmt(&backup);
+        lex->old_var_list.empty();
+        lex->free_arena_for_set_stmt();
         goto error;
       }
       if (v->var->is_default())
@@ -2721,11 +2729,15 @@ static bool do_execute_sp(THD *thd, sp_head *sp)
       DBUG_ASSERT(o);
       lex->old_var_list.push_back(o);
     }
+    lex->reset_arena_for_set_stmt(&backup);
+    if (lex->old_var_list.is_empty())
+      lex->free_arena_for_set_stmt();
     if (thd->is_error() ||
         (res= sql_set_variables(thd, &lex->stmt_var_list, false)))
     {
       if (!thd->is_error())
         my_error(ER_WRONG_ARGUMENTS, MYF(0), "SET");
+      lex->restore_set_statement_var();
       goto error;
     }
   }
@@ -5577,7 +5589,6 @@ static bool do_execute_sp(THD *thd, sp_head *sp)
                thd->in_multi_stmt_transaction_mode());
 
 
-  lex->restore_set_statement_var();
   lex->unit.cleanup();
 
   if (! thd->in_sub_stmt)
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 5c67a4c..50ae8d7 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -2799,7 +2799,7 @@ void mysql_sql_stmt_execute(THD *thd)
   DBUG_PRINT("info",("stmt: 0x%lx", (long) stmt));
 
   (void) stmt->execute_loop(&expanded_query, FALSE, NULL, NULL);
-
+  stmt->lex->restore_set_statement_var();
   DBUG_VOID_RETURN;
 }
 
@@ -3189,6 +3189,7 @@ bool Select_fetch_protocol_binary::send_eof()
                       thd->query(), thd->query_length());
 
 end:
+  thd->lex->restore_set_statement_var();
   lex_end(thd->lex);
 
   return error;
@@ -4114,6 +4115,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
     general_log_write(thd, COM_STMT_EXECUTE, thd->query(), thd->query_length());
 
 error:
+  thd->lex->restore_set_statement_var();
   flags&= ~ (uint) IS_IN_USE;
   return error;
 }
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index a7d5843..767d174 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -1182,7 +1182,7 @@ static Sys_var_double Sys_long_query_time(
        "Log all queries that have taken more than long_query_time seconds "
        "to execute to file. The argument will be treated as a decimal value "
        "with microsecond precision",
-       NO_SET_STMT SESSION_VAR(long_query_time_double),
+       SESSION_VAR(long_query_time_double),
        CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(10),
        NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
        ON_UPDATE(update_cached_long_query_time));
@@ -1437,7 +1437,7 @@ static Sys_var_uint Sys_gtid_domain_id(
        "parallel paths (for example multiple masters), each independent "
        "source server must use a distinct domain_id. For simple tree-shaped "
        "replication topologies, it can be left at its default, 0.",
-       NO_SET_STMT SESSION_VAR(gtid_domain_id),
+       SESSION_VAR(gtid_domain_id),
        CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, UINT_MAX32), DEFAULT(0),
        BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG,
        ON_CHECK(check_gtid_domain_id));
@@ -2037,7 +2037,7 @@ static Sys_var_ulong Sys_min_examined_row_limit(
        "min_examined_row_limit",
        "Don't write queries to slow log that examine fewer rows "
        "than that",
-       NO_SET_STMT SESSION_VAR(min_examined_row_limit), CMD_LINE(REQUIRED_ARG),
+       SESSION_VAR(min_examined_row_limit), CMD_LINE(REQUIRED_ARG),
        VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1));
 
 #ifdef _WIN32
@@ -3964,7 +3964,7 @@ static Sys_var_mybool Sys_slow_query_log(
        "Log slow queries to a table or log file. Defaults logging to a file "
        "'hostname'-slow.log or a table mysql.slow_log if --log-output=TABLE is "
        "used. Must be enabled to activate other slow log options",
-       NO_SET_STMT SESSION_VAR(sql_log_slow), CMD_LINE(OPT_ARG),
+       SESSION_VAR(sql_log_slow), CMD_LINE(OPT_ARG),
        DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
        ON_CHECK(0), ON_UPDATE(fix_log_state));
 
@@ -4835,7 +4835,7 @@ static Sys_var_keycache Sys_key_cache_segments(
 static Sys_var_set Sys_log_slow_filter(
        "log_slow_filter",
        "Log only certain types of queries",
-       NO_SET_STMT SESSION_VAR(log_slow_filter), CMD_LINE(REQUIRED_ARG),
+       SESSION_VAR(log_slow_filter), CMD_LINE(REQUIRED_ARG),
        log_slow_filter_names,
        DEFAULT(MAX_SET(array_elements(log_slow_filter_names)-1)));
 
@@ -4882,7 +4882,7 @@ static Sys_var_ulong Sys_log_slow_rate_limit(
        "Write to slow log every #th slow query. Set to 1 to log everything. "
        "Increase it to reduce the size of the slow or the performance impact "
        "of slow logging",
-       NO_SET_STMT SESSION_VAR(log_slow_rate_limit), CMD_LINE(REQUIRED_ARG),
+       SESSION_VAR(log_slow_rate_limit), CMD_LINE(REQUIRED_ARG),
        VALID_RANGE(1, UINT_MAX), DEFAULT(1), BLOCK_SIZE(1));
 
 static const char *log_slow_verbosity_names[]= { "innodb", "query_plan", 
@@ -4890,7 +4890,7 @@ static Sys_var_ulong Sys_log_slow_rate_limit(
 static Sys_var_set Sys_log_slow_verbosity(
        "log_slow_verbosity",
        "Verbosity level for the slow log",
-       NO_SET_STMT SESSION_VAR(log_slow_verbosity), CMD_LINE(REQUIRED_ARG),
+       SESSION_VAR(log_slow_verbosity), CMD_LINE(REQUIRED_ARG),
        log_slow_verbosity_names, DEFAULT(LOG_SLOW_VERBOSITY_INIT));
 
 static Sys_var_ulong Sys_join_cache_level(


More information about the commits mailing list