Skip to content

Commit

Permalink
MDEV-19130 Assertion failed in handler::update_auto_increment
Browse files Browse the repository at this point in the history
add store/restore_auto_increment in period portion insert/update functions
  • Loading branch information
FooBarrior committed Oct 14, 2020
1 parent c2ac0ce commit 5896a49
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
20 changes: 20 additions & 0 deletions mysql-test/suite/period/r/delete.result
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,23 @@ drop procedure sp;
drop table t,t2,t3,log_tbl;
drop view v;
drop procedure log;
# MDEV-19130 Assertion
# `next_insert_id >= auto_inc_interval_for_cur_row.minimum()'
# failed in handler::update_auto_increment after error 167
create or replace table t (f tinyint auto_increment null,
s timestamp, e timestamp,
period for app(s,e), key(f, s));
insert into t (s,e) values
('2021-08-22 10:28:43', '2023-09-17 00:00:00'),
('2019-05-09 21:45:24', '2020-04-22 14:38:49');
insert into t (s,e) select s,e from t;
insert into t (s,e) select s,e from t;
insert into t (s,e) select s,e from t;
insert into t (s,e) values ('2015-07-07 00:00:00','2020-03-11 08:48:52');
insert into t (s,e) select s,e from t;
insert into t (s,e) select s,e from t;
insert into t select * from t;
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;
11 changes: 11 additions & 0 deletions mysql-test/suite/period/r/update.result
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,14 @@ create table t1 (s date, e date, period for app(s,e), f varchar(8)) engine=aria
insert into t1 values ('2024-05-13','2026-03-25','foo');
update t1 for portion of app from '2024-04-02' to '2026-03-15' set f = 'bar';
drop table t1;
# MDEV-19130 Assertion
# `next_insert_id >= auto_inc_interval_for_cur_row.minimum()'
# failed in handler::update_auto_increment after error 167
create table t1 (id int auto_increment, f int, s datetime, e datetime, period for p(s,e), primary key(id));
insert into t1 (s,e) values ('1994-01-06','2004-11-30'),('1994-06-21','1997-06-20');
update ignore t1 set id = 2429681664;
Warnings:
Warning 1264 Out of range value for column 'id' at row 1
Warning 1264 Out of range value for column 'id' at row 2
update ignore t1 for portion of p from '1995-07-06' to '2009-01-12' set f = 1;
drop table t1;
29 changes: 28 additions & 1 deletion mysql-test/suite/period/t/delete.test
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,34 @@ call sp;
drop table t1;
drop procedure sp;


drop table t,t2,t3,log_tbl;
drop view v;
drop procedure log;

--echo # MDEV-19130 Assertion
--echo # `next_insert_id >= auto_inc_interval_for_cur_row.minimum()'
--echo # failed in handler::update_auto_increment after error 167

create or replace table t (f tinyint auto_increment null,
s timestamp, e timestamp,
period for app(s,e), key(f, s));
insert into t (s,e) values
('2021-08-22 10:28:43', '2023-09-17 00:00:00'),
('2019-05-09 21:45:24', '2020-04-22 14:38:49');
insert into t (s,e) select s,e from t;
insert into t (s,e) select s,e from t;
insert into t (s,e) select s,e from t;
insert into t (s,e) values ('2015-07-07 00:00:00','2020-03-11 08:48:52');
insert into t (s,e) select s,e from t;
insert into t (s,e) select s,e from t;

--replace_regex /row \d+/row ROW/
--error HA_ERR_AUTOINC_ERANGE
insert into t select * from t;

--disable_warnings
delete ignore from t
for portion of app from '2015-07-07 00:00:00' to '2020-03-11 08:48:52';
--enable_warnings

drop table t;
10 changes: 10 additions & 0 deletions mysql-test/suite/period/t/update.test
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,13 @@ update t1 for portion of app from '2024-04-02' to '2026-03-15' set f = 'bar';

# cleanup
drop table t1;

--echo # MDEV-19130 Assertion
--echo # `next_insert_id >= auto_inc_interval_for_cur_row.minimum()'
--echo # failed in handler::update_auto_increment after error 167
create table t1 (id int auto_increment, f int, s datetime, e datetime, period for p(s,e), primary key(id));
insert into t1 (s,e) values ('1994-01-06','2004-11-30'),('1994-06-21','1997-06-20');
update ignore t1 set id = 2429681664;
update ignore t1 for portion of p from '1995-07-06' to '2009-01-12' set f = 1;

drop table t1;
3 changes: 3 additions & 0 deletions sql/sql_delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ int update_portion_of_time(THD *thd, TABLE *table,
uint dst_fieldno= lcond ? table->s->period.end_fieldno
: table->s->period.start_fieldno;

table->file->store_auto_increment();
store_record(table, record[1]);
if (likely(!res))
res= src->save_in_field(table->field[dst_fieldno], true);
Expand All @@ -274,6 +275,8 @@ int update_portion_of_time(THD *thd, TABLE *table,
res= table->triggers->process_triggers(thd, TRG_EVENT_INSERT,
TRG_ACTION_AFTER, true);
restore_record(table, record[1]);
if (res)
table->file->restore_auto_increment();

if (likely(!res) && lcond && rcond)
res= table->period_make_insert(period_conds.end.item,
Expand Down
3 changes: 3 additions & 0 deletions sql/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8499,6 +8499,7 @@ int TABLE::period_make_insert(Item *src, Field *dst)
{
THD *thd= in_use;

file->store_auto_increment();
store_record(this, record[1]);
int res= src->save_in_field(dst, true);

Expand All @@ -8517,6 +8518,8 @@ int TABLE::period_make_insert(Item *src, Field *dst)
TRG_ACTION_AFTER, true);

restore_record(this, record[1]);
if (res)
file->restore_auto_increment();
return res;
}

Expand Down

0 comments on commit 5896a49

Please sign in to comment.