[Commits] 7ceff99: MDEV-6954: SET STATEMENT rand_seedX = ...FOR ... makes the next rand() to return 0

sanja at mariadb.com sanja at mariadb.com
Wed Mar 11 12:02:16 EET 2015


revision-id: 7ceff99ff25b74bb188848ce0e5f9e2f1ddac3d0
parent(s): 9f4ee16bf351ea2969d73abcdea92e70538c723c
committer: Oleksandr Byelkin
branch nick: server
timestamp: 2015-03-11 11:02:13 +0100
message:

MDEV-6954: SET STATEMENT rand_seedX = ...FOR ... makes the next rand() to return 0

The variables now return real values. They can't be made usual variables because they do not have DEFAULT value.

---
 mysql-test/r/set_statement.result                  | 14 ++++++++---
 mysql-test/suite/sys_vars/inc/sysvars_server.inc   |  1 +
 .../suite/sys_vars/r/rand_seed1_basic.result       | 13 ++++++----
 .../suite/sys_vars/r/rand_seed2_basic.result       | 13 ++++++----
 .../sys_vars/r/sysvars_server_notembedded.result   | 29 +---------------------
 mysql-test/suite/sys_vars/t/rand_seed1_basic.test  |  3 +++
 mysql-test/suite/sys_vars/t/rand_seed2_basic.test  |  3 +++
 mysql-test/t/set_statement.test                    | 24 +++++++++++++++---
 sql/sys_vars.cc                                    | 16 +++++++-----
 9 files changed, 64 insertions(+), 52 deletions(-)

diff --git a/mysql-test/r/set_statement.result b/mysql-test/r/set_statement.result
index 51687ca..f1d8792 100644
--- a/mysql-test/r/set_statement.result
+++ b/mysql-test/r/set_statement.result
@@ -1040,10 +1040,6 @@ 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;
-ERROR 42000: The system variable rand_seed1 cannot be set in SET STATEMENT.
-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 last_insert_id=1 for select 1;
@@ -1138,3 +1134,13 @@ password(a)
 deallocate prepare stmt1;
 drop table t1;
 set @@old_passwords=@save_old_passwords;
+#
+# MDEV-6954: SET STATEMENT rand_seedX = ...FOR ... makes
+# the next rand() to return 0
+#
+set @rnd=1;
+# test that rand() is not always 0 after restoring rand_seed, rand_seed2...
+# @rnd should be 0
+select @rnd;
+ at rnd
+0
diff --git a/mysql-test/suite/sys_vars/inc/sysvars_server.inc b/mysql-test/suite/sys_vars/inc/sysvars_server.inc
index fb6121d..3a9a312 100644
--- a/mysql-test/suite/sys_vars/inc/sysvars_server.inc
+++ b/mysql-test/suite/sys_vars/inc/sysvars_server.inc
@@ -17,6 +17,7 @@ select * from information_schema.system_variables
   where variable_name not like 'aria%' and
         variable_name not like 'debug%' and
         variable_name not like 'wsrep%' and
+        variable_name not like 'rand_seed%%' and
         variable_name not in (
           'have_openssl',
           'have_symlink',
diff --git a/mysql-test/suite/sys_vars/r/rand_seed1_basic.result b/mysql-test/suite/sys_vars/r/rand_seed1_basic.result
index 155d716..c4244da 100644
--- a/mysql-test/suite/sys_vars/r/rand_seed1_basic.result
+++ b/mysql-test/suite/sys_vars/r/rand_seed1_basic.result
@@ -1,27 +1,30 @@
 select @@global.rand_seed1;
 ERROR HY000: Variable 'rand_seed1' is a SESSION variable
+set session rand_seed1=default;
+ERROR 42000: Variable 'rand_seed1' doesn't have a default value
+set session rand_seed1=10969771;
 select @@session.rand_seed1;
 @@session.rand_seed1
-0
+10969771
 show global variables like 'rand_seed1';
 Variable_name	Value
 show session variables like 'rand_seed1';
 Variable_name	Value
-rand_seed1	0
+rand_seed1	10969771
 select * from information_schema.global_variables where variable_name='rand_seed1';
 VARIABLE_NAME	VARIABLE_VALUE
 select * from information_schema.session_variables where variable_name='rand_seed1';
 VARIABLE_NAME	VARIABLE_VALUE
-RAND_SEED1	0
+RAND_SEED1	10969771
 set session rand_seed1=1;
 select @@session.rand_seed1;
 @@session.rand_seed1
-0
+1
 select * from information_schema.global_variables where variable_name='rand_seed1';
 VARIABLE_NAME	VARIABLE_VALUE
 select * from information_schema.session_variables where variable_name='rand_seed1';
 VARIABLE_NAME	VARIABLE_VALUE
-RAND_SEED1	0
+RAND_SEED1	1
 set global rand_seed1=1;
 ERROR HY000: Variable 'rand_seed1' is a SESSION variable and can't be used with SET GLOBAL
 set session rand_seed1=1.1;
diff --git a/mysql-test/suite/sys_vars/r/rand_seed2_basic.result b/mysql-test/suite/sys_vars/r/rand_seed2_basic.result
index 4974d8a..23e154d 100644
--- a/mysql-test/suite/sys_vars/r/rand_seed2_basic.result
+++ b/mysql-test/suite/sys_vars/r/rand_seed2_basic.result
@@ -1,27 +1,30 @@
 select @@global.rand_seed2;
 ERROR HY000: Variable 'rand_seed2' is a SESSION variable
+set session rand_seed2=default;
+ERROR 42000: Variable 'rand_seed2' doesn't have a default value
+set session rand_seed2=10969771;
 select @@session.rand_seed2;
 @@session.rand_seed2
-0
+10969771
 show global variables like 'rand_seed2';
 Variable_name	Value
 show session variables like 'rand_seed2';
 Variable_name	Value
-rand_seed2	0
+rand_seed2	10969771
 select * from information_schema.global_variables where variable_name='rand_seed2';
 VARIABLE_NAME	VARIABLE_VALUE
 select * from information_schema.session_variables where variable_name='rand_seed2';
 VARIABLE_NAME	VARIABLE_VALUE
-RAND_SEED2	0
+RAND_SEED2	10969771
 set session rand_seed2=1;
 select @@session.rand_seed2;
 @@session.rand_seed2
-0
+1
 select * from information_schema.global_variables where variable_name='rand_seed2';
 VARIABLE_NAME	VARIABLE_VALUE
 select * from information_schema.session_variables where variable_name='rand_seed2';
 VARIABLE_NAME	VARIABLE_VALUE
-RAND_SEED2	0
+RAND_SEED2	1
 set global rand_seed2=1;
 ERROR HY000: Variable 'rand_seed2' is a SESSION variable and can't be used with SET GLOBAL
 set session rand_seed2=1.1;
diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result
index 83c0196..156cec9 100644
--- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result
+++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result
@@ -7,6 +7,7 @@ select * from information_schema.system_variables
 where variable_name not like 'aria%' and
 variable_name not like 'debug%' and
 variable_name not like 'wsrep%' and
+variable_name not like 'rand_seed%%' and
 variable_name not in (
 'have_openssl',
 'have_symlink',
@@ -3255,34 +3256,6 @@ NUMERIC_BLOCK_SIZE	1024
 ENUM_VALUE_LIST	NULL
 READ_ONLY	NO
 COMMAND_LINE_ARGUMENT	REQUIRED
-VARIABLE_NAME	RAND_SEED1
-SESSION_VALUE	0
-GLOBAL_VALUE	NULL
-GLOBAL_VALUE_ORIGIN	COMPILE-TIME
-DEFAULT_VALUE	0
-VARIABLE_SCOPE	SESSION ONLY
-VARIABLE_TYPE	BIGINT UNSIGNED
-VARIABLE_COMMENT	Sets the internal state of the RAND() generator for replication purposes
-NUMERIC_MIN_VALUE	0
-NUMERIC_MAX_VALUE	18446744073709551615
-NUMERIC_BLOCK_SIZE	1
-ENUM_VALUE_LIST	NULL
-READ_ONLY	NO
-COMMAND_LINE_ARGUMENT	NULL
-VARIABLE_NAME	RAND_SEED2
-SESSION_VALUE	0
-GLOBAL_VALUE	NULL
-GLOBAL_VALUE_ORIGIN	COMPILE-TIME
-DEFAULT_VALUE	0
-VARIABLE_SCOPE	SESSION ONLY
-VARIABLE_TYPE	BIGINT UNSIGNED
-VARIABLE_COMMENT	Sets the internal state of the RAND() generator for replication purposes
-NUMERIC_MIN_VALUE	0
-NUMERIC_MAX_VALUE	18446744073709551615
-NUMERIC_BLOCK_SIZE	1
-ENUM_VALUE_LIST	NULL
-READ_ONLY	NO
-COMMAND_LINE_ARGUMENT	NULL
 VARIABLE_NAME	RANGE_ALLOC_BLOCK_SIZE
 SESSION_VALUE	4096
 GLOBAL_VALUE	4096
diff --git a/mysql-test/suite/sys_vars/t/rand_seed1_basic.test b/mysql-test/suite/sys_vars/t/rand_seed1_basic.test
index 3745d2f..a64f8a6 100644
--- a/mysql-test/suite/sys_vars/t/rand_seed1_basic.test
+++ b/mysql-test/suite/sys_vars/t/rand_seed1_basic.test
@@ -6,6 +6,9 @@
 #
 --error ER_INCORRECT_GLOBAL_LOCAL_VAR
 select @@global.rand_seed1;
+--error ER_NO_DEFAULT
+set session rand_seed1=default;
+set session rand_seed1=10969771;
 select @@session.rand_seed1;
 show global variables like 'rand_seed1';
 show session variables like 'rand_seed1';
diff --git a/mysql-test/suite/sys_vars/t/rand_seed2_basic.test b/mysql-test/suite/sys_vars/t/rand_seed2_basic.test
index 7a5abcd..091fd8f 100644
--- a/mysql-test/suite/sys_vars/t/rand_seed2_basic.test
+++ b/mysql-test/suite/sys_vars/t/rand_seed2_basic.test
@@ -7,6 +7,9 @@
 #
 --error ER_INCORRECT_GLOBAL_LOCAL_VAR
 select @@global.rand_seed2;
+--error ER_NO_DEFAULT
+set session rand_seed2=default;
+set session rand_seed2=10969771;
 select @@session.rand_seed2;
 show global variables like 'rand_seed2';
 show session variables like 'rand_seed2';
diff --git a/mysql-test/t/set_statement.test b/mysql-test/t/set_statement.test
index 6421317..38a93b9 100644
--- a/mysql-test/t/set_statement.test
+++ b/mysql-test/t/set_statement.test
@@ -997,10 +997,6 @@ 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;
---error ER_SET_STATEMENT_NOT_SUPPORTED
-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 last_insert_id=1 for select 1;
@@ -1068,3 +1064,23 @@ execute stmt1;
 deallocate prepare stmt1;
 drop table t1;
 set @@old_passwords=@save_old_passwords;
+
+--echo #
+--echo # MDEV-6954: SET STATEMENT rand_seedX = ...FOR ... makes
+--echo # the next rand() to return 0
+--echo #
+set @rnd=1;
+let $1=10;
+--disable_query_log
+--echo # test that rand() is not always 0 after restoring rand_seed, rand_seed2...
+while ($1)
+{
+  --disable_result_log
+  set statement rand_seed1=1, rand_seed2=1 for select 1;
+  --enable_result_log
+  set @rnd= rand()=0 and @rnd;
+  dec $1;
+}
+--enable_query_log
+--echo # @rnd should be 0
+select @rnd;
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 079861f..3816509 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -3824,17 +3824,17 @@ static bool update_rand_seed1(THD *thd, set_var *var)
   thd->rand.seed1= (ulong) var->save_result.ulonglong_value;
   return false;
 }
-static ulonglong read_rand_seed(THD *thd)
+static ulonglong read_rand_seed1(THD *thd)
 {
-  return 0;
+  return thd->rand.seed1;
 }
 static Sys_var_session_special Sys_rand_seed1(
        "rand_seed1", "Sets the internal state of the RAND() "
        "generator for replication purposes",
-       NO_SET_STMT sys_var::ONLY_SESSION, NO_CMD_LINE,
+       sys_var::ONLY_SESSION, NO_CMD_LINE,
        VALID_RANGE(0, ULONG_MAX), BLOCK_SIZE(1),
        NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
-       ON_UPDATE(update_rand_seed1), ON_READ(read_rand_seed));
+       ON_UPDATE(update_rand_seed1), ON_READ(read_rand_seed1));
 
 static bool update_rand_seed2(THD *thd, set_var *var)
 {
@@ -3846,13 +3846,17 @@ static bool update_rand_seed2(THD *thd, set_var *var)
   thd->rand.seed2= (ulong) var->save_result.ulonglong_value;
   return false;
 }
+static ulonglong read_rand_seed2(THD *thd)
+{
+  return thd->rand.seed2;
+}
 static Sys_var_session_special Sys_rand_seed2(
        "rand_seed2", "Sets the internal state of the RAND() "
        "generator for replication purposes",
-       NO_SET_STMT sys_var::ONLY_SESSION, NO_CMD_LINE,
+       sys_var::ONLY_SESSION, NO_CMD_LINE,
        VALID_RANGE(0, ULONG_MAX), BLOCK_SIZE(1),
        NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
-       ON_UPDATE(update_rand_seed2), ON_READ(read_rand_seed));
+       ON_UPDATE(update_rand_seed2), ON_READ(read_rand_seed2));
 
 static ulonglong read_error_count(THD *thd)
 {


More information about the commits mailing list