From 304f0084ef86b712358393b3b673e88612320957 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Feb 2019 12:34:26 -0500 Subject: [PATCH] MDEV-18720 Assertion `inited==NONE' failed in ha_index_init upon update on versioned table with key on blob * update system versioning fields before generaled columns * don't presume that ha_write_row() means INSERT. It could still be UPDATE * use the correct handler in check_duplicate_long_entry_key() --- mysql-test/main/long_unique_bugs.result | 16 ++++++++++++++++ mysql-test/main/long_unique_bugs.test | 12 ++++++++++++ sql/handler.cc | 11 +++++++---- sql/sql_base.cc | 4 ++-- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/mysql-test/main/long_unique_bugs.result b/mysql-test/main/long_unique_bugs.result index b7c6c3776b3..d81125eda91 100644 --- a/mysql-test/main/long_unique_bugs.result +++ b/mysql-test/main/long_unique_bugs.result @@ -33,3 +33,19 @@ Warnings: Warning 1265 Data truncated for column 't' at row 1 Warning 1265 Data truncated for column 't' at row 2 drop table t1; +create table t1 ( pk int, f text, primary key (pk), unique(f)) with system versioning; +insert into t1 values (1,'foo'); +update t1 set f = 'bar'; +select * from t1; +pk f +1 bar +update t1 set f = 'foo'; +select * from t1; +pk f +1 foo +select pk, f, row_end > DATE'2030-01-01' from t1 for system_time all; +pk f row_end > DATE'2030-01-01' +1 foo 1 +1 foo 0 +1 bar 0 +drop table t1; diff --git a/mysql-test/main/long_unique_bugs.test b/mysql-test/main/long_unique_bugs.test index 9992fe1fb98..6220a22e759 100644 --- a/mysql-test/main/long_unique_bugs.test +++ b/mysql-test/main/long_unique_bugs.test @@ -44,3 +44,15 @@ create table t1 (t time, unique(t)) engine=innodb; insert into t1 values (null),(null); alter ignore table t1 modify t text not null default ''; drop table t1; + +# +# MDEV-18720 Assertion `inited==NONE' failed in ha_index_init upon update on versioned table with key on blob +# +create table t1 ( pk int, f text, primary key (pk), unique(f)) with system versioning; +insert into t1 values (1,'foo'); +update t1 set f = 'bar'; +select * from t1; +update t1 set f = 'foo'; +select * from t1; +select pk, f, row_end > DATE'2030-01-01' from t1 for system_time all; +drop table t1; diff --git a/sql/handler.cc b/sql/handler.cc index 418d600cb1f..532ecc84621 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -6548,7 +6548,7 @@ static int check_duplicate_long_entry_key(TABLE *table, handler *h, } } } - while (!is_same && !(result= table->file->ha_index_next_same(table->check_unique_buf, + while (!is_same && !(result= h->ha_index_next_same(table->check_unique_buf, ptr, key_info->key_length))); if (is_same) error= HA_ERR_FOUND_DUPP_KEY; @@ -6651,9 +6651,12 @@ int handler::ha_write_row(uchar *buf) mark_trx_read_write(); increment_statistics(&SSV::ha_write_count); - if (table->s->long_unique_table && - (error= check_duplicate_long_entries(table, table->file, buf))) - DBUG_RETURN(error); + if (table->s->long_unique_table) + { + handler *h= table->update_handler ? table->update_handler : table->file; + if ((error= check_duplicate_long_entries(table, h, buf))) + DBUG_RETURN(error); + } TABLE_IO_WAIT(tracker, m_psi, PSI_TABLE_WRITE_ROW, MAX_KEY, 0, { error= write_row(buf); }) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 566c1970691..5de8bcc6df6 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -8698,11 +8698,11 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List &values, goto err; /* Update virtual fields */ thd->abort_on_warning= FALSE; + if (table->versioned()) + table->vers_update_fields(); if (table->vfield && table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE)) goto err; - if (table->versioned()) - table->vers_update_fields(); thd->abort_on_warning= abort_on_warning_saved; DBUG_RETURN(thd->is_error());