mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
f3985c649d
General overview: The logic for switching to row format when binlog_format=MIXED had numerous flaws. The underlying problem was the lack of a consistent architecture. General purpose of this changeset: This changeset introduces an architecture for switching to row format when binlog_format=MIXED. It enforces the architecture where it has to. It leaves some bugs to be fixed later. It adds extensive tests to verify that unsafe statements work as expected and that appropriate errors are produced by problems with the selection of binlog format. It was not practical to split this into smaller pieces of work. Problem 1: To determine the logging mode, the code has to take several parameters into account (namely: (1) the value of binlog_format; (2) the capabilities of the engines; (3) the type of the current statement: normal, unsafe, or row injection). These parameters may conflict in several ways, namely: - binlog_format=STATEMENT for a row injection - binlog_format=STATEMENT for an unsafe statement - binlog_format=STATEMENT for an engine only supporting row logging - binlog_format=ROW for an engine only supporting statement logging - statement is unsafe and engine does not support row logging - row injection in a table that does not support statement logging - statement modifies one table that does not support row logging and one that does not support statement logging Several of these conflicts were not detected, or were detected with an inappropriate error message. The problem of BUG#39934 was that no appropriate error message was written for the case when an engine only supporting row logging executed a row injection with binlog_format=ROW. However, all above cases must be handled. Fix 1: Introduce new error codes (sql/share/errmsg.txt). Ensure that all conditions are detected and handled in decide_logging_format() Problem 2: The binlog format shall be determined once per statement, in decide_logging_format(). It shall not be changed before or after that. Before decide_logging_format() is called, all information necessary to determine the logging format must be available. This principle ensures that all unsafe statements are handled in a consistent way. However, this principle is not followed: thd->set_current_stmt_binlog_row_based_if_mixed() is called in several places, including from code executing UPDATE..LIMIT, INSERT..SELECT..LIMIT, DELETE..LIMIT, INSERT DELAYED, and SET @@binlog_format. After Problem 1 was fixed, that caused inconsistencies where these unsafe statements would not print the appropriate warnings or errors for some of the conflicts. Fix 2: Remove calls to THD::set_current_stmt_binlog_row_based_if_mixed() from code executed after decide_logging_format(). Compensate by calling the set_current_stmt_unsafe() at parse time. This way, all unsafe statements are detected by decide_logging_format(). Problem 3: INSERT DELAYED is not unsafe: it is logged in statement format even if binlog_format=MIXED, and no warning is printed even if binlog_format=STATEMENT. This is BUG#45825. Fix 3: Made INSERT DELAYED set itself to unsafe at parse time. This allows decide_logging_format() to detect that a warning should be printed or the binlog_format changed. Problem 4: LIMIT clause were not marked as unsafe when executed inside stored functions/triggers/views/prepared statements. This is BUG#45785. Fix 4: Make statements containing the LIMIT clause marked as unsafe at parse time, instead of at execution time. This allows propagating unsafe-ness to the view.
191 lines
5.7 KiB
SQL
191 lines
5.7 KiB
SQL
#####################################################################
|
|
# Author: Chuck Bell #
|
|
# Date: 2006-12-21 #
|
|
# Purpose: To test that UDFs are replicated in both row based and #
|
|
# statement based format. This tests work completed in WL#3629. #
|
|
# #
|
|
# This test is designed to exercise two of the three types of UDFs: #
|
|
# 1) UDFs via loadable libraries, and 2) UDFs with a SQL body. #
|
|
#####################################################################
|
|
|
|
--source include/have_udf.inc
|
|
|
|
#
|
|
# To run this tests the "sql/udf_example.c" need to be compiled into
|
|
# udf_example.so and LD_LIBRARY_PATH should be setup to point out where
|
|
# the library are.
|
|
#
|
|
|
|
connection master;
|
|
--disable_warnings
|
|
drop table if exists t1;
|
|
--enable_warnings
|
|
|
|
#
|
|
# Test 1) Test UDFs via loadable libraries
|
|
#
|
|
--echo "*** Test 1) Test UDFs via loadable libraries ***
|
|
--echo "Running on the master"
|
|
--enable_info
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
eval CREATE FUNCTION myfunc_double RETURNS REAL SONAME "$UDF_EXAMPLE_LIB";
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
|
|
--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
|
|
--error ER_CANT_FIND_DL_ENTRY
|
|
eval CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
|
|
--replace_column 3 UDF_LIB
|
|
SELECT * FROM mysql.func ORDER BY name;
|
|
--disable_info
|
|
|
|
save_master_pos;
|
|
connection slave;
|
|
sync_with_master;
|
|
|
|
# Check to see that UDF CREATE statements were replicated
|
|
--echo "Running on the slave"
|
|
--enable_info
|
|
--replace_column 3 UDF_LIB
|
|
SELECT * FROM mysql.func ORDER BY name;
|
|
--disable_info
|
|
|
|
connection master;
|
|
|
|
# Use the UDFs to do something
|
|
--echo "Running on the master"
|
|
--enable_info
|
|
eval CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=$engine_type;
|
|
--disable_warnings
|
|
INSERT INTO t1 VALUES(myfunc_int(100), myfunc_double(50.00));
|
|
INSERT INTO t1 VALUES(myfunc_int(10), myfunc_double(5.00));
|
|
INSERT INTO t1 VALUES(myfunc_int(200), myfunc_double(25.00));
|
|
INSERT INTO t1 VALUES(myfunc_int(1), myfunc_double(500.00));
|
|
SELECT * FROM t1 ORDER BY sum;
|
|
--enable_warnings
|
|
--disable_info
|
|
|
|
sync_slave_with_master;
|
|
|
|
# Check to see if data was replicated
|
|
--echo "Running on the slave"
|
|
--enable_info
|
|
SELECT * FROM t1 ORDER BY sum;
|
|
|
|
# Check to see that the functions are available for execution on the slave
|
|
SELECT myfunc_int(25);
|
|
SELECT myfunc_double(75.00);
|
|
--disable_info
|
|
|
|
connection master;
|
|
|
|
# Drop the functions
|
|
--echo "Running on the master"
|
|
--enable_info
|
|
DROP FUNCTION myfunc_double;
|
|
DROP FUNCTION myfunc_int;
|
|
SELECT * FROM mysql.func ORDER BY name;
|
|
--disable_info
|
|
|
|
sync_slave_with_master;
|
|
|
|
# Check to see if the UDFs were dropped on the slave
|
|
--echo "Running on the slave"
|
|
--enable_info
|
|
SELECT * FROM mysql.func ORDER BY name;
|
|
--disable_info
|
|
|
|
connection master;
|
|
|
|
# Cleanup
|
|
--echo "Running on the master"
|
|
--enable_info
|
|
DROP TABLE t1;
|
|
--disable_info
|
|
|
|
#
|
|
# Test 2) Test UDFs with SQL body
|
|
#
|
|
--echo "*** Test 2) Test UDFs with SQL body ***
|
|
--echo "Running on the master"
|
|
--enable_info
|
|
CREATE FUNCTION myfuncsql_int(i INT) RETURNS INTEGER DETERMINISTIC RETURN i;
|
|
CREATE FUNCTION myfuncsql_double(d DOUBLE) RETURNS INTEGER DETERMINISTIC RETURN d * 2.00;
|
|
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
|
|
--disable_info
|
|
|
|
sync_slave_with_master;
|
|
|
|
# Check to see that UDF CREATE statements were replicated
|
|
--echo "Running on the slave"
|
|
--enable_info
|
|
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
|
|
--disable_info
|
|
|
|
connection master;
|
|
|
|
# Use the UDFs to do something
|
|
--echo "Running on the master"
|
|
--enable_info
|
|
eval CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=$engine_type;
|
|
INSERT INTO t1 VALUES(myfuncsql_int(100), myfuncsql_double(50.00));
|
|
INSERT INTO t1 VALUES(myfuncsql_int(10), myfuncsql_double(5.00));
|
|
INSERT INTO t1 VALUES(myfuncsql_int(200), myfuncsql_double(25.00));
|
|
INSERT INTO t1 VALUES(myfuncsql_int(1), myfuncsql_double(500.00));
|
|
SELECT * FROM t1 ORDER BY sum;
|
|
--disable_info
|
|
|
|
sync_slave_with_master;
|
|
|
|
# Check to see if data was replicated
|
|
--echo "Running on the slave"
|
|
--enable_info
|
|
SELECT * FROM t1 ORDER BY sum;
|
|
--disable_info
|
|
|
|
connection master;
|
|
|
|
# Modify the UDFs to add a comment
|
|
--echo "Running on the master"
|
|
--enable_info
|
|
ALTER FUNCTION myfuncsql_int COMMENT "This was altered.";
|
|
ALTER FUNCTION myfuncsql_double COMMENT "This was altered.";
|
|
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
|
|
--disable_info
|
|
|
|
sync_slave_with_master;
|
|
|
|
# Check to see if data was replicated
|
|
--echo "Running on the slave"
|
|
--enable_info
|
|
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
|
|
|
|
# Check to see that the functions are available for execution on the slave
|
|
SELECT myfuncsql_int(25);
|
|
SELECT myfuncsql_double(75.00);
|
|
--disable_info
|
|
|
|
connection master;
|
|
|
|
# Drop the functions
|
|
--echo "Running on the master"
|
|
--enable_info
|
|
DROP FUNCTION myfuncsql_double;
|
|
DROP FUNCTION myfuncsql_int;
|
|
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
|
|
--disable_info
|
|
|
|
sync_slave_with_master;
|
|
|
|
# Check to see if the UDFs were dropped on the slave
|
|
--echo "Running on the slave"
|
|
--enable_info
|
|
SELECT db, name, type, param_list, body, comment FROM mysql.proc WHERE db = 'test' AND name LIKE 'myfuncsql%' ORDER BY name;
|
|
--disable_info
|
|
|
|
connection master;
|
|
|
|
# Cleanup
|
|
--echo "Running on the master"
|
|
--enable_info
|
|
DROP TABLE t1;
|
|
--disable_info
|