diff options
author | unknown <cbell/Chuck@mysql_cab_desk.> | 2007-03-09 12:18:28 -0500 |
---|---|---|
committer | unknown <cbell/Chuck@mysql_cab_desk.> | 2007-03-09 12:18:28 -0500 |
commit | bcba75df423314a49da7436281eba1403e020897 (patch) | |
tree | 078a7ee2677d3da06dbf0913509c368f9b8524fd /sql/sql_class.cc | |
parent | 1636d00fa7fd6ff2b8d5a0117efc44d7997860fb (diff) | |
download | mariadb-git-bcba75df423314a49da7436281eba1403e020897.tar.gz |
Bug #25543 Replication of wrong values if using rand() in stored procedure
When rand() is called multiple times inside a stored procedure, the server does
not binlog the correct random seed values.
This patch corrects the problem by resetting rand_used= 0 in
THD::cleanup_after_query() allowing the system to save the random seeds if needed
for each command in a stored procedure body.
However, rand_used is not reset if executing in a stored function or trigger
because these operations are binlogged by call and thus only the calling statement
need detect the call to rand() made by its substatements. These substatements must
not set rand_used to 0 because it would remove the detection of rand() by the
calling statement.
mysql-test/r/rpl_misc_functions.result:
Bug #25543 Replication of wrong values if using rand() in stored procedure
The result file was modified to include the correct processing of the new
additions to the test. The results from execution are written to files on
both the master and the slave. The files are compared to ensure the values
from rand() generated on the master are correctly generated on the slave.
mysql-test/t/rpl_misc_functions.test:
Bug #25543 Replication of wrong values if using rand() in stored procedure
The test was modified to include a test of a stored procedure that calls
the rand() function multiple times.
The results from execution are written to files on both the master and the
slave. The files are compared to ensure the values from rand() generated
on the master are correctly generated on the slave.
sql/sql_class.cc:
Bug #25543 Replication of wrong values if using rand() in stored procedure
The code was modified to reset rand_used so that detection of calls to rand()
will save random seeds if needed by the slave.
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r-- | sql/sql_class.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 3c91e3e8fb7..adb7323c463 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -575,6 +575,18 @@ void THD::cleanup_after_query() clear_next_insert_id= 0; next_insert_id= 0; } + /* + Reset rand_used so that detection of calls to rand() will save random + seeds if needed by the slave. + + Do not reset rand_used if inside a stored function or trigger because + only the call to these operations is logged. Thus only the calling + statement needs to detect rand() calls made by its substatements. These + substatements must not set rand_used to 0 because it would remove the + detection of rand() by the calling statement. + */ + if (!in_sub_stmt) + rand_used= 0; /* Free Items that were created during this execution */ free_items(); /* Reset where. */ |