[MDEV-27854] SIGSEGV in heap_info on second stored procedure call Created: 2022-02-16  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Data Definition - Temporary, Stored routines
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 10.4, 10.5, 10.6, 10.11, 11.0

Type: Bug Priority: Major
Reporter: Roel Van de Paar Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: not-10.2, regression-10.3, stored_procedures, upstream-5.5

Issue Links:
Relates
relates to MDEV-23213 Server crashes in opt_sum_query / (ma... Open

 Description   

Somewhat similar to MDEV-23213, but the versions affected are different and optimizer setting derived_merge is not modified/used here. Also noting that MDEV-23213 does not reproduce on MySQL 5.5 as derived_merge is not implemented there.

CREATE TABLE t2 (c INT,c2 CHAR(1),c3 DATE) ENGINE=InnoDB;
CREATE PROCEDURE p (cnt INT(1)) SELECT COUNT(*) INTO cnt FROM t;
CREATE VIEW t AS SELECT * FROM t2;
CREATE TEMPORARY TABLE t (c TEXT);
CALL p (1);
DROP TEMPORARY TABLE IF EXISTS t,t2;
CALL p (1);

Leads to:

10.9.0 b5852ffbeebc3000982988383daeefb0549e058a (Debug)

Core was generated by `/test/MD140222-mariadb-10.9.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  heap_info (info=0x0, x=x@entry=0x14a57c0ae2b0, flag=flag@entry=18)
    at /test/10.9_dbg/storage/heap/hp_info.c:34
34	  x->records         = info->s->records;
[Current thread is 1 (Thread 0x14a57c0b2700 (LWP 4012922))]
(gdb) bt
#0  heap_info (info=0x0, x=x@entry=0x14a57c0ae2b0, flag=flag@entry=18) at /test/10.9_dbg/storage/heap/hp_info.c:34
#1  0x00005602557402dc in ha_heap::info (this=0x14a4ec0a9120, flag=18) at /test/10.9_dbg/storage/heap/ha_heap.cc:370
#2  0x0000560254f94b27 in opt_sum_query (thd=0x14a4ec000db8, tables=@0x14a4ec0544b0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14a4ec05e7f8, last = 0x14a4ec05e7f8, elements = 1}, <No data fields>}, all_fields=@0x14a4ec05dd78: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14a4ec0548a8, last = 0x14a4ec0548a8, elements = 1}, <No data fields>}, conds=0x0) at /test/10.9_dbg/sql/opt_sum.cc:318
#3  0x000056025513da9e in JOIN::optimize_inner (this=this@entry=0x14a4ec05da10) at /test/10.9_dbg/sql/sql_select.cc:2374
#4  0x000056025513e1dc in JOIN::optimize (this=this@entry=0x14a4ec05da10) at /test/10.9_dbg/sql/sql_select.cc:1808
#5  0x000056025513e880 in mysql_select (thd=thd@entry=0x14a4ec000db8, tables=0x14a4ec0549b8, fields=@0x14a4ec054538: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14a4ec0548a8, last = 0x14a4ec0548a8, elements = 1}, <No data fields>}, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147749632, result=0x14a4ec0548d8, unit=0x14a4ec0553e8, select_lex=0x14a4ec054298) at /test/10.9_dbg/sql/sql_select.cc:4993
#6  0x000056025513eb84 in handle_select (thd=thd@entry=0x14a4ec000db8, lex=lex@entry=0x14a4ec055310, result=result@entry=0x14a4ec0548d8, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.9_dbg/sql/sql_select.cc:543
#7  0x000056025509e124 in execute_sqlcom_select (thd=thd@entry=0x14a4ec000db8, all_tables=0x14a4ec0549b8) at /test/10.9_dbg/sql/sql_parse.cc:6252
#8  0x00005602550ab08b in mysql_execute_command (thd=0x14a4ec000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.9_dbg/sql/sql_parse.cc:3943
#9  0x0000560254fc21cc in sp_instr_stmt::exec_core (this=0x14a4ec0550b8, thd=<optimized out>, nextp=0x14a57c0b022c) at /test/10.9_dbg/sql/sp_head.cc:3834
#10 0x0000560254fd0c4b in sp_lex_keeper::reset_lex_and_exec_core (this=this@entry=0x14a4ec055100, thd=thd@entry=0x14a4ec000db8, nextp=nextp@entry=0x14a57c0b022c, open_tables=open_tables@entry=false, instr=instr@entry=0x14a4ec0550b8) at /test/10.9_dbg/sql/sp_head.cc:3560
#11 0x0000560254fd1566 in sp_instr_stmt::execute (this=0x14a4ec0550b8, thd=0x14a4ec000db8, nextp=0x14a57c0b022c) at /test/10.9_dbg/sql/sp_head.cc:3740
#12 0x0000560254fc8bcd in sp_head::execute (this=this@entry=0x14a4ec053280, thd=thd@entry=0x14a4ec000db8, merge_da_on_success=merge_da_on_success@entry=true) at /test/10.9_dbg/sql/sp_head.cc:1437
#13 0x0000560254fcb24e in sp_head::execute_procedure (this=0x14a4ec053280, thd=thd@entry=0x14a4ec000db8, args=0x14a4ec006098) at /test/10.9_dbg/sql/sp_head.cc:2424
#14 0x000056025509da19 in do_execute_sp (thd=thd@entry=0x14a4ec000db8, sp=sp@entry=0x14a4ec053280) at /test/10.9_dbg/sql/sql_parse.cc:3023
#15 0x00005602550a348a in Sql_cmd_call::execute (this=0x14a4ec013e90, thd=0x14a4ec000db8) at /test/10.9_dbg/sql/sql_parse.cc:3269
#16 0x00005602550b080e in mysql_execute_command (thd=thd@entry=0x14a4ec000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.9_dbg/sql/sql_parse.cc:5988
#17 0x0000560255097315 in mysql_parse (thd=thd@entry=0x14a4ec000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14a57c0b1400) at /test/10.9_dbg/sql/sql_parse.cc:8027
#18 0x00005602550a5fb1 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14a4ec000db8, packet=packet@entry=0x14a4ec00b889 "CALL p (1)", packet_length=packet_length@entry=10, blocking=blocking@entry=true) at /test/10.9_dbg/sql/sql_class.h:1362
#19 0x00005602550a93f8 in do_command (thd=0x14a4ec000db8, blocking=blocking@entry=true) at /test/10.9_dbg/sql/sql_parse.cc:1402
#20 0x0000560255223fc4 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x56025862b848, put_in_cache=put_in_cache@entry=true) at /test/10.9_dbg/sql/sql_connect.cc:1418
#21 0x00005602552245c9 in handle_one_connection (arg=arg@entry=0x56025862b848) at /test/10.9_dbg/sql/sql_connect.cc:1312
#22 0x00005602556aad67 in pfs_spawn_thread (arg=0x56025853e9a8) at /test/10.9_dbg/storage/perfschema/pfs.cc:2201
#23 0x000014a587a25609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#24 0x000014a587613293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.3.33 (dbg), 10.3.33 (opt), 10.4.23 (dbg), 10.4.23 (opt), 10.5.14 (dbg), 10.5.14 (opt), 10.6.6 (dbg), 10.6.6 (opt), 10.7.2 (dbg), 10.7.2 (opt), 10.8.1 (dbg), 10.8.1 (opt), 10.9.0 (dbg), 10.9.0 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.2.42 (dbg), 10.2.42 (opt)
MySQL: 5.6.51 (dbg), 5.6.51 (opt), 5.7.36 (dbg), 5.7.36 (opt), 8.0.27 (dbg), 8.0.27 (opt)



 Comments   
Comment by Roel Van de Paar [ 2022-02-16 ]

Here is how MySQL 5.5 (affected) crashes:

MSQL 5.5.62 (Debug)

mysqld: /test/5.5_dbg/sql/sql_select.cc:9479: void restore_prev_nj_state(JOIN_TAB*): Assertion `nest->counter > 0' failed.

MSQL 5.5.62 (Debug)

Core was generated by `/test/MS121121-mysql-5.5.62-linux-x86_64-dbg/bin/mysqld --no-defaults --core --'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
[Current thread is 1 (Thread 0x152c0cc1f700 (LWP 808806))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
#1  0x000055e4dd3cb1f1 in my_write_core (sig=sig@entry=6) at /test/5.5_dbg/mysys/stacktrace.c:433
#2  0x000055e4dd288e1e in handle_fatal_signal (sig=6) at /test/5.5_dbg/sql/signal_handler.cc:247
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#5  0x0000152c1d492859 in __GI_abort () at abort.c:79
#6  0x0000152c1d492729 in __assert_fail_base (fmt=0x152c1d628588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55e4dd688960 "nest->counter > 0", file=0x55e4dd6878a8 "/test/5.5_dbg/sql/sql_select.cc", line=9479, function=<optimized out>) at assert.c:92
#7  0x0000152c1d4a3f36 in __GI___assert_fail (assertion=assertion@entry=0x55e4dd688960 "nest->counter > 0", file=file@entry=0x55e4dd6878a8 "/test/5.5_dbg/sql/sql_select.cc", line=line@entry=9479, function=function@entry=0x55e4dd6879c0 "void restore_prev_nj_state(JOIN_TAB*)") at assert.c:101
#8  0x000055e4dd18b0b4 in restore_prev_nj_state (last=last@entry=0x152c0001d8a8) at /test/5.5_dbg/sql/sql_select.cc:9476
#9  0x000055e4dd18e5b7 in best_extension_by_limited_search (join=join@entry=0x152c0001c130, remaining_tables=remaining_tables@entry=1, idx=idx@entry=0, record_count=record_count@entry=1, read_time=read_time@entry=0, search_depth=search_depth@entry=62, prune_level=prune_level@entry=1) at /test/5.5_dbg/sql/sql_select.cc:5634
#10 0x000055e4dd1a322c in greedy_search (prune_level=1, search_depth=62, remaining_tables=1, join=0x152c0001c130) at /test/5.5_dbg/sql/sql_select.cc:5321
#11 choose_plan (join_tables=<optimized out>, join=0x152c0001c130) at /test/5.5_dbg/sql/sql_select.cc:5035
#12 make_join_statistics (join=join@entry=0x152c0001c130, tables_arg=0x152c0002ce10, conds=0x0, keyuse_array=keyuse_array@entry=0x152c0001d6e8) at /test/5.5_dbg/sql/sql_select.cc:3143
#13 0x000055e4dd1a5f93 in JOIN::optimize (this=this@entry=0x152c0001c130) at /test/5.5_dbg/sql/sql_select.cc:1072
#14 0x000055e4dd1aae4f in mysql_select (thd=thd@entry=0x55e4df497ba0, rref_pointer_array=rref_pointer_array@entry=0x152c00023f40, tables=0x152c00014610, wild_num=0, fields=@0x152c00023e68: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x152c000249e0, last = 0x152c000249e0, elements = 1}, <No data fields>}, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147749632, result=0x152c00024a08, unit=0x152c00023738, select_lex=0x152c00023d58) at /test/5.5_dbg/sql/sql_select.cc:2605
#15 0x000055e4dd1ab0df in handle_select (thd=thd@entry=0x55e4df497ba0, lex=lex@entry=0x152c00023688, result=result@entry=0x152c00024a08, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/5.5_dbg/sql/sql_select.cc:285
#16 0x000055e4dd15e26c in execute_sqlcom_select (thd=thd@entry=0x55e4df497ba0, all_tables=0x152c00014610) at /test/5.5_dbg/sql/sql_parse.cc:4676
#17 0x000055e4dd16535a in mysql_execute_command (thd=0x55e4df497ba0) at /test/5.5_dbg/sql/sql_parse.cc:2213
#18 0x000055e4dd366b6d in sp_instr_stmt::exec_core (this=0x152c00024ac0, thd=<optimized out>, nextp=0x152c0cc1d3b4) at /test/5.5_dbg/sql/sp_head.cc:3209
#19 0x000055e4dd36d8cd in sp_lex_keeper::reset_lex_and_exec_core (this=this@entry=0x152c00024b00, thd=thd@entry=0x55e4df497ba0, nextp=nextp@entry=0x152c0cc1d3b4, open_tables=open_tables@entry=false, instr=instr@entry=0x152c00024ac0) at /test/5.5_dbg/sql/sp_head.cc:2998
#20 0x000055e4dd36dd61 in sp_instr_stmt::execute (this=0x152c00024ac0, thd=0x55e4df497ba0, nextp=0x152c0cc1d3b4) at /test/5.5_dbg/sql/sp_head.cc:3141
#21 0x000055e4dd36960d in sp_head::execute (this=this@entry=0x152c00022eb0, thd=thd@entry=0x55e4df497ba0, merge_da_on_success=merge_da_on_success@entry=true) at /test/5.5_dbg/sql/sp_head.cc:1435
#22 0x000055e4dd36ad2c in sp_head::execute_procedure (this=this@entry=0x152c00022eb0, thd=thd@entry=0x55e4df497ba0, args=args@entry=0x55e4df49a130) at /test/5.5_dbg/sql/sp_head.cc:2199
#23 0x000055e4dd16ab38 in mysql_execute_command (thd=thd@entry=0x55e4df497ba0) at /test/5.5_dbg/sql/sql_parse.cc:4120
#24 0x000055e4dd16cc47 in mysql_parse (thd=thd@entry=0x55e4df497ba0, rawbuf=<optimized out>, length=10, parser_state=parser_state@entry=0x152c0cc1e610) at /test/5.5_dbg/sql/sql_parse.cc:5831
#25 0x000055e4dd16e4bd in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x55e4df497ba0, packet=packet@entry=0x55e4df51efb1 "CALL p (1)", packet_length=packet_length@entry=10) at /test/5.5_dbg/sql/sql_class.h:758
#26 0x000055e4dd16fd83 in do_command (thd=0x55e4df497ba0) at /test/5.5_dbg/sql/sql_parse.cc:776
#27 0x000055e4dd2203f2 in do_handle_one_connection (thd_arg=thd_arg@entry=0x55e4df497ba0) at /test/5.5_dbg/sql/sql_connect.cc:870
#28 0x000055e4dd2204c4 in handle_one_connection (arg=0x55e4df497ba0) at /test/5.5_dbg/sql/sql_connect.cc:789
#29 0x0000152c1d99b609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#30 0x0000152c1d58f293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

MSQL 5.5.62 (Optimized)

Core was generated by `/test/MS121121-mysql-5.5.62-linux-x86_64-opt/bin/mysqld --no-defaults --core --'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=11)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
[Current thread is 1 (Thread 0x14c5e40c0700 (LWP 808808))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=11) at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
#1  0x0000555682b00fcf in my_write_core (sig=sig@entry=11) at /test/5.5_opt/mysys/stacktrace.c:433
#2  0x00005556829d915e in handle_fatal_signal (sig=11) at /test/5.5_opt/sql/signal_handler.cc:247
#3  <signal handler called>
#4  0x000055568290ef0a in make_cond_for_table (cond=cond@entry=0x0, tables=tables@entry=13835058055282163713, used_table=1) at /test/5.5_opt/sql/sql_select.cc:13340
#5  0x000055568291029f in make_join_select (join=join@entry=0x14c5d801c6e0, select=0x14c5d8037570, cond=0x0) at /test/5.5_opt/sql/sql_select.cc:6807
#6  0x0000555682920f00 in JOIN::optimize (this=0x14c5d801c6e0) at /test/5.5_opt/sql/sql_select.cc:1203
#7  JOIN::optimize (this=0x14c5d801c6e0) at /test/5.5_opt/sql/sql_select.cc:856
#8  0x0000555682923d7a in mysql_select (thd=thd@entry=0x5556853822c0, rref_pointer_array=rref_pointer_array@entry=0x14c5d80246f0, tables=0x14c5d8029680, wild_num=0, fields=@0x14c5d8024618: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14c5d8025190, last = 0x14c5d8025190, elements = 1}, <No data fields>}, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147749632, result=0x14c5d80251b8, unit=0x14c5d8023ee8, select_lex=0x14c5d8024508) at /test/5.5_opt/sql/sql_select.cc:2605
#9  0x0000555682923f22 in handle_select (thd=thd@entry=0x5556853822c0, lex=lex@entry=0x14c5d8023e38, result=result@entry=0x14c5d80251b8, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/5.5_opt/sql/sql_select.cc:285
#10 0x00005556828dfd92 in execute_sqlcom_select (thd=thd@entry=0x5556853822c0, all_tables=0x14c5d8029680) at /test/5.5_opt/sql/sql_parse.cc:4676
#11 0x00005556828e9e2a in mysql_execute_command (thd=0x5556853822c0) at /test/5.5_opt/sql/sql_parse.cc:2213
#12 0x0000555682aa49d9 in sp_instr_stmt::exec_core (this=0x14c5d8025268, thd=<optimized out>, nextp=0x14c5e40be4c4) at /test/5.5_opt/sql/sp_head.cc:3209
#13 0x0000555682aab0bb in sp_lex_keeper::reset_lex_and_exec_core (this=this@entry=0x14c5d80252a8, thd=thd@entry=0x5556853822c0, nextp=nextp@entry=0x14c5e40be4c4, open_tables=open_tables@entry=false, instr=instr@entry=0x14c5d8025268) at /test/5.5_opt/sql/sp_head.cc:2998
#14 0x0000555682aab445 in sp_instr_stmt::execute (this=0x14c5d8025268, thd=0x5556853822c0, nextp=0x14c5e40be4c4) at /test/5.5_opt/sql/sp_head.cc:3141
#15 0x0000555682aa7a9b in sp_head::execute (this=this@entry=0x14c5d8023660, thd=thd@entry=0x5556853822c0, merge_da_on_success=merge_da_on_success@entry=true) at /test/5.5_opt/sql/sp_head.cc:1435
#16 0x0000555682aa9291 in sp_head::execute_procedure (this=this@entry=0x14c5d8023660, thd=thd@entry=0x5556853822c0, args=args@entry=0x555685384840) at /test/5.5_opt/sql/sp_head.cc:2199
#17 0x00005556828e931c in mysql_execute_command (thd=thd@entry=0x5556853822c0) at /test/5.5_opt/sql/sql_parse.cc:4120
#18 0x00005556828ebe4f in mysql_parse (rawbuf=<optimized out>, length=10, parser_state=0x14c5e40bf6a0, thd=0x5556853822c0) at /test/5.5_opt/sql/sql_parse.cc:5831
#19 mysql_parse (thd=0x5556853822c0, rawbuf=<optimized out>, length=10, parser_state=0x14c5e40bf6a0) at /test/5.5_opt/sql/sql_parse.cc:5755
#20 0x00005556828ee14f in dispatch_command (command=<optimized out>, thd=0x5556853822c0, packet=<optimized out>, packet_length=<optimized out>) at /test/5.5_opt/sql/sql_class.h:758
#21 0x00005556828eec1f in do_command (thd=<optimized out>) at /test/5.5_opt/sql/sql_parse.cc:776
#22 0x0000555682988ec2 in do_handle_one_connection (thd_arg=thd_arg@entry=0x5556853822c0) at /test/5.5_opt/sql/sql_connect.cc:870
#23 0x0000555682988f8c in handle_one_connection (arg=0x5556853822c0) at /test/5.5_opt/sql/sql_connect.cc:789
#24 0x000014c5f4f0d609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#25 0x000014c5f4b01293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Generated at Thu Feb 08 09:56:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.