1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-25644 UPDATE not working properly on transaction precise system versioned table

First UPDATE under START TRANSACTION does nothing (nstate= nstate),
but anyway generates history. Since update vector is empty we get into
(!uvect->n_fields) branch which only adds history row, but does not do
update. After that we get current row with wrong (old) row_start value
and because of that second UPDATE tries to insert history row again
because it sees trx->id != row_start which is the guard to avoid
inserting multiple trx_id-based history rows under same transaction
(because we have same trx_id and we get duplicate error and this bug
demostrates that). But this try anyway fails because PK is based on
row_end which is constant under same transaction, so PK didn't change.

The fix moves vers_make_update() to an earlier stage of
calc_row_difference(). Therefore it prepares update vector before
(!uvect->n_fields) check and never gets into that branch, hence no
need to handle versioning inside that condition anymore.

Now trx->id and row_start are equal after first UPDATE and we don't
try to insert second history row.

== Cleanups and improvements ==

ha_innobase::update_row():

vers_set_fields and vers_ins_row are cleaned up into direct condition
check. SQLCOM_ALTER_TABLE check now is not used as this is dead code,
assertion is done instead.

upd_node->is_delete is set in calc_row_difference() just to keep
versioning code as much in one place as possible. vers_make_delete()
is still located in row_update_for_mysql() as this is required for
ha_innodbase::delete_row() as well.

row_ins_duplicate_error_in_clust():

Restrict DB_FOREIGN_DUPLICATE_KEY to the better conditions.
VERSIONED_DELETE is used specifically to help lower stack to
understand what caused current insert. Related to MDEV-29813.
This commit is contained in:
Aleksey Midenkov
2023-07-20 14:14:00 +03:00
parent 21a8d2c313
commit 14cc7e7d6e
10 changed files with 160 additions and 60 deletions

View File

@ -133,18 +133,38 @@ drop table t1;
#
# MDEV-21138 Assertion `col->ord_part' or `f.col->ord_part' failed in row_build_index_entry_low
#
# Check DELETE and multi-DELETE with foreign key
create table t1 (
f1 int, f2 text, f3 int, fulltext (f2), key(f1), key(f3),
foreign key r (f3) references t1 (f1) on delete set null)
foreign key r (f3) references t1 (f1) on delete set null,
row_start SYS_TYPE as row start invisible,
row_end SYS_TYPE as row end invisible,
period for system_time (row_start, row_end))
with system versioning engine innodb;
insert into t1 values (1, repeat('a', 8193), 1), (1, repeat('b', 8193), 1);
select f1, f3, check_row_ts(row_start, row_end) from t1;
f1 f3 check_row_ts(row_start, row_end)
insert into t1 select 2, f2, 2 from t1;
select f1, f3, check_row(row_start, row_end) from t1;
f1 f3 check_row(row_start, row_end)
1 1 CURRENT ROW
1 1 CURRENT ROW
delete from t1;
select f1, f3, check_row_ts(row_start, row_end) from t1 for system_time all;
f1 f3 check_row_ts(row_start, row_end)
2 2 CURRENT ROW
2 2 CURRENT ROW
delete from t1 where f1 = 1;
select f1, f3, check_row(row_start, row_end) from t1 for system_time all order by f1, row_end;
f1 f3 check_row(row_start, row_end)
1 1 HISTORICAL ROW
1 1 HISTORICAL ROW
drop table t1;
2 2 CURRENT ROW
2 2 CURRENT ROW
create table t2 (f1 int);
insert into t2 values (2);
# Multi-delelte
delete t1, t2 from t1 join t2 where t1.f1 = t2.f1;
select f1, f3, check_row(row_start, row_end) from t1 for system_time all order by f1, row_end;
f1 f3 check_row(row_start, row_end)
1 1 HISTORICAL ROW
1 1 HISTORICAL ROW
2 2 HISTORICAL ROW
2 2 HISTORICAL ROW
# Cleanup
drop tables t1, t2;