Commit 0c99e6e9 authored by Aleksey Midenkov's avatar Aleksey Midenkov

MDEV-22562 Assertion `next_insert_id == 0' upon UPDATE on system-versioned table

Don't update autoinc counter on history row insert. Uniqueness is kept
due to merge with row_end.
parent af52a0e5
...@@ -63,3 +63,13 @@ A x y x y ...@@ -63,3 +63,13 @@ A x y x y
1 7 17 7 17 1 7 17 7 17
drop table t1; drop table t1;
drop table t2; drop table t2;
#
# MDEV-22562 Assertion `next_insert_id == 0' upon UPDATE on system-versioned table
#
create table t1 (pk integer auto_increment primary key) engine=myisam with system versioning;
insert delayed into t1 (pk) values (1);
lock tables t1 write;
update t1 set pk= 0;
update t1 set pk= 0;
unlock tables;
drop table t1;
...@@ -47,4 +47,17 @@ select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner jo ...@@ -47,4 +47,17 @@ select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner jo
drop table t1; drop table t1;
drop table t2; drop table t2;
--echo #
--echo # MDEV-22562 Assertion `next_insert_id == 0' upon UPDATE on system-versioned table
--echo #
create table t1 (pk integer auto_increment primary key) engine=myisam with system versioning;
insert delayed into t1 (pk) values (1);
lock tables t1 write;
update t1 set pk= 0;
update t1 set pk= 0;
unlock tables;
# cleanup
drop table t1;
-- source suite/versioning/common_finish.inc -- source suite/versioning/common_finish.inc
...@@ -3326,24 +3326,26 @@ int handler::update_auto_increment() ...@@ -3326,24 +3326,26 @@ int handler::update_auto_increment()
DBUG_RETURN(0); DBUG_RETURN(0);
} }
// ALTER TABLE ... ADD COLUMN ... AUTO_INCREMENT
if (thd->lex->sql_command == SQLCOM_ALTER_TABLE)
{
if (table->versioned()) if (table->versioned())
{ {
Field *end= table->vers_end_field(); Field *end= table->vers_end_field();
DBUG_ASSERT(end); DBUG_ASSERT(end);
bitmap_set_bit(table->read_set, end->field_index); bitmap_set_bit(table->read_set, end->field_index);
if (!end->is_max()) if (!end->is_max())
{
if (thd->lex->sql_command == SQLCOM_ALTER_TABLE)
{ {
if (!table->next_number_field->real_maybe_null()) if (!table->next_number_field->real_maybe_null())
DBUG_RETURN(HA_ERR_UNSUPPORTED); DBUG_RETURN(HA_ERR_UNSUPPORTED);
table->next_number_field->set_null(); table->next_number_field->set_null();
}
DBUG_RETURN(0); DBUG_RETURN(0);
} }
} }
// ALTER TABLE ... ADD COLUMN ... AUTO_INCREMENT
if (thd->lex->sql_command == SQLCOM_ALTER_TABLE)
table->next_number_field->set_notnull(); table->next_number_field->set_notnull();
}
if ((nr= next_insert_id) >= auto_inc_interval_for_cur_row.maximum()) if ((nr= next_insert_id) >= auto_inc_interval_for_cur_row.maximum())
{ {
......
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