Commit efedf3da authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-22711 Assertion `nr != 0' failed in handler::update_auto_increment.

DBUG_ASSERT removed as the AUTO INCREMENT can actually be 0 when the
SET insert_id= 0; was done.
parent d627d00b
...@@ -69,3 +69,28 @@ id name ...@@ -69,3 +69,28 @@ id name
drop table t1; drop table t1;
disconnect test_con1; disconnect test_con1;
disconnect test_con2; disconnect test_con2;
connection default;
CREATE TABLE t1(id int primary key auto_increment);
SET SESSION insert_id=123;
SET SESSION insert_id=0;
INSERT INTO t1 VALUES ();
SET SESSION insert_id=123;
SET SESSION insert_id=default;
INSERT INTO t1 VALUES ();
SET SESSION insert_id=123;
SET SESSION insert_id=-1;
Warnings:
Warning 1292 Truncated incorrect insert_id value: '-1'
INSERT INTO t1 VALUES ();
SET SESSION insert_id=123;
SET SESSION insert_id=-10;
Warnings:
Warning 1292 Truncated incorrect insert_id value: '-10'
INSERT INTO t1 VALUES ();
SELECT * FROM t1;
id
1
2
3
4
DROP TABLE t1;
...@@ -103,3 +103,23 @@ drop table t1; ...@@ -103,3 +103,23 @@ drop table t1;
disconnect test_con1; disconnect test_con1;
disconnect test_con2; disconnect test_con2;
# MDEV-22711 Assertion `nr != 0' failed in handler::update_auto_increment.
#
connection default;
CREATE TABLE t1(id int primary key auto_increment);
SET SESSION insert_id=123;
SET SESSION insert_id=0;
INSERT INTO t1 VALUES ();
SET SESSION insert_id=123;
SET SESSION insert_id=default;
INSERT INTO t1 VALUES ();
SET SESSION insert_id=123;
SET SESSION insert_id=-1;
INSERT INTO t1 VALUES ();
SET SESSION insert_id=123;
SET SESSION insert_id=-10;
INSERT INTO t1 VALUES ();
SELECT * FROM t1;
DROP TABLE t1;
...@@ -4064,12 +4064,16 @@ static Sys_var_session_special Sys_identity( ...@@ -4064,12 +4064,16 @@ static Sys_var_session_special Sys_identity(
*/ */
static bool update_insert_id(THD *thd, set_var *var) static bool update_insert_id(THD *thd, set_var *var)
{ {
if (!var->value) /*
{ If we set the insert_id to the DEFAULT or 0
my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str); it means we 'reset' it so it's value doesn't
return true; affect the INSERT.
} */
thd->force_one_auto_inc_interval(var->save_result.ulonglong_value); if (!var->value ||
var->save_result.ulonglong_value == 0)
thd->auto_inc_intervals_forced.empty();
else
thd->force_one_auto_inc_interval(var->save_result.ulonglong_value);
return false; return false;
} }
...@@ -4077,6 +4081,8 @@ static ulonglong read_insert_id(THD *thd) ...@@ -4077,6 +4081,8 @@ static ulonglong read_insert_id(THD *thd)
{ {
return thd->auto_inc_intervals_forced.minimum(); return thd->auto_inc_intervals_forced.minimum();
} }
static Sys_var_session_special Sys_insert_id( static Sys_var_session_special Sys_insert_id(
"insert_id", "The value to be used by the following INSERT " "insert_id", "The value to be used by the following INSERT "
"or ALTER TABLE statement when inserting an AUTO_INCREMENT value", "or ALTER TABLE statement when inserting an AUTO_INCREMENT value",
......
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