mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
MDEV-21555 Assertion secondary index is out of sync on delete from versioned table
Delete-marked record is on the secondary index and the clustered index already purged the corresponding record. We cannot detect if such record is historical and we should not: the algorithm of row_ins_check_foreign_constraint() skips such record anyway.
This commit is contained in:
@ -443,3 +443,16 @@ pk f1 f2 left(f3, 4) check_row_ts(row_start, row_end)
|
||||
1 8 8 SHOR HISTORICAL ROW
|
||||
2 8 8 LONG HISTORICAL ROW
|
||||
drop table t1;
|
||||
#
|
||||
# MDEV-21555 Assertion secondary index is out of sync on delete from versioned table
|
||||
#
|
||||
create table t1 (a int, b int as (a + 1) virtual, key(a)) engine=innodb with system versioning;
|
||||
set foreign_key_checks= off;
|
||||
insert into t1 (a) values (1), (2);
|
||||
alter table t1 add foreign key (b) references t1 (a), algorithm=copy;
|
||||
update t1 set a= null where a = 1;
|
||||
delete from t1 where a is null;
|
||||
set foreign_key_checks= on;
|
||||
delete history from t1;
|
||||
delete from t1;
|
||||
drop table t1;
|
||||
|
@ -476,4 +476,22 @@ select pk, f1, f2, left(f3, 4), check_row_ts(row_start, row_end) from t1 for sys
|
||||
# cleanup
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-21555 Assertion secondary index is out of sync on delete from versioned table
|
||||
--echo #
|
||||
create table t1 (a int, b int as (a + 1) virtual, key(a)) engine=innodb with system versioning;
|
||||
|
||||
set foreign_key_checks= off;
|
||||
insert into t1 (a) values (1), (2);
|
||||
alter table t1 add foreign key (b) references t1 (a), algorithm=copy;
|
||||
update t1 set a= null where a = 1;
|
||||
delete from t1 where a is null;
|
||||
set foreign_key_checks= on;
|
||||
|
||||
delete history from t1;
|
||||
delete from t1;
|
||||
|
||||
# cleanup
|
||||
drop table t1;
|
||||
|
||||
--source suite/versioning/common_finish.inc
|
||||
|
@ -1666,23 +1666,6 @@ row_ins_check_foreign_constraint(
|
||||
cmp = cmp_dtuple_rec(entry, rec, offsets);
|
||||
|
||||
if (cmp == 0) {
|
||||
if (check_table->versioned()) {
|
||||
bool history_row = false;
|
||||
|
||||
if (check_index->is_primary()) {
|
||||
history_row = check_index->
|
||||
vers_history_row(rec, offsets);
|
||||
} else if (check_index->
|
||||
vers_history_row(rec, history_row))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (history_row) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (rec_get_deleted_flag(rec,
|
||||
rec_offs_comp(offsets))) {
|
||||
/* In delete-marked records, DB_TRX_ID must
|
||||
@ -1704,6 +1687,23 @@ row_ins_check_foreign_constraint(
|
||||
goto end_scan;
|
||||
}
|
||||
} else {
|
||||
if (check_table->versioned()) {
|
||||
bool history_row = false;
|
||||
|
||||
if (check_index->is_primary()) {
|
||||
history_row = check_index->
|
||||
vers_history_row(rec,
|
||||
offsets);
|
||||
} else if (check_index->
|
||||
vers_history_row(rec,
|
||||
history_row)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (history_row) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* Found a matching record. Lock only
|
||||
a record because we can allow inserts
|
||||
into gaps */
|
||||
|
Reference in New Issue
Block a user