An out of range error is produced when an INSERT is targeted at a partitioned table with a PARTITION clause to force the partition selection. Only occurs when using SELECT to get rows, not when using VALUES clause. Only occurs if the most recent statement targeting the table was a TRUNCATE PARTITION, but the TRUNCATE could be on any partition, not just the one being inserted.
The auto increment has plenty of room within the INT data type size and the relevant field values match the targeted partition. Performing a SELECT without a PARTITION clause against the table resolves the situation and the INSERT with PARTITION succeeds.
Before the fixes from MDEV-18244 this would crash. After that was fixed, the VALUES version of the INSERT worked, but the SELECT version throws the out of range error.
I have attached a test case that is slightly modified from the one in MDEV-20718 which demonstrates the slightly different scenario of using INSERT..SELECT.
MDEV-21027Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed in ha_partition::set_auto_increment_if_higher
Closed
MDEV-29636Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed in ha_partition::set_auto_increment_if_higher upon REPLACE with partition pruning
#selectcount(*) from t1; # this statement prevents the segfault
insertinto t1 partition (p1) (groupid) select 1;
#cleanup
droptable t1;
om debug version Assertion `part_share->auto_inc_initialized' fails:
10.3 3466b47b0d2f0aca0a2191574c593c7eaea0b0b8
#3 <signal handler called>
#4 0x00007fa09d382428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#5 0x00007fa09d38402a in __GI_abort () at abort.c:89
#6 0x00007fa09d37abd7 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x560fe7164d88 "part_share->auto_inc_initialized", file=file@entry=0x560fe7161a28 "/10.3/sql/ha_partition.cc", line=line@entry=10508, function=function@entry=0x560fe71669c0 <ha_partition::get_auto_increment(unsigned long long, unsigned long long, unsigned long long, unsigned long long*, unsigned long long*)::__PRETTY_FUNCTION__> "virtual void ha_partition::get_auto_increment(ulonglong, ulonglong, ulonglong, ulonglong*, ulonglong*)") at assert.c:92
#7 0x00007fa09d37ac82 in __GI___assert_fail (assertion=0x560fe7164d88 "part_share->auto_inc_initialized", file=0x560fe7161a28 "/10.3/sql/ha_partition.cc", line=10508, function=0x560fe71669c0 <ha_partition::get_auto_increment(unsigned long long, unsigned long long, unsigned long long, unsigned long long*, unsigned long long*)::__PRETTY_FUNCTION__> "virtual void ha_partition::get_auto_increment(ulonglong, ulonglong, ulonglong, ulonglong*, ulonglong*)") at assert.c:101
#8 0x0000560fe6ce5725 in ha_partition::get_auto_increment (this=0x7fa04c0a4108, offset=1, increment=1, nb_desired_values=1, first_value=0x7fa0969ec6a8, nb_reserved_values=0x7fa0969ec6b0) at /10.3/sql/ha_partition.cc:10508
#9 0x0000560fe64adccd in handler::update_auto_increment (this=0x7fa04c0a4108) at /10.3/sql/handler.cc:3390
#10 0x0000560fe6cd4fac in ha_partition::write_row (this=0x7fa04c0a4108, buf=0x7fa04c032a28 "\377") at /10.3/sql/ha_partition.cc:4290
#11 0x0000560fe64b646d in handler::ha_write_row (this=0x7fa04c0a4108, buf=0x7fa04c032a28 "\377") at /10.3/sql/handler.cc:6446
#12 0x0000560fe6146c08 in write_record (thd=0x7fa04c000af0, table=0x7fa04c0a34c0, info=0x7fa04c013250) at /10.3/sql/sql_insert.cc:2034
#13 0x0000560fe614c507 in select_insert::send_data (this=0x7fa04c013208, values=...) at /10.3/sql/sql_insert.cc:3952
#14 0x0000560fe61d5ad5 in JOIN::exec_inner (this=0x7fa04c0132b8) at /10.3/sql/sql_select.cc:3967
#15 0x0000560fe61d54c8 in JOIN::exec (this=0x7fa04c0132b8) at /10.3/sql/sql_select.cc:3886
#16 0x0000560fe61d67cf in mysql_select (thd=0x7fa04c000af0, tables=0x0, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=3489925888, result=0x7fa04c013208, unit=0x7fa04c0049c0, select_lex=0x7fa04c005148) at /10.3/sql/sql_select.cc:4291
#17 0x0000560fe61c7e60 in handle_select (thd=0x7fa04c000af0, lex=0x7fa04c0048f8, result=0x7fa04c013208, setup_tables_done_option=1073741824) at /10.3/sql/sql_select.cc:382
#18 0x0000560fe618885f in mysql_execute_command (thd=0x7fa04c000af0) at /10.3/sql/sql_parse.cc:4571
#19 0x0000560fe619393a in mysql_parse (thd=0x7fa04c000af0, rawbuf=0x7fa04c012818 "insert into t1 partition (p1) (groupid) select 1", length=48, parser_state=0x7fa0969ed460, is_com_multi=false, is_next_command=false) at /10.3/sql/sql_parse.cc:7818
#20 0x0000560fe6180421 in dispatch_command (command=COM_QUERY, thd=0x7fa04c000af0, packet=0x7fa04c008c71 "insert into t1 partition (p1) (groupid) select 1", packet_length=48, is_com_multi=false, is_next_command=false) at /10.3/sql/sql_parse.cc:1856
#21 0x0000560fe617ed2f in do_command (thd=0x7fa04c000af0) at /10.3/sql/sql_parse.cc:1402
#22 0x0000560fe62f774a in do_handle_one_connection (connect=0x560fe8cffaf0) at /10.3/sql/sql_connect.cc:1403
#23 0x0000560fe62f7486 in handle_one_connection (arg=0x560fe8cffaf0) at /10.3/sql/sql_connect.cc:1308
#24 0x0000560fe6ca767c in pfs_spawn_thread (arg=0x560fe8c4a2b0) at /10.3/storage/perfschema/pfs.cc:1862
#25 0x00007fa09dfbf6ba in start_thread (arg=0x7fa0969ee700) at pthread_create.c:333
#26 0x00007fa09d45441d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
Alice Sherepa
added a comment - - edited Thank you! I reproduced as described on 10.3-10.4, with MyIsam and InnoDb.
--source include/have_partition.inc
create table t1 (
id int not null auto_increment,
groupid int ,
primary key (id, groupid)
)partition by list(groupid) (partition p1 values in (1), partition p2 values in (2));
alter table t1 truncate partition p1;
# select count (*) from t1; # this statement prevents the segfault
insert into t1 partition (p1) (groupid) select 1;
#cleanup
drop table t1;
om debug version Assertion `part_share->auto_inc_initialized' fails:
10.3 3466b47b0d2f0aca0a2191574c593c7eaea0b0b8
#3 <signal handler called>
#4 0x00007fa09d382428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#5 0x00007fa09d38402a in __GI_abort () at abort.c:89
#6 0x00007fa09d37abd7 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x560fe7164d88 "part_share->auto_inc_initialized", file=file@entry=0x560fe7161a28 "/10.3/sql/ha_partition.cc", line=line@entry=10508, function=function@entry=0x560fe71669c0 <ha_partition::get_auto_increment(unsigned long long, unsigned long long, unsigned long long, unsigned long long*, unsigned long long*)::__PRETTY_FUNCTION__> "virtual void ha_partition::get_auto_increment(ulonglong, ulonglong, ulonglong, ulonglong*, ulonglong*)") at assert.c:92
#7 0x00007fa09d37ac82 in __GI___assert_fail (assertion=0x560fe7164d88 "part_share->auto_inc_initialized", file=0x560fe7161a28 "/10.3/sql/ha_partition.cc", line=10508, function=0x560fe71669c0 <ha_partition::get_auto_increment(unsigned long long, unsigned long long, unsigned long long, unsigned long long*, unsigned long long*)::__PRETTY_FUNCTION__> "virtual void ha_partition::get_auto_increment(ulonglong, ulonglong, ulonglong, ulonglong*, ulonglong*)") at assert.c:101
#8 0x0000560fe6ce5725 in ha_partition::get_auto_increment (this=0x7fa04c0a4108, offset=1, increment=1, nb_desired_values=1, first_value=0x7fa0969ec6a8, nb_reserved_values=0x7fa0969ec6b0) at /10.3/sql/ha_partition.cc:10508
#9 0x0000560fe64adccd in handler::update_auto_increment (this=0x7fa04c0a4108) at /10.3/sql/handler.cc:3390
#10 0x0000560fe6cd4fac in ha_partition::write_row (this=0x7fa04c0a4108, buf=0x7fa04c032a28 "\377") at /10.3/sql/ha_partition.cc:4290
#11 0x0000560fe64b646d in handler::ha_write_row (this=0x7fa04c0a4108, buf=0x7fa04c032a28 "\377") at /10.3/sql/handler.cc:6446
#12 0x0000560fe6146c08 in write_record (thd=0x7fa04c000af0, table=0x7fa04c0a34c0, info=0x7fa04c013250) at /10.3/sql/sql_insert.cc:2034
#13 0x0000560fe614c507 in select_insert::send_data (this=0x7fa04c013208, values=...) at /10.3/sql/sql_insert.cc:3952
#14 0x0000560fe61d5ad5 in JOIN::exec_inner (this=0x7fa04c0132b8) at /10.3/sql/sql_select.cc:3967
#15 0x0000560fe61d54c8 in JOIN::exec (this=0x7fa04c0132b8) at /10.3/sql/sql_select.cc:3886
#16 0x0000560fe61d67cf in mysql_select (thd=0x7fa04c000af0, tables=0x0, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=3489925888, result=0x7fa04c013208, unit=0x7fa04c0049c0, select_lex=0x7fa04c005148) at /10.3/sql/sql_select.cc:4291
#17 0x0000560fe61c7e60 in handle_select (thd=0x7fa04c000af0, lex=0x7fa04c0048f8, result=0x7fa04c013208, setup_tables_done_option=1073741824) at /10.3/sql/sql_select.cc:382
#18 0x0000560fe618885f in mysql_execute_command (thd=0x7fa04c000af0) at /10.3/sql/sql_parse.cc:4571
#19 0x0000560fe619393a in mysql_parse (thd=0x7fa04c000af0, rawbuf=0x7fa04c012818 "insert into t1 partition (p1) (groupid) select 1", length=48, parser_state=0x7fa0969ed460, is_com_multi=false, is_next_command=false) at /10.3/sql/sql_parse.cc:7818
#20 0x0000560fe6180421 in dispatch_command (command=COM_QUERY, thd=0x7fa04c000af0, packet=0x7fa04c008c71 "insert into t1 partition (p1) (groupid) select 1", packet_length=48, is_com_multi=false, is_next_command=false) at /10.3/sql/sql_parse.cc:1856
#21 0x0000560fe617ed2f in do_command (thd=0x7fa04c000af0) at /10.3/sql/sql_parse.cc:1402
#22 0x0000560fe62f774a in do_handle_one_connection (connect=0x560fe8cffaf0) at /10.3/sql/sql_connect.cc:1403
#23 0x0000560fe62f7486 in handle_one_connection (arg=0x560fe8cffaf0) at /10.3/sql/sql_connect.cc:1308
#24 0x0000560fe6ca767c in pfs_spawn_thread (arg=0x560fe8c4a2b0) at /10.3/storage/perfschema/pfs.cc:1862
#25 0x00007fa09dfbf6ba in start_thread (arg=0x7fa0969ee700) at pthread_create.c:333
#26 0x00007fa09d45441d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
Core was generated by `/test/MD140222-mariadb-10.9.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGABRT, Aborted.
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
[Current thread is 1 (Thread 0x151cac1b0700 (LWP 1272005))]
(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x0000151cc1835859 in __GI_abort () at abort.c:79
#2 0x0000151cc1835729 in __assert_fail_base (fmt=0x151cc19cb588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55e22691f9d0 "part_share->auto_inc_initialized || !can_use_for_auto_inc_init()", file=0x55e226738dc0 "/test/10.9_dbg/sql/ha_partition.h", line=1403, function=<optimized out>) at assert.c:92
#3 0x0000151cc1846f36 in __GI___assert_fail (assertion=assertion@entry=0x55e22691f9d0 "part_share->auto_inc_initialized || !can_use_for_auto_inc_init()", file=file@entry=0x55e226738dc0 "/test/10.9_dbg/sql/ha_partition.h", line=line@entry=1403, function=function@entry=0x55e22691fa18 "virtual void ha_partition::set_auto_increment_if_higher(Field*)") at assert.c:101
#4 0x000055e226035170 in ha_partition::set_auto_increment_if_higher (field=<optimized out>, this=0x151c5401dc50) at /test/10.9_dbg/sql/ha_partition.h:1403
#5 ha_partition::write_row (this=0x151c5401dc50, buf=0x151c5401d7e0 "\377\001") at /test/10.9_dbg/sql/ha_partition.cc:4487
#6 0x000055e225d54369 in handler::ha_write_row (this=0x151c5401dc50, buf=0x151c5401d7e0 "\377\001") at /test/10.9_dbg/sql/handler.cc:7522
#7 0x000055e2259ea372 in write_record (thd=0x151c54000db8, table=0x151c54029f68, info=info@entry=0x151c54015570, sink=0x0) at /test/10.9_dbg/sql/sql_insert.cc:2156
#8 0x000055e2259ea7c9 in select_insert::send_data (this=0x151c54015520, values=<optimized out>) at /test/10.9_dbg/sql/sql_insert.cc:4120
#9 0x000055e225acf6f4 in select_result_sink::send_data_with_check (sent=0, u=<optimized out>, items=<optimized out>, this=<optimized out>) at /test/10.9_dbg/sql/sql_class.h:5612
#10 JOIN::exec_inner (this=this@entry=0x151c540155e0) at /test/10.9_dbg/sql/sql_select.cc:4615
#11 0x000055e225ad08c0 in JOIN::exec (this=this@entry=0x151c540155e0) at /test/10.9_dbg/sql/sql_select.cc:4527
#12 0x000055e225ace8cf in mysql_select (thd=thd@entry=0x151c54000db8, tables=0x0, fields=@0x151c540149e0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x151c54014c38, last = 0x151c54014c38, elements = 1}, <No data fields>}, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2202244745984, result=0x151c54015520, unit=0x151c540051c8, select_lex=0x151c54014740) at /test/10.9_dbg/sql/sql_select.cc:5007
#13 0x000055e225aceb84 in handle_select (thd=thd@entry=0x151c54000db8, lex=lex@entry=0x151c540050f0, result=result@entry=0x151c54015520, setup_tables_done_option=setup_tables_done_option@entry=1073741824) at /test/10.9_dbg/sql/sql_select.cc:543
#14 0x000055e225a3d0c4 in mysql_execute_command (thd=thd@entry=0x151c54000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.9_dbg/sql/sql_parse.cc:4708
#15 0x000055e225a27315 in mysql_parse (thd=thd@entry=0x151c54000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x151cac1af400) at /test/10.9_dbg/sql/sql_parse.cc:8027
#16 0x000055e225a35fb1 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x151c54000db8, packet=packet@entry=0x151c5400b889 "INSERT INTO t PARTITION (p) (c) SELECT 1", packet_length=packet_length@entry=40, blocking=blocking@entry=true) at /test/10.9_dbg/sql/sql_class.h:1362
#17 0x000055e225a393f8 in do_command (thd=0x151c54000db8, blocking=blocking@entry=true) at /test/10.9_dbg/sql/sql_parse.cc:1402
#18 0x000055e225bb3fc4 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x55e229ed8b38, put_in_cache=put_in_cache@entry=true) at /test/10.9_dbg/sql/sql_connect.cc:1418
#19 0x000055e225bb45c9 in handle_one_connection (arg=arg@entry=0x55e229ed8b38) at /test/10.9_dbg/sql/sql_connect.cc:1312
#20 0x000055e22603ad67 in pfs_spawn_thread (arg=0x55e229e1b578) at /test/10.9_dbg/storage/perfschema/pfs.cc:2201
#21 0x0000151cc1d44609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#22 0x0000151cc1932293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
I believe that the bug is quite similar to MDEV-21027. check_insert_or_replace_autoincrement() should set the bitmap on SQLCOM_INSERT_SELECT too.
Nayuta Yanagisawa (Inactive)
added a comment - I believe that the bug is quite similar to MDEV-21027 . check_insert_or_replace_autoincrement() should set the bitmap on SQLCOM_INSERT_SELECT too.
Thank you! I reproduced as described on 10.3-10.4, with MyIsam and InnoDb.
--source include/have_partition.inc
#cleanup
om debug version Assertion `part_share->auto_inc_initialized' fails:
10.3 3466b47b0d2f0aca0a2191574c593c7eaea0b0b8
#3 <signal handler called>
#4 0x00007fa09d382428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#5 0x00007fa09d38402a in __GI_abort () at abort.c:89
#6 0x00007fa09d37abd7 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x560fe7164d88 "part_share->auto_inc_initialized", file=file@entry=0x560fe7161a28 "/10.3/sql/ha_partition.cc", line=line@entry=10508, function=function@entry=0x560fe71669c0 <ha_partition::get_auto_increment(unsigned long long, unsigned long long, unsigned long long, unsigned long long*, unsigned long long*)::__PRETTY_FUNCTION__> "virtual void ha_partition::get_auto_increment(ulonglong, ulonglong, ulonglong, ulonglong*, ulonglong*)") at assert.c:92
#7 0x00007fa09d37ac82 in __GI___assert_fail (assertion=0x560fe7164d88 "part_share->auto_inc_initialized", file=0x560fe7161a28 "/10.3/sql/ha_partition.cc", line=10508, function=0x560fe71669c0 <ha_partition::get_auto_increment(unsigned long long, unsigned long long, unsigned long long, unsigned long long*, unsigned long long*)::__PRETTY_FUNCTION__> "virtual void ha_partition::get_auto_increment(ulonglong, ulonglong, ulonglong, ulonglong*, ulonglong*)") at assert.c:101
#8 0x0000560fe6ce5725 in ha_partition::get_auto_increment (this=0x7fa04c0a4108, offset=1, increment=1, nb_desired_values=1, first_value=0x7fa0969ec6a8, nb_reserved_values=0x7fa0969ec6b0) at /10.3/sql/ha_partition.cc:10508
#9 0x0000560fe64adccd in handler::update_auto_increment (this=0x7fa04c0a4108) at /10.3/sql/handler.cc:3390
#10 0x0000560fe6cd4fac in ha_partition::write_row (this=0x7fa04c0a4108, buf=0x7fa04c032a28 "\377") at /10.3/sql/ha_partition.cc:4290
#11 0x0000560fe64b646d in handler::ha_write_row (this=0x7fa04c0a4108, buf=0x7fa04c032a28 "\377") at /10.3/sql/handler.cc:6446
#12 0x0000560fe6146c08 in write_record (thd=0x7fa04c000af0, table=0x7fa04c0a34c0, info=0x7fa04c013250) at /10.3/sql/sql_insert.cc:2034
#13 0x0000560fe614c507 in select_insert::send_data (this=0x7fa04c013208, values=...) at /10.3/sql/sql_insert.cc:3952
#14 0x0000560fe61d5ad5 in JOIN::exec_inner (this=0x7fa04c0132b8) at /10.3/sql/sql_select.cc:3967
#15 0x0000560fe61d54c8 in JOIN::exec (this=0x7fa04c0132b8) at /10.3/sql/sql_select.cc:3886
#16 0x0000560fe61d67cf in mysql_select (thd=0x7fa04c000af0, tables=0x0, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=3489925888, result=0x7fa04c013208, unit=0x7fa04c0049c0, select_lex=0x7fa04c005148) at /10.3/sql/sql_select.cc:4291
#17 0x0000560fe61c7e60 in handle_select (thd=0x7fa04c000af0, lex=0x7fa04c0048f8, result=0x7fa04c013208, setup_tables_done_option=1073741824) at /10.3/sql/sql_select.cc:382
#18 0x0000560fe618885f in mysql_execute_command (thd=0x7fa04c000af0) at /10.3/sql/sql_parse.cc:4571
#19 0x0000560fe619393a in mysql_parse (thd=0x7fa04c000af0, rawbuf=0x7fa04c012818 "insert into t1 partition (p1) (groupid) select 1", length=48, parser_state=0x7fa0969ed460, is_com_multi=false, is_next_command=false) at /10.3/sql/sql_parse.cc:7818
#20 0x0000560fe6180421 in dispatch_command (command=COM_QUERY, thd=0x7fa04c000af0, packet=0x7fa04c008c71 "insert into t1 partition (p1) (groupid) select 1", packet_length=48, is_com_multi=false, is_next_command=false) at /10.3/sql/sql_parse.cc:1856
#21 0x0000560fe617ed2f in do_command (thd=0x7fa04c000af0) at /10.3/sql/sql_parse.cc:1402
#22 0x0000560fe62f774a in do_handle_one_connection (connect=0x560fe8cffaf0) at /10.3/sql/sql_connect.cc:1403
#23 0x0000560fe62f7486 in handle_one_connection (arg=0x560fe8cffaf0) at /10.3/sql/sql_connect.cc:1308
#24 0x0000560fe6ca767c in pfs_spawn_thread (arg=0x560fe8c4a2b0) at /10.3/storage/perfschema/pfs.cc:1862
#25 0x00007fa09dfbf6ba in start_thread (arg=0x7fa0969ee700) at pthread_create.c:333
#26 0x00007fa09d45441d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109