@@ -9,16 +9,14 @@ insert into gh_ost_test (email) values ('alice@example.com');
99insert into gh_ost_test (email) values (' bob@example.com' );
1010insert into gh_ost_test (email) values (' charlie@example.com' );
1111
12- -- Add many rows to extend row copy duration significantly
13- -- Need enough rows that copying takes multiple seconds to give event time to detect
14- -- With chunk-size=10, 1000 rows = 100 chunks which should take several seconds
12+ -- Add enough rows to give a window for the event to fire
13+ -- With chunk-size=10, 100 rows = 10 chunks
1514insert into gh_ost_test (email)
1615select concat(' user' , @row := @row + 1 , ' @example.com' )
1716from (select @row := 3 ) init,
1817 (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9 ) t1,
19- (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9 ) t2,
20- (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9 ) t3
21- limit 1000 ;
18+ (select 0 union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9 ) t2
19+ limit 100 ;
2220
2321drop event if exists gh_ost_test;
2422delimiter ;;
@@ -30,12 +28,15 @@ create event gh_ost_test
3028 enable
3129 do
3230begin
33- -- Poll for row copy to start by checking if alice has been copied to ghost table
34- -- Once row copy has started, fire the UPDATE that creates a duplicate
35- if exists (select 1 from test ._gh_ost_test_gho where email = ' alice@example.com' ) then
31+ -- Poll for row copy to complete by checking if last row has been copied
32+ -- Once row copy is done but before cutover, fire the UPDATE that creates a duplicate
33+ -- Check a flag table to ensure we only fire once
34+ if exists (select 1 from test ._gh_ost_test_gho where id >= 100 )
35+ and not exists (select 1 from information_schema .tables where table_schema= ' test' and table_name= ' _gh_ost_fired' ) then
36+ create table test ._gh_ost_fired (id int );
3637 -- This UPDATE modifies the primary key, so it will be converted to DELETE + INSERT
3738 -- The INSERT will attempt to insert email='alice@example.com' (duplicate)
3839 -- which violates the new unique index being added by the migration
39- update gh_ost_test set id= 10 , email= ' alice@example.com' where id= 2 ;
40+ update gh_ost_test set id= 200 , email= ' alice@example.com' where id= 2 ;
4041 end if;
4142end ;;
0 commit comments