File tree Expand file tree Collapse file tree 3 files changed +54
-4
lines changed
mysql-test/suite/versioning Expand file tree Collapse file tree 3 files changed +54
-4
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,30 @@ insert into t2 (a) values (now()),(now());
5757select * from t2 where a in (select row_start from t1);
5858a
5959drop table t1, t2;
60+ # MDEV-30046 wrong row targeted with "insert ... on duplicate" and "replace"
61+ # Don't allow changes from the past
62+ create or replace table t1 (pk int primary key, i int) with system versioning;
63+ show create table t1;
64+ Table Create Table
65+ t1 CREATE TABLE `t1` (
66+ `pk` int(11) NOT NULL,
67+ `i` int(11) DEFAULT NULL,
68+ PRIMARY KEY (`pk`)
69+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci WITH SYSTEM VERSIONING
70+ set timestamp=12345;
71+ insert t1(pk, i) values(1,3);
72+ set timestamp=12344;
73+ delete from t1;
74+ select pk,i from t1 for system_time all;
75+ pk i
76+ set timestamp=12345;
77+ insert t1(pk, i) values(1,3);
78+ set timestamp=12344;
79+ replace t1(pk, i) values(1,4);
80+ select pk,i from t1 for system_time all;
81+ pk i
82+ 1 4
83+ drop table t1;
6084#
6185# End of 10.11 tests
6286#
Original file line number Diff line number Diff line change @@ -51,6 +51,25 @@ insert into t2 (a) values (now()),(now());
5151select * from t2 where a in (select row_start from t1);
5252drop table t1, t2;
5353
54+ --echo # MDEV-30046 wrong row targeted with "insert ... on duplicate" and "replace"
55+ --echo # Don't allow changes from the past
56+ create or replace table t1 (pk int primary key, i int) with system versioning;
57+ show create table t1;
58+ set timestamp=12345;
59+ insert t1(pk, i) values(1,3);
60+ set timestamp=12344;
61+ delete from t1;
62+
63+ select pk,i from t1 for system_time all;
64+
65+ set timestamp=12345;
66+ insert t1(pk, i) values(1,3);
67+ set timestamp=12344;
68+ replace t1(pk, i) values(1,4);
69+
70+ select pk,i from t1 for system_time all;
71+ drop table t1;
72+
5473--echo #
5574--echo # End of 10.11 tests
5675--echo #
Original file line number Diff line number Diff line change @@ -333,7 +333,14 @@ int TABLE::delete_row(bool treat_versioned)
333333 store_record (this , record[1 ]);
334334 }
335335 vers_update_end ();
336- err= file->ha_update_row (record[1 ], record[0 ]);
336+
337+ Field *row_start= vers_start_field ();
338+ Field *row_end= vers_end_field ();
339+ // Don't make history row with negative lifetime
340+ delete_row= row_start->cmp (row_start->ptr , row_end->ptr ) > 0 ;
341+
342+ if (likely (!delete_row))
343+ err= file->ha_update_row (record[1 ], record[0 ]);
337344 if (unlikely (err))
338345 {
339346 /*
@@ -350,11 +357,11 @@ int TABLE::delete_row(bool treat_versioned)
350357 || err == HA_ERR_FOREIGN_DUPLICATE_KEY;
351358 if (!delete_row)
352359 return err;
353-
354- if (!replace)
355- del_buf= record[1 ];
356360 }
357361
362+ if (delete_row)
363+ del_buf= record[1 ];
364+
358365 if (replace)
359366 restore_record (this , record[2 ]);
360367 }
You can’t perform that action at this time.
0 commit comments