Commit da03d8d9 authored by lrf141's avatar lrf141 Committed by Nikita Malyavin

MDEV-19190 Assertion `...auto_inc_initialized` failed in get_auto_increment

This is a DELETE only case. Normally this statement doesn't make inserts,
but DELETE ... FOR PORTION changes it. UPDATE and INSERT initializes
autoinc by calling handler::info(HA_STATUS_AUTO). Also myisam and innodb
can lazily initialize it in their update_create_info overrides.

The solution is to initialize autoinc during delete preparation,
if period (DELETE FOR PORTION) is specified.

The initial work has been done by Kento Takeuchi by his PR #2048,
however this commit also holds a few technical modifications by
Nikita Malyavin
parent 1ebf0b73
......@@ -388,3 +388,27 @@ ERROR 22003: Out of range value for column 'f' at row ROW
delete ignore from t
for portion of app from '2015-07-07 00:00:00' to '2020-03-11 08:48:52';
drop table t;
#
# MDEV-19190 Assertion `part_share->auto_inc_initialized` failed in
# ha_partition::get_auto_increment
#
create table t1 (id int, s date, e date, period for app(s,e))
partition by key(id);
insert into t1 (s,e) values ('2023-07-21','2024-06-07');
alter table t1 modify id int auto_increment key;
delete from t1 for portion of app from '2023-07-20' to '2024-05-23';
select * from t1;
id s e
2 2024-05-23 2024-06-07
drop table t1;
create table t1 (id int, s date, e date, period for app(s,e))
partition by key(id);
insert into t1 (s,e) values ('2023-07-21','2024-06-07');
alter table t1 modify id int auto_increment key;
delete from t1 for portion of app from '2023-07-20' to '2024-05-23';
select * from t1;
id s e
2 2024-05-23 2024-06-07
drop table t1;
drop table log_tbl;
drop procedure log;
source suite/period/engines.inc;
source include/have_log_bin.inc;
source include/have_partition.inc;
create table t (id int, s date, e date, period for apptime(s,e));
......@@ -225,3 +226,31 @@ delete ignore from t
--enable_warnings
drop table t;
--echo #
--echo # MDEV-19190 Assertion `part_share->auto_inc_initialized` failed in
--echo # ha_partition::get_auto_increment
--echo #
create table t1 (id int, s date, e date, period for app(s,e))
partition by key(id);
insert into t1 (s,e) values ('2023-07-21','2024-06-07');
alter table t1 modify id int auto_increment key;
delete from t1 for portion of app from '2023-07-20' to '2024-05-23';
select * from t1;
drop table t1;
create table t1 (id int, s date, e date, period for app(s,e))
partition by key(id);
insert into t1 (s,e) values ('2023-07-21','2024-06-07');
alter table t1 modify id int auto_increment key;
--let $trig_table=t1
--let $trig_cols=id, s, e
--disable_query_log
--source suite/period/create_triggers.inc
--enable_query_log
delete from t1 for portion of app from '2023-07-20' to '2024-05-23';
select * from t1;
drop table t1;
drop table log_tbl;
drop procedure log;
......@@ -4003,7 +4003,7 @@ void handler::print_error(int error, myf errflag)
break;
case HA_ERR_AUTOINC_ERANGE:
textno= error;
my_error(textno, errflag, table->next_number_field->field_name.str,
my_error(textno, errflag, table->found_next_number_field->field_name.str,
table->in_use->get_stmt_da()->current_row_for_warning());
DBUG_VOID_RETURN;
break;
......
......@@ -707,6 +707,10 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
{
table->use_all_columns();
table->rpl_write_set= table->write_set;
// Initialize autoinc.
// We don't set next_number_field here, as it is handled manually.
if (table->found_next_number_field)
table->file->info(HA_STATUS_AUTO);
}
else
{
......
......@@ -8733,6 +8733,7 @@ int TABLE::update_generated_fields()
res= found_next_number_field->set_default();
if (likely(!res))
res= file->update_auto_increment();
next_number_field= NULL;
}
if (likely(!res) && vfield)
......
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