Skip to content

Commit 706a8bc

Browse files
committed
MDEV-33470 Unique hash index is broken on DML for system-versioned table
Hash index is vcol-based wrapper (MDEV-371). row_end is added to unique index. So when row_end is updated unique hash index must be recalculated via vcol_update_fields(). DELETE did not update virtual fields, so DELETE HISTORY was getting wrong hash value. The fix does update_virtual_fields() on vers_update_end() so in every case row_end is updated virtual fields are updated as well.
1 parent d37bb14 commit 706a8bc

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

mysql-test/suite/versioning/r/delete_history.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,14 @@ ERROR HY000: The target table v1 of the DELETE is not updatable
224224
DROP VIEW v1;
225225
DROP TABLE t1;
226226
# End of 10.4 tests
227+
#
228+
# MDEV-33470 Unique hash index is broken on DML for system-versioned table
229+
#
230+
create or replace table t (
231+
c int, unique (c) using hash)
232+
with system versioning;
233+
insert into t values (0);
234+
delete from t;
235+
delete history from t;
236+
drop table t;
237+
# End of 10.5 tests

mysql-test/suite/versioning/t/delete_history.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,17 @@ DROP TABLE t1;
232232

233233
--echo # End of 10.4 tests
234234

235+
--echo #
236+
--echo # MDEV-33470 Unique hash index is broken on DML for system-versioned table
237+
--echo #
238+
create or replace table t (
239+
c int, unique (c) using hash)
240+
with system versioning;
241+
insert into t values (0);
242+
delete from t;
243+
delete history from t;
244+
drop table t;
245+
246+
--echo # End of 10.5 tests
247+
235248
--source suite/versioning/common_finish.inc

sql/sql_insert.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,10 +1810,6 @@ int vers_insert_history_row(TABLE *table)
18101810
if (row_start->cmp(row_start->ptr, row_end->ptr) >= 0)
18111811
return 0;
18121812

1813-
if (table->vfield &&
1814-
table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_READ))
1815-
return HA_ERR_GENERIC;
1816-
18171813
return table->file->ha_write_row(table->record[0]);
18181814
}
18191815

sql/table.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9078,6 +9078,8 @@ void TABLE::vers_update_end()
90789078
in_use->query_start_sec_part()))
90799079
DBUG_ASSERT(0);
90809080
vers_end_field()->set_has_explicit_value();
9081+
if (vfield)
9082+
update_virtual_fields(file, VCOL_UPDATE_FOR_WRITE);
90819083
}
90829084

90839085
/**

0 commit comments

Comments
 (0)