--source suite/xengine/include/have_xengine.inc --source include/master-slave.inc --source include/have_debug.inc connection master; SET @prior_xengine_perf_context_level = @@xengine_perf_context_level; SET GLOBAL xengine_perf_context_level=3; SET GLOBAL enable_blind_replace=ON; # Create and insert some rows in a table create table t1(c1 int,c2 int, primary key (c1)) engine=xengine; insert into t1 values(1,1),(2,2),(3,3); select * from t1; # Create table which has a trigger only in slave create table t2(c1 int,c2 int, primary key (c1)) engine=xengine; insert into t2 values(1,1),(2,2),(3,3); select * from t2; # Create table which has a secondary key only in slave create table t3(c1 int,c2 int, primary key (c1)) engine=xengine; insert into t3 values(1,1),(2,2),(3,3); select * from t3; sync_slave_with_master; # Enable blind replace in both slave and master connection slave; SET GLOBAL enable_blind_replace=ON; create trigger trg before insert on t2 for each row set @a:=1; alter table t3 add constraint slave_unique_key unique (c2); connection master; sync_slave_with_master; --echo connect slave select variable_value into @d from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; # Case 1 - 'replace into' on a table with no triggers or secondary keys. Blind replace optimization should kick in both in master and slave --echo Case 1 connection master; --echo connect master select variable_value into @d from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; replace into t1 values(1,11); replace into t1 values(2,22); replace into t1 values(3,33); select case when variable_value-@d > 3 then 'false' else 'true' end as read_free from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; select * from t1; sync_slave_with_master; --echo connect slave select case when variable_value-@d > 3 then 'false' else 'true' end as read_free from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; select * from t1; select variable_value into @d from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; # Case 2 - Multiple replaces in a single statement. blind replace optimization should kick in connection master; --echo Case 2 --echo connect master select variable_value into @d from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; replace into t1 values(2,44),(3,55); select case when variable_value-@d > 2 then 'false' else 'true' end as read_free from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; select * from t1; sync_slave_with_master; --echo connect slave select case when variable_value-@d > 2 then 'false' else 'true' end as read_free from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; select * from t1; select variable_value into @d from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; # Case 3 - A regular update. This is not a blind replace --echo Case 3 connection master; --echo connect master update t1 set c2=66 where c1=3; select * from t1; sync_slave_with_master; --echo connect slave select * from t1; select variable_value into @d from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; # Case 4 - Slave has trigger on its table. No triggers on the table in master. # Blind replace optimization should kick in on master. # Slave should convert this statement into a regular update --echo Case 4 connection master; --echo connect master select variable_value into @d from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; replace into t2 values(1,111); replace into t2 values(2,222); replace into t2 values(3,333); select case when variable_value-@d > 3 then 'false' else 'true' end as read_free from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; select * from t2; sync_slave_with_master; --echo connect slave select case when variable_value-@d > 3 then 'false' else 'true' end as read_free from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; select * from t2; select variable_value into @d from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; # Case 5 - Slave has secondary keys on the table. No secondary keys on the table in master # Blind replace optimization should kick in on master. # Slave should convert this statement into a regular delete_insert --echo Case 5 connection master; --echo connect master select variable_value into @d from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; replace into t3 values(1,1111); replace into t3 values(2,2222); replace into t3 values(3,3333); select * from t3; select case when variable_value-@d > 3 then 'false' else 'true' end as read_free from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; sync_slave_with_master; --echo connect slave select case when variable_value-@d > 3 then 'false' else 'true' end as read_free from information_schema.global_status where variable_name='xengine_num_get_for_update_calls'; select * from t3; select * from t3 use index (slave_unique_key); # Case 6 - Just to verify all binlog events. # blind replace will generate a write_rows event. # Or else, it will be a update_rows event or a delete_rows_write_rows event --echo Case 6 connection master; --source include/show_binlog_events.inc connection slave; --source include/show_binlog_events.inc # Cleanup connection master; drop table t1; drop table t2; drop table t3; SET GLOBAL xengine_perf_context_level = @prior_xengine_perf_context_level; SET GLOBAL enable_blind_replace=DEFAULT; connection slave; SET GLOBAL enable_blind_replace=DEFAULT; --source include/rpl_end.inc