Skip to content

Commit 679115a

Browse files
committed
Revise test
1 parent 6c124f4 commit 679115a

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

localtests/panic-on-warnings-update-pk-with-duplicate-on-new-unique-index/create.sql

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ insert into gh_ost_test (email) values ('alice@example.com');
99
insert into gh_ost_test (email) values ('bob@example.com');
1010
insert 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
1514
insert into gh_ost_test (email)
1615
select concat('user', @row := @row + 1, '@example.com')
1716
from (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

2321
drop event if exists gh_ost_test;
2422
delimiter ;;
@@ -30,12 +28,15 @@ create event gh_ost_test
3028
enable
3129
do
3230
begin
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;
4142
end ;;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
drop table if exists _gh_ost_fired;

0 commit comments

Comments
 (0)