[MDEV-20325] Assertion `outer_context || !*from_field || *from_field == not_found_field' failed in Item_field::fix_outer_field | `!derived->is_excluded()' failed in TABLE_LIST::set_check_materialized | SIGEGV in st_select_lex::mark_as_dependent (optimized builds) Created: 2019-08-12  Updated: 2022-07-09  Resolved: 2022-01-11

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7
Fix Version/s: 10.2.42, 10.3.33, 10.4.23, 10.5.14, 10.6.6, 10.7.2

Type: Bug Priority: Critical
Reporter: Alice Sherepa Assignee: Dmitry Shulga
Resolution: Fixed Votes: 2
Labels: None

Issue Links:
Relates
relates to MDEV-29071 SIGSEGV's in st_select_lex::mark_as_d... Confirmed
relates to MDEV-25631 Crash executing query with VIEW, aggr... Closed

 Description   

create table t1 (a int) ;
 
delimiter $$;
create procedure t1_data()
begin
  declare i int default 1;
  while i < 1000 do insert into t1 values (i); set i = i + 1;
  end while;
end$$
delimiter ;$$
 
call t1_data();
create procedure sp() select * from (select a from t1) tb;
call sp();
set optimizer_switch='derived_merge=off';
call sp();

or the same with prepared statement:

prepare stmt from "select * from (select a from t1) tb;";
execute stmt;
set optimizer_switch='derived_merge=off';
execute stmt;

#5  0x00007f95c8c9402a in __GI_abort () at abort.c:89
#6  0x00007f95c8c8abd7 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0xe1d190 "outer_context || !*from_field || *from_field == not_found_field", file=file@entry=0xe1cb80 "/5.5/sql/item.cc", line=line@entry=4761, function=function@entry=0xe1ebc0 <Item_field::fix_outer_field(THD*, Field**, Item**)::__PRETTY_FUNCTION__> "int Item_field::fix_outer_field(THD*, Field**, Item**)") at assert.c:92
#7  0x00007f95c8c8ac82 in __GI___assert_fail (assertion=0xe1d190 "outer_context || !*from_field || *from_field == not_found_field", file=0xe1cb80 "/5.5/sql/item.cc", line=4761, function=0xe1ebc0 <Item_field::fix_outer_field(THD*, Field**, Item**)::__PRETTY_FUNCTION__> "int Item_field::fix_outer_field(THD*, Field**, Item**)") at assert.c:101
#8  0x00000000007f820e in Item_field::fix_outer_field (this=0x7f95c3940e68, thd=0x7f95c53e6060, from_field=0x7f95ca50b5d8, reference=0x7f95c393dfa0) at /5.5/sql/item.cc:4760
#9  0x00000000007f9520 in Item_field::fix_fields (this=0x7f95c3940e68, thd=0x7f95c53e6060, reference=0x7f95c393dfa0) at /5.5/sql/item.cc:5168
#10 0x0000000000801463 in Item_direct_view_ref::fix_fields (this=0x7f95c3939650, thd=0x7f95c53e6060, reference=0x7f95c3940e30) at /5.5/sql/item.cc:7933
#11 0x00000000005b71d5 in setup_fields (thd=0x7f95c53e6060, ref_pointer_array=0x7f95c3939760, fields=..., mark_used_columns=MARK_COLUMNS_READ, sum_func_list=0x7f95c3945510, pre_fix=0x7f95c3940280, allow_sum_func=true) at /5.5/sql/sql_base.cc:8216
#12 0x0000000000642651 in JOIN::prepare (this=0x7f95c39451c0, rref_pointer_array=0x7f95c39403f0, tables_init=0x7f95c3939078, wild_num=0, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7f95c3940150, unit_arg=0x7f95c393fa68) at /5.5/sql/sql_select.cc:733
#13 0x000000000064b7db in mysql_select (thd=0x7f95c53e6060, rref_pointer_array=0x7f95c39403f0, tables=0x7f95c3939078, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147749632, result=0x7f95c39451a0, unit=0x7f95c393fa68, select_lex=0x7f95c3940150) at /5.5/sql/sql_select.cc:3113
#14 0x000000000064176d in handle_select (thd=0x7f95c53e6060, lex=0x7f95c393f9b8, result=0x7f95c39451a0, setup_tables_done_option=0) at /5.5/sql/sql_select.cc:324
#15 0x0000000000617562 in execute_sqlcom_select (thd=0x7f95c53e6060, all_tables=0x7f95c3939078) at /5.5/sql/sql_parse.cc:4684
#16 0x000000000061001c in mysql_execute_command (thd=0x7f95c53e6060) at /5.5/sql/sql_parse.cc:2222
#17 0x000000000091e978 in sp_instr_stmt::exec_core (this=0x7f95c393dd40, thd=0x7f95c53e6060, nextp=0x7f95ca50c89c) at /5.5/sql/sp_head.cc:3221
#18 0x000000000091e0e0 in sp_lex_keeper::reset_lex_and_exec_core (this=0x7f95c393dd80, thd=0x7f95c53e6060, nextp=0x7f95ca50c89c, open_tables=false, instr=0x7f95c393dd40) at /5.5/sql/sp_head.cc:2999
#19 0x000000000091e684 in sp_instr_stmt::execute (this=0x7f95c393dd40, thd=0x7f95c53e6060, nextp=0x7f95ca50c89c) at /5.5/sql/sp_head.cc:3145
#20 0x000000000091a021 in sp_head::execute (this=0x7f95c393f078, thd=0x7f95c53e6060, merge_da_on_success=true) at /5.5/sql/sp_head.cc:1432
#21 0x000000000091bfab in sp_head::execute_procedure (this=0x7f95c393f078, thd=0x7f95c53e6060, args=0x7f95c53ea028) at /5.5/sql/sp_head.cc:2198
#22 0x00000000006158bc in mysql_execute_command (thd=0x7f95c53e6060) at /5.5/sql/sql_parse.cc:4121
#23 0x000000000061a47c in mysql_parse (thd=0x7f95c53e6060, rawbuf=0x7f95c38c4078 "call sp()", length=9, parser_state=0x7f95ca50d660) at /5.5/sql/sql_parse.cc:5929
#24 0x000000000060d3c4 in dispatch_command (command=COM_QUERY, thd=0x7f95c53e6060, packet=0x7f95c46f4061 "call sp()", packet_length=9) at /5.5/sql/sql_parse.cc:1067
#25 0x000000000060c529 in do_command (thd=0x7f95c53e6060) at /5.5/sql/sql_parse.cc:793
#26 0x0000000000723ec4 in do_handle_one_connection (thd_arg=0x7f95c53e6060) at /5.5/sql/sql_connect.cc:1268
#27 0x0000000000723c2d in handle_one_connection (arg=0x7f95c53e6060) at /5.5/sql/sql_connect.cc:1184
#28 0x0000000000cc6db9 in pfs_spawn_thread (arg=0x7f95c469c300) at /5.5/storage/perfschema/pfs.cc:1015
#29 0x00007f95c98bd6ba in start_thread (arg=0x7f95ca50e700) at pthread_create.c:333
#30 0x00007f95c8d6441d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

10.2 3b234104ae227556f06c

#4  0x00007f56dc2af428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#5  0x00007f56dc2b102a in __GI_abort () at abort.c:89
#6  0x00007f56dc2a7bd7 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x562a4f36f49b "!derived->is_excluded()", file=file@entry=0x562a4f36dfa8 "/10.2/sql/table.cc", line=line@entry=5641, function=function@entry=0x562a4f370b60 <TABLE_LIST::set_check_materialized()::__PRETTY_FUNCTION__> "void TABLE_LIST::set_check_materialized()") at assert.c:92
#7  0x00007f56dc2a7c82 in __GI___assert_fail (assertion=0x562a4f36f49b "!derived->is_excluded()", file=0x562a4f36dfa8 "/10.2/sql/table.cc", line=5641, function=0x562a4f370b60 <TABLE_LIST::set_check_materialized()::__PRETTY_FUNCTION__> "void TABLE_LIST::set_check_materialized()") at assert.c:101
#8  0x0000562a4e96fc2f in TABLE_LIST::set_check_materialized (this=0x7f5680043c40) at /10.2/sql/table.cc:5641
#9  0x0000562a4e7fe059 in TABLE_LIST::set_materialized_derived (this=0x7f5680043c40) at /10.2/sql/table.h:2362
#10 0x0000562a4e975b37 in TABLE_LIST::init_derived (this=0x7f5680043c40, thd=0x7f5680000b00, init_view=true) at /10.2/sql/table.cc:8119
#11 0x0000562a4e830f7b in mysql_derived_init (thd=0x7f5680000b00, lex=0x7f56800425d8, derived=0x7f5680043c40) at /10.2/sql/sql_derived.cc:557
#12 0x0000562a4e830224 in mysql_handle_derived (lex=0x7f56800425d8, phases=1) at /10.2/sql/sql_derived.cc:122
#13 0x0000562a4e7f3931 in open_and_lock_tables (thd=0x7f5680000b00, options=..., tables=0x7f5680043c40, derived=true, flags=0, prelocking_strategy=0x7f56d4121060) at /10.2/sql/sql_base.cc:4827
#14 0x0000562a4e7e64e8 in open_and_lock_tables (thd=0x7f5680000b00, tables=0x7f5680043c40, derived=true, flags=0) at /10.2/sql/sql_base.h:509
#15 0x0000562a4e86a513 in execute_sqlcom_select (thd=0x7f5680000b00, all_tables=0x7f5680043c40) at /10.2/sql/sql_parse.cc:6147
#16 0x0000562a4e8613c0 in mysql_execute_command (thd=0x7f5680000b00) at /10.2/sql/sql_parse.cc:3533
#17 0x0000562a4ec6415e in sp_instr_stmt::exec_core (this=0x7f5680044268, thd=0x7f5680000b00, nextp=0x7f56d4122064) at /10.2/sql/sp_head.cc:3248
#18 0x0000562a4ec637cf in sp_lex_keeper::reset_lex_and_exec_core (this=0x7f56800442a8, thd=0x7f5680000b00, nextp=0x7f56d4122064, open_tables=false, instr=0x7f5680044268) at /10.2/sql/sp_head.cc:3011
#19 0x0000562a4ec63e07 in sp_instr_stmt::execute (this=0x7f5680044268, thd=0x7f5680000b00, nextp=0x7f56d4122064) at /10.2/sql/sp_head.cc:3164
#20 0x0000562a4ec5efca in sp_head::execute (this=0x7f5680040538, thd=0x7f5680000b00, merge_da_on_success=true) at /10.2/sql/sp_head.cc:1329
#21 0x0000562a4ec61063 in sp_head::execute_procedure (this=0x7f5680040538, thd=0x7f5680000b00, args=0x7f5680005440) at /10.2/sql/sp_head.cc:2118
#22 0x0000562a4e85f92d in do_execute_sp (thd=0x7f5680000b00, sp=0x7f5680040538) at /10.2/sql/sql_parse.cc:2955
#23 0x0000562a4e868090 in mysql_execute_command (thd=0x7f5680000b00) at /10.2/sql/sql_parse.cc:5573
#24 0x0000562a4e86e85b in mysql_parse (thd=0x7f5680000b00, rawbuf=0x7f5680012468 "call sp()", length=9, parser_state=0x7f56d4123080, is_com_multi=false, is_next_command=false) at /10.2/sql/sql_parse.cc:7760
#25 0x0000562a4e85cb24 in dispatch_command (command=COM_QUERY, thd=0x7f5680000b00, packet=0x7f5680096021 "call sp()", packet_length=9, is_com_multi=false, is_next_command=false) at /10.2/sql/sql_parse.cc:1832
#26 0x0000562a4e85b438 in do_command (thd=0x7f5680000b00) at /10.2/sql/sql_parse.cc:1386
#27 0x0000562a4e9b0b8d in do_handle_one_connection (connect=0x562a51cd6420) at /10.2/sql/sql_connect.cc:1336
#28 0x0000562a4e9b08f8 in handle_one_connection (arg=0x562a51cd6420) at /10.2/sql/sql_connect.cc:1241
#29 0x0000562a4f1db886 in pfs_spawn_thread (arg=0x562a51ce1210) at /10.2/storage/perfschema/pfs.cc:1862
#30 0x00007f56dceec6ba in start_thread (arg=0x7f56d4124700) at pthread_create.c:333
#31 0x00007f56dc38141d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

10.2.26

190812 11:39:33 [ERROR] mysqld got signal 11 ;
 
sql/sql_lex.cc:2497(st_select_lex::mark_as_dependent(THD*, st_select_lex*, Item*))[0x55dc63e8e067]
sql/item.cc:4677(mark_as_dependent(THD*, st_select_lex*, st_select_lex*, Item_ident*, Item_ident*))[0x55dc64035608]
sql/item.cc:5363(Item_field::fix_outer_field(THD*, Field**, Item**))[0x55dc6404609e]
sql/item.cc:5555(Item_field::fix_fields(THD*, Item**))[0x55dc640466b7]
sql/item.cc:8584(Item_direct_view_ref::fix_fields(THD*, Item**))[0x55dc64042ce7]
sql/sql_base.cc:7203(setup_fields(THD*, Bounds_checked_array<Item*>, List<Item>&, enum_mark_columns, List<Item>*, List<Item>*, bool))[0x55dc63e5dd2b]
sql/sql_select.cc:815(JOIN::prepare(TABLE_LIST*, unsigned int, Item*, unsigned int, st_order*, bool, st_order*, Item*, st_order*, st_select_lex*, st_select_lex_unit*))[0x55dc63edb6fd]
sql/sql_select.cc:3800(mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*))[0x55dc63eecce6]
sql/sql_select.cc:377(handle_select(THD*, LEX*, select_result*, unsigned long))[0x55dc63eede04]
sql/sql_parse.cc:6227(execute_sqlcom_select(THD*, TABLE_LIST*))[0x55dc63ddddea]
sql/sql_parse.cc:3533(mysql_execute_command(THD*))[0x55dc63e9c84d]
sql/sp_head.cc:3250(sp_instr_stmt::exec_core(THD*, unsigned int*))[0x55dc6412868e]
sql/sp_head.cc:3011(sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*))[0x55dc6412e3c9]
sql/sp_head.cc:3165(sp_instr_stmt::execute(THD*, unsigned int*))[0x55dc6412e905]
sql/sp_head.cc:1331(sp_head::execute(THD*, bool))[0x55dc6412b76a]
sql/sp_head.cc:2118(sp_head::execute_procedure(THD*, List<Item>*))[0x55dc6412cb8e]
sql/sql_parse.cc:2958(do_execute_sp(THD*, sp_head*))[0x55dc63e93f67]
sql/sql_parse.cc:5573(mysql_execute_command(THD*))[0x55dc63e9ecc4]
sql/sql_parse.cc:7760(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x55dc63ea12ea]
sql/sql_parse.cc:1832(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x55dc63ea37ee]
sql/sql_parse.cc:1388(do_command(THD*))[0x55dc63ea3ddd]
sql/sql_connect.cc:1336(do_handle_one_connection(CONNECT*))[0x55dc63f65f11]
sql/sql_connect.cc:1243(handle_one_connection)[0x55dc63f65fe4]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7f42e63166ba]
x86_64/clone.S:111(clone)[0x7f42e59c141d]
 
Query (0x7f427c059ab0): select * from (select a from t1) tb



 Comments   
Comment by Roel Van de Paar [ 2020-06-12 ]

USE test;
CREATE TABLE t AS SELECT {d'2001-01-01'},{d'2001-01-01 10:10:10'};
PREPARE p FROM "SELECT p.* FROM (SELECT t.* FROM t AS t) AS p";
EXECUTE p;
SET @@SESSION.OPTIMIZER_SWITCH="derived_merge=OFF";
EXECUTE p;

Leads to:

10.5.4 07d1c8567cbfe94398a9857c47fb9919cad42651

Core was generated by `/test/MD120620-mariadb-10.5.4-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:57
[Current thread is 1 (Thread 0x1493b8d27700 (LWP 1619083))]
(gdb) bt
(gdb) (gdb) #0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=11) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x000055a81e3a29e7 in my_write_core (sig=sig@entry=11) at /test/10.5_opt/mysys/stacktrace.c:518
#2  0x000055a81dd6ddaa in handle_fatal_signal (sig=11) at /test/10.5_opt/sql/signal_handler.cc:330
#3  <signal handler called>
#4  0x000055a81db54bd3 in st_select_lex::mark_as_dependent (this=this@entry=0x149392cfa240, thd=thd@entry=0x149392c12018, last=last@entry=0x149392cfa240, dependency=0x149392cfc6b0) at /test/10.5_opt/sql/sql_lex.cc:3335
#5  0x000055a81dd832b1 in mark_as_dependent (thd=0x149392c12018, last=0x149392cfa240, current=0x149392cfa240, resolved_item=0x149392cfc6b0, mark_item=<optimized out>) at /test/10.5_opt/sql/item.cc:5033
#6  0x000055a81dd93a66 in Item_field::fix_outer_field (this=this@entry=0x149392cfc6b0, thd=thd@entry=0x149392c12018, from_field=from_field@entry=0x1493b8d24f80, reference=reference@entry=0x149392cfca48) at /test/10.5_opt/sql/item.cc:5714
#7  0x000055a81dd947e3 in Item_field::fix_fields (this=0x149392cfc6b0, thd=0x149392c12018, reference=<optimized out>) at /test/10.5_opt/sql/item.cc:5916
#8  0x000055a81dd953cc in Item::fix_fields_if_needed (ref=0x149392cfca48, thd=0x149392c12018, this=0x149392cfc6b0) at /test/10.5_opt/sql/item.h:978
#9  Item_direct_view_ref::fix_fields (this=0x149392cfcaa0, thd=0x149392c12018, reference=0x149392cfa238) at /test/10.5_opt/sql/item.cc:8934
#10 0x000055a81db19fe9 in Item::fix_fields_if_needed (ref=0x149392cfa238, thd=0x149392c12018, this=0x149392cfcaa0) at /test/10.5_opt/sql/item.h:978
#11 Item::fix_fields_if_needed_for_scalar (ref=0x149392cfa238, thd=0x149392c12018, this=0x149392cfcaa0) at /test/10.5_opt/sql/item.h:982
#12 setup_fields (thd=0x149392c12018, ref_pointer_array=<optimized out>, fields=<optimized out>, column_usage=column_usage@entry=MARK_COLUMNS_READ, sum_func_list=sum_func_list@entry=0x149392c474a0, pre_fix=0x149392cf9de0, allow_sum_func=true) at /test/10.5_opt/sql/sql_base.cc:7569
#13 0x000055a81dbc4d37 in JOIN::prepare (this=this@entry=0x149392c47178, tables_init=tables_init@entry=0x149392cfb788, conds_init=conds_init@entry=0x0, og_num=og_num@entry=0, order_init=order_init@entry=0x0, skip_order_by=skip_order_by@entry=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x149392cf9c78, unit_arg=0x149392cf8100) at /test/10.5_opt/sql/sql_select.cc:1247
#14 0x000055a81dbd4b90 in mysql_select (thd=thd@entry=0x149392c12018, tables=0x149392cfb788, fields=@0x149392cf9dc8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x149392cfa230, last = 0x149392cfcd60, elements = 2}, <No data fields>}, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201171004160, result=0x149392cfc688, unit=0x149392cf8100, select_lex=0x149392cf9c78) at /test/10.5_opt/sql/sql_select.cc:4614
#15 0x000055a81dbd4e31 in handle_select (thd=thd@entry=0x149392c12018, lex=lex@entry=0x149392cf8038, result=result@entry=0x149392cfc688, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.5_opt/sql/sql_select.cc:417
#16 0x000055a81db7b7e1 in execute_sqlcom_select (thd=thd@entry=0x149392c12018, all_tables=0x149392cfb788) at /test/10.5_opt/sql/sql_parse.cc:6208
#17 0x000055a81db77f11 in mysql_execute_command (thd=0x149392c12018) at /test/10.5_opt/sql/sql_parse.cc:3939
#18 0x000055a81db94f75 in Prepared_statement::execute (this=this@entry=0x149392c54c18, expanded_query=expanded_query@entry=0x1493b8d25e20, open_cursor=open_cursor@entry=false) at /test/10.5_opt/sql/sql_prepare.cc:4786
#19 0x000055a81db95072 in Prepared_statement::execute_loop (this=0x149392c54c18, expanded_query=0x1493b8d25e20, open_cursor=<optimized out>, packet=<optimized out>, packet_end=<optimized out>) at /test/10.5_opt/sql/sql_prepare.cc:4275
#20 0x000055a81db95363 in mysql_sql_stmt_execute (thd=thd@entry=0x149392c12018) at /test/10.5_opt/sql/sql_prepare.cc:3387
#21 0x000055a81db7878f in mysql_execute_command (thd=thd@entry=0x149392c12018) at /test/10.5_opt/sql/sql_parse.cc:3955
#22 0x000055a81db7e8fc in mysql_parse (thd=0x149392c12018, rawbuf=<optimized out>, length=9, parser_state=0x1493b8d26430, is_com_multi=<optimized out>, is_next_command=<optimized out>) at /test/10.5_opt/sql/sql_parse.cc:7992
#23 0x000055a81db73be5 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x149392c12018, packet=packet@entry=0x149392c3a019 "EXECUTE p", packet_length=packet_length@entry=9, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_opt/sql/sql_parse.cc:1874
#24 0x000055a81db71fd4 in do_command (thd=0x149392c12018) at /test/10.5_opt/sql/sql_parse.cc:1355
#25 0x000055a81dc67681 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x1493b5c33958, put_in_cache=put_in_cache@entry=true) at /test/10.5_opt/sql/sql_connect.cc:1411
#26 0x000055a81dc679e4 in handle_one_connection (arg=arg@entry=0x1493b5c33958) at /test/10.5_opt/sql/sql_connect.cc:1313
#27 0x000055a81dfd540a in pfs_spawn_thread (arg=0x1493b5c4e818) at /test/10.5_opt/storage/perfschema/pfs.cc:2201
#28 0x00001493b7ca06db in start_thread (arg=0x1493b8d27700) at pthread_create.c:463
#29 0x00001493b709e88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.1.46 (dbg), 10.1.46 (opt), 10.2.33 (dbg), 10.2.33 (opt), 10.3.24 (dbg), 10.3.24 (opt), 10.4.14 (dbg), 10.4.14 (opt), 10.5.4 (dbg), 10.5.4 (opt)

Bug confirmed not present in:
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.47 (dbg), 5.6.47 (opt), 5.7.29 (dbg), 5.7.29 (opt), 8.0.19 (dbg), 8.0.19 (opt)

Comment by Roel Van de Paar [ 2020-06-12 ]

10.5 Behaviour may be new/different (or have changed across all releases); it produces SIGSEGV on both opt and dbg builds.

Comment by Roel Van de Paar [ 2020-10-12 ]

Another one to test with (similar to secondary testcase in OP):

USE test;
CREATE TABLE t (a INT PRIMARY KEY);
PREPARE s FROM "SELECT a.* FROM (SELECT tt.* FROM t tt) AS a";
EXECUTE s;
SET SESSION optimizer_switch="derived_merge=OFF";
EXECUTE s;

Leads to:

10.5.6 2bac9782aa81ad386beaf00eb126ccf2d15031a1 (Debug)

mysqld: /test/10.5_dbg/sql/table.cc:6508: void TABLE_LIST::set_check_materialized(): Assertion `!derived->is_excluded()' failed.

10.5.6 2bac9782aa81ad386beaf00eb126ccf2d15031a1 (Debug)

Core was generated by `/test/MD150920-mariadb-10.5.6-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:57
[Current thread is 1 (Thread 0x14979ddb5700 (LWP 593706))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x00005614f505d85a in my_write_core (sig=sig@entry=6) at /test/10.5_dbg/mysys/stacktrace.c:424
#2  0x00005614f48243a9 in handle_fatal_signal (sig=6) at /test/10.5_dbg/sql/signal_handler.cc:330
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#5  0x000014979c04b8b1 in __GI_abort () at abort.c:79
#6  0x000014979c03b42a in __assert_fail_base (fmt=0x14979c1c2a38 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x5614f51ffc62 "!derived->is_excluded()", file=file@entry=0x5614f51ff889 "/test/10.5_dbg/sql/table.cc", line=line@entry=6508, function=function@entry=0x5614f52032c0 <TABLE_LIST::set_check_materialized()::__PRETTY_FUNCTION__> "void TABLE_LIST::set_check_materialized()") at assert.c:92
#7  0x000014979c03b4a2 in __GI___assert_fail (assertion=assertion@entry=0x5614f51ffc62 "!derived->is_excluded()", file=file@entry=0x5614f51ff889 "/test/10.5_dbg/sql/table.cc", line=line@entry=6508, function=function@entry=0x5614f52032c0 <TABLE_LIST::set_check_materialized()::__PRETTY_FUNCTION__> "void TABLE_LIST::set_check_materialized()") at assert.c:101
#8  0x00005614f467d057 in TABLE_LIST::set_check_materialized (this=this@entry=0x1497798d07f8) at /test/10.5_dbg/sql/table.cc:6508
#9  0x00005614f4689640 in TABLE_LIST::set_materialized_derived (this=0x1497798d07f8) at /test/10.5_dbg/sql/table.h:2749
#10 TABLE_LIST::init_derived (this=this@entry=0x1497798d07f8, thd=thd@entry=0x149779815088, init_view=init_view@entry=true) at /test/10.5_dbg/sql/table.cc:9226
#11 0x00005614f45234e0 in mysql_derived_init (thd=0x149779815088, lex=<optimized out>, derived=0x1497798d07f8) at /test/10.5_dbg/sql/sql_derived.cc:591
#12 0x00005614f4524276 in mysql_handle_derived (lex=0x1497798cd0a8, phases=phases@entry=1) at /test/10.5_dbg/sql/sql_derived.cc:126
#13 0x00005614f44f305c in open_and_lock_tables (thd=thd@entry=0x149779815088, options=<optimized out>, tables=<optimized out>, tables@entry=0x1497798d07f8, derived=derived@entry=true, flags=flags@entry=0, prelocking_strategy=prelocking_strategy@entry=0x14979ddb2ec0) at /test/10.5_dbg/sql/sql_base.cc:5178
#14 0x00005614f4577f07 in open_and_lock_tables (flags=0, derived=true, tables=0x1497798d07f8, thd=0x149779815088) at /test/10.5_dbg/sql/sql_base.h:509
#15 execute_sqlcom_select (thd=thd@entry=0x149779815088, all_tables=0x1497798d07f8) at /test/10.5_dbg/sql/sql_parse.cc:6131
#16 0x00005614f457141c in mysql_execute_command (thd=0x149779815088) at /test/10.5_dbg/sql/sql_parse.cc:3932
#17 0x00005614f4596e15 in Prepared_statement::execute (this=this@entry=0x149779851188, expanded_query=expanded_query@entry=0x14979ddb3ab0, open_cursor=open_cursor@entry=false) at /test/10.5_dbg/sql/sql_prepare.cc:4736
#18 0x00005614f4597162 in Prepared_statement::execute_loop (this=this@entry=0x149779851188, expanded_query=expanded_query@entry=0x14979ddb3ab0, open_cursor=open_cursor@entry=false, packet=packet@entry=0x0, packet_end=packet_end@entry=0x0) at /test/10.5_dbg/sql/sql_prepare.cc:4225
#19 0x00005614f4597751 in mysql_sql_stmt_execute (thd=thd@entry=0x149779815088) at /test/10.5_dbg/sql/sql_prepare.cc:3336
#20 0x00005614f457147c in mysql_execute_command (thd=thd@entry=0x149779815088) at /test/10.5_dbg/sql/sql_parse.cc:3948
#21 0x00005614f457e324 in mysql_parse (thd=thd@entry=0x149779815088, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14979ddb4350, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_dbg/sql/sql_parse.cc:7994
#22 0x00005614f456ad54 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x149779815088, packet=packet@entry=0x149779867089 "EXECUTE s", packet_length=packet_length@entry=9, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_dbg/sql/sql_parse.cc:1867
#23 0x00005614f456953e in do_command (thd=0x149779815088) at /test/10.5_dbg/sql/sql_parse.cc:1348
#24 0x00005614f46c8893 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x14977ccd42c8, put_in_cache=put_in_cache@entry=true) at /test/10.5_dbg/sql/sql_connect.cc:1410
#25 0x00005614f46c8fb7 in handle_one_connection (arg=arg@entry=0x14977ccd42c8) at /test/10.5_dbg/sql/sql_connect.cc:1312
#26 0x00005614f4b335c2 in pfs_spawn_thread (arg=0x14979ac46508) at /test/10.5_dbg/storage/perfschema/pfs.cc:2201
#27 0x000014979cd2e6db in start_thread (arg=0x14979ddb5700) at pthread_create.c:463
#28 0x000014979c12ca3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.1.47 (dbg), 10.1.47 (opt), 10.2.34 (dbg), 10.2.34 (opt), 10.3.25 (dbg), 10.3.25 (opt), 10.4.15 (dbg), 10.4.15 (opt), 10.5.6 (dbg), 10.5.6 (opt), 10.6.0 (dbg), 10.6.0 (opt)

Bug confirmed not present in:
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.49 (dbg), 5.6.49 (opt), 5.7.31 (dbg), 5.7.31 (opt), 8.0.21 (dbg), 8.0.21 (opt)

Comment by Roel Van de Paar [ 2021-07-13 ]

10.7.0 57f14eab20ae2733eb341f3d293515a10a40bc48 (Debug)

mysqld: /test/10.7_dbg/sql/table.cc:6621: void TABLE_LIST::set_check_materialized(): Assertion `!derived->is_excluded()' failed.

10.7.0 57f14eab20ae2733eb341f3d293515a10a40bc48 (Debug)

Core was generated by `/test/MD090721-mariadb-10.7.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 0x14d82408c700 (LWP 1739915))]
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x000014d826648859 in __GI_abort () at abort.c:79
#2  0x000014d826648729 in __assert_fail_base (fmt=0x14d8267de588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x562350851757 "!derived->is_excluded()", file=0x562350851381 "/test/10.7_dbg/sql/table.cc", line=6621, function=<optimized out>) at assert.c:92
#3  0x000014d826659f36 in __GI___assert_fail (assertion=assertion@entry=0x562350851757 "!derived->is_excluded()", file=file@entry=0x562350851381 "/test/10.7_dbg/sql/table.cc", line=line@entry=6621, function=function@entry=0x562350852f08 "void TABLE_LIST::set_check_materialized()") at assert.c:101
#4  0x000056234fca0b9e in TABLE_LIST::set_check_materialized (this=this@entry=0x14d7d402c8f8) at /test/10.7_dbg/sql/sql_lex.h:992
#5  0x000056234fcad54f in TABLE_LIST::set_materialized_derived (this=0x14d7d402c8f8) at /test/10.7_dbg/sql/table.h:2800
#6  TABLE_LIST::init_derived (this=this@entry=0x14d7d402c8f8, thd=thd@entry=0x14d7d4000db8, init_view=init_view@entry=true) at /test/10.7_dbg/sql/table.cc:9338
#7  0x000056234fb2bbbd in mysql_derived_init (thd=0x14d7d4000db8, lex=<optimized out>, derived=0x14d7d402c8f8) at /test/10.7_dbg/sql/sql_derived.cc:582
#8  0x000056234fb2c8ba in mysql_handle_derived (lex=0x14d7d40291c8, phases=phases@entry=1) at /test/10.7_dbg/sql/sql_derived.cc:123
#9  0x000056234faf9c10 in open_and_lock_tables (thd=thd@entry=0x14d7d4000db8, options=<optimized out>, tables=<optimized out>, tables@entry=0x14d7d402c8f8, derived=derived@entry=true, flags=flags@entry=0, prelocking_strategy=prelocking_strategy@entry=0x14d82408a240) at /test/10.7_dbg/sql/sql_base.cc:5270
#10 0x000056234fb7c293 in open_and_lock_tables (flags=0, derived=true, tables=0x14d7d402c8f8, thd=0x14d7d4000db8) at /test/10.7_dbg/sql/sql_base.h:509
#11 execute_sqlcom_select (thd=thd@entry=0x14d7d4000db8, all_tables=0x14d7d402c8f8) at /test/10.7_dbg/sql/sql_parse.cc:6173
#12 0x000056234fb89592 in mysql_execute_command (thd=0x14d7d4000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=true) at /test/10.7_dbg/sql/sql_parse.cc:3947
#13 0x000056234fba2ebe in Prepared_statement::execute (this=this@entry=0x14d7d40244e8, expanded_query=expanded_query@entry=0x14d82408ada0, open_cursor=open_cursor@entry=false) at /test/10.7_dbg/sql/sql_prepare.cc:5162
#14 0x000056234fba3233 in Prepared_statement::execute_loop (this=this@entry=0x14d7d40244e8, expanded_query=expanded_query@entry=0x14d82408ada0, open_cursor=open_cursor@entry=false, packet=packet@entry=0x0, packet_end=packet_end@entry=0x0) at /test/10.7_dbg/sql/sql_prepare.cc:4609
#15 0x000056234fba3763 in mysql_sql_stmt_execute (thd=thd@entry=0x14d7d4000db8) at /test/10.7_dbg/sql/sql_prepare.cc:3669
#16 0x000056234fb895ef in mysql_execute_command (thd=thd@entry=0x14d7d4000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.7_dbg/sql/sql_parse.cc:3963
#17 0x000056234fb75b27 in mysql_parse (thd=thd@entry=0x14d7d4000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x14d82408b400) at /test/10.7_dbg/sql/sql_parse.cc:8026
#18 0x000056234fb84692 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x14d7d4000db8, packet=packet@entry=0x14d7d400b769 "EXECUTE s", packet_length=packet_length@entry=9, blocking=blocking@entry=true) at /test/10.7_dbg/sql/sql_class.h:1340
#19 0x000056234fb87aaa in do_command (thd=0x14d7d4000db8, blocking=blocking@entry=true) at /test/10.7_dbg/sql/sql_parse.cc:1404
#20 0x000056234fcec09a in do_handle_one_connection (connect=<optimized out>, connect@entry=0x562352374588, put_in_cache=put_in_cache@entry=true) at /test/10.7_dbg/sql/sql_connect.cc:1410
#21 0x000056234fcec69f in handle_one_connection (arg=arg@entry=0x562352374588) at /test/10.7_dbg/sql/sql_connect.cc:1312
#22 0x000056235019b400 in pfs_spawn_thread (arg=0x56235225cf18) at /test/10.7_dbg/storage/perfschema/pfs.cc:2201
#23 0x000014d826b57609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#24 0x000014d826745293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Comment by Roel Van de Paar [ 2021-11-13 ]

CREATE TABLE t0 (c INT KEY);
PREPARE s FROM 'SELECT * FROM (SELECT * FROM t0) AS d';
EXECUTE s;
SET SESSION optimizer_switch='derived_merge=OFF';
EXECUTE s;

Leads to:

10.8.0 bc57ff7cf79504a198d4752b4748340a4afd886c (Debug)

mysqld: /test/10.8_dbg/sql/table.cc:6659: void TABLE_LIST::set_check_materialized(): Assertion `!derived->is_excluded()' failed.

10.8.0 bc57ff7cf79504a198d4752b4748340a4afd886c (Debug)

Core was generated by `/test/MD121121-mariadb-10.8.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 0x1495bc11f700 (LWP 4006128))]
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00001495d21d9859 in __GI_abort () at abort.c:79
#2  0x00001495d21d9729 in __assert_fail_base (fmt=0x1495d236f588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x555fcba68c57 "!derived->is_excluded()", file=0x555fcba68881 "/test/10.8_dbg/sql/table.cc", line=6659, function=<optimized out>) at assert.c:92
#3  0x00001495d21eaf36 in __GI___assert_fail (assertion=assertion@entry=0x555fcba68c57 "!derived->is_excluded()", file=file@entry=0x555fcba68881 "/test/10.8_dbg/sql/table.cc", line=line@entry=6659, function=function@entry=0x555fcba6a420 "void TABLE_LIST::set_check_materialized()") at assert.c:101
#4  0x0000555fcaeaabac in TABLE_LIST::set_check_materialized (this=this@entry=0x149580028950) at /test/10.8_dbg/sql/sql_lex.h:991
#5  0x0000555fcaeb73eb in TABLE_LIST::set_materialized_derived (this=0x149580028950) at /test/10.8_dbg/sql/table.h:2801
#6  TABLE_LIST::init_derived (this=this@entry=0x149580028950, thd=thd@entry=0x149580000db8, init_view=init_view@entry=true) at /test/10.8_dbg/sql/table.cc:9389
#7  0x0000555fcad1f8f9 in mysql_derived_init (thd=0x149580000db8, lex=<optimized out>, derived=0x149580028950) at /test/10.8_dbg/sql/sql_derived.cc:582
#8  0x0000555fcad205f6 in mysql_handle_derived (lex=0x1495800251f8, phases=phases@entry=1) at /test/10.8_dbg/sql/sql_derived.cc:123
#9  0x0000555fcace7882 in open_and_lock_tables (thd=thd@entry=0x149580000db8, options=<optimized out>, tables=<optimized out>, tables@entry=0x149580028950, derived=derived@entry=true, flags=flags@entry=0, prelocking_strategy=prelocking_strategy@entry=0x1495bc11d200) at /test/10.8_dbg/sql/sql_base.cc:5280
#10 0x0000555fcad7065a in open_and_lock_tables (flags=0, derived=true, tables=0x149580028950, thd=0x149580000db8) at /test/10.8_dbg/sql/sql_base.h:509
#11 execute_sqlcom_select (thd=thd@entry=0x149580000db8, all_tables=0x149580028950) at /test/10.8_dbg/sql/sql_parse.cc:6174
#12 0x0000555fcad7d9e3 in mysql_execute_command (thd=0x149580000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=true) at /test/10.8_dbg/sql/sql_parse.cc:3944
#13 0x0000555fcadab230 in Prepared_statement::execute (this=this@entry=0x1495800239d8, expanded_query=expanded_query@entry=0x1495bc11dd80, open_cursor=open_cursor@entry=false) at /test/10.8_dbg/sql/sql_prepare.cc:5210
#14 0x0000555fcadab5a5 in Prepared_statement::execute_loop (this=this@entry=0x1495800239d8, expanded_query=expanded_query@entry=0x1495bc11dd80, open_cursor=open_cursor@entry=false, packet=packet@entry=0x0, packet_end=packet_end@entry=0x0) at /test/10.8_dbg/sql/sql_prepare.cc:4633
#15 0x0000555fcadabad5 in mysql_sql_stmt_execute (thd=thd@entry=0x149580000db8) at /test/10.8_dbg/sql/sql_prepare.cc:3684
#16 0x0000555fcad7da40 in mysql_execute_command (thd=thd@entry=0x149580000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.8_dbg/sql/sql_parse.cc:3960
#17 0x0000555fcad69cad in mysql_parse (thd=thd@entry=0x149580000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x1495bc11e400) at /test/10.8_dbg/sql/sql_parse.cc:8028
#18 0x0000555fcad78949 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x149580000db8, packet=packet@entry=0x14958000b879 "EXECUTE s", packet_length=packet_length@entry=9, blocking=blocking@entry=true) at /test/10.8_dbg/sql/sql_class.h:1360
#19 0x0000555fcad7bd83 in do_command (thd=0x149580000db8, blocking=blocking@entry=true) at /test/10.8_dbg/sql/sql_parse.cc:1402
#20 0x0000555fcaef5e2a in do_handle_one_connection (connect=<optimized out>, connect@entry=0x555fcdd63f38, put_in_cache=put_in_cache@entry=true) at /test/10.8_dbg/sql/sql_connect.cc:1418
#21 0x0000555fcaef642f in handle_one_connection (arg=arg@entry=0x555fcdd63f38) at /test/10.8_dbg/sql/sql_connect.cc:1312
#22 0x0000555fcb3764ce in pfs_spawn_thread (arg=0x555fcdc78568) at /test/10.8_dbg/storage/perfschema/pfs.cc:2201
#23 0x00001495d26e8609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#24 0x00001495d22d6293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.2.42 (dbg), 10.2.42 (opt), 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.0 (dbg), 10.8.0 (opt)

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

Comment by Oleksandr Byelkin [ 2022-01-10 ]

OK to push after changing in the commit description "derived tabble moved" to "derived table merged" (we usually use term merged)

Comment by Roel Van de Paar [ 2022-01-28 ]

Note to self (and anyone interested): test patch with these testcases also:

CREATE TABLE t (c INT,c2 INT);
SET optimizer_switch='derived_merge=off,derived_with_keys=off';
SET @save_optimizer_switch=@@optimizer_switch;
SET @@optimizer_switch=DEFAULT;
PREPARE stmt FROM 'SELECT A.* FROM (SELECT tt.* FROM t tt) A ';
EXECUTE stmt;
SET @@optimizer_switch=@save_optimizer_switch;
EXECUTE stmt;

SET @tmp_optimizer_switch=@@optimizer_switch;
SET optimizer_switch='derived_merge=off,derived_with_keys=off';
SET @save_optimizer_switch=@@optimizer_switch;
SET optimizer_switch=@tmp_optimizer_switch;
PREPARE stmt FROM "SELECT * FROM (SELECT * FROM JSON_TABLE (load_file (0),'$' COLUMNS (a FOR ORDINALITY)) AS t) AS sq";
EXECUTE stmt;
SET @@optimizer_switch=@save_optimizer_switch;
EXECUTE stmt;

Comment by Roel Van de Paar [ 2022-01-31 ]

Last two testcases still crash 10.8 @ 0c5d1342ae6b5ab3256848be7a83e5c3b1f21566 but not on 10.2.42 (build 29/1) anymore. Wait for upmerge.

Generated at Thu Feb 08 08:58:36 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.