Commit 304f0084 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-18720 Assertion `inited==NONE' failed in ha_index_init upon update on...

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()
parent f78c0f6f
...@@ -33,3 +33,19 @@ Warnings: ...@@ -33,3 +33,19 @@ Warnings:
Warning 1265 Data truncated for column 't' at row 1 Warning 1265 Data truncated for column 't' at row 1
Warning 1265 Data truncated for column 't' at row 2 Warning 1265 Data truncated for column 't' at row 2
drop table t1; 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;
...@@ -44,3 +44,15 @@ create table t1 (t time, unique(t)) engine=innodb; ...@@ -44,3 +44,15 @@ create table t1 (t time, unique(t)) engine=innodb;
insert into t1 values (null),(null); insert into t1 values (null),(null);
alter ignore table t1 modify t text not null default ''; alter ignore table t1 modify t text not null default '';
drop table t1; 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;
...@@ -6548,7 +6548,7 @@ static int check_duplicate_long_entry_key(TABLE *table, handler *h, ...@@ -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))); ptr, key_info->key_length)));
if (is_same) if (is_same)
error= HA_ERR_FOUND_DUPP_KEY; error= HA_ERR_FOUND_DUPP_KEY;
...@@ -6651,9 +6651,12 @@ int handler::ha_write_row(uchar *buf) ...@@ -6651,9 +6651,12 @@ int handler::ha_write_row(uchar *buf)
mark_trx_read_write(); mark_trx_read_write();
increment_statistics(&SSV::ha_write_count); increment_statistics(&SSV::ha_write_count);
if (table->s->long_unique_table && if (table->s->long_unique_table)
(error= check_duplicate_long_entries(table, table->file, buf))) {
DBUG_RETURN(error); 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, TABLE_IO_WAIT(tracker, m_psi, PSI_TABLE_WRITE_ROW, MAX_KEY, 0,
{ error= write_row(buf); }) { error= write_row(buf); })
......
...@@ -8698,11 +8698,11 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values, ...@@ -8698,11 +8698,11 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
goto err; goto err;
/* Update virtual fields */ /* Update virtual fields */
thd->abort_on_warning= FALSE; thd->abort_on_warning= FALSE;
if (table->versioned())
table->vers_update_fields();
if (table->vfield && if (table->vfield &&
table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE)) table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE))
goto err; goto err;
if (table->versioned())
table->vers_update_fields();
thd->abort_on_warning= abort_on_warning_saved; thd->abort_on_warning= abort_on_warning_saved;
DBUG_RETURN(thd->is_error()); DBUG_RETURN(thd->is_error());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment