Some pointers may be invalid and cause the dump to abort.
Query (0x7fe5f80130d8): SELECT EXISTS ( WITH x ( x ) AS ( SELECT 1 ) SELECT NULL WHERE ( 1 , 1 ) = ( SELECT 1 , ( ( x , 1.000000 ) , 1 ) IN ( SELECT 'x' , 'x' WHERE ( ( 'x' ) ) UNION SELECT 1 , x HAVING 1 != 1 ) FROM x ) )
create_tmp_field() returns NULL for Item_row, the "(1,1.000000)" .
This means, the temptable is created with 3 fields, not 4.
Then add_tmp_key() crashes when it tries to add an index on fields with indexes 1,2,and 3. (field with index 0 is subquery's result).
Sergei Petrunia
added a comment - - edited Execution eventually reaches
#0 Expression_cache_tmptable::init (this=0x7fff78093b10) at /home/psergey/dev-git2/10.4-fix1/sql/sql_expression_cache.cc:121
The list of items passed to create_tmp_table is:
(gdb) p dbug_print_item(items.elem(0))
$125 = 0x5555577d6c80 <dbug_item_print_buf> "<cache>(<in_optimizer>(((1,1.000000),1),<exists>(subquery#5)))"
(gdb) p dbug_print_item(items.elem(1))
$126 = 0x5555577d6c80 <dbug_item_print_buf> "(1,1.000000)"
(gdb) p dbug_print_item(items.elem(2))
$127 = 0x5555577d6c80 <dbug_item_print_buf> "1"
(gdb) p dbug_print_item(items.elem(3))
$128 = 0x5555577d6c80 <dbug_item_print_buf> "1"
(gdb) p items.elements
$129 = 4
create_tmp_field() returns NULL for Item_row , the "(1,1.000000)" .
This means, the temptable is created with 3 fields, not 4.
Then add_tmp_key() crashes when it tries to add an index on fields with indexes 1,2,and 3. (field with index 0 is subquery's result).
( x , 1.000000 ) is not a scalar here ... should this have produced an error on name resolution phase?
Sergei Petrunia
added a comment - - edited
( ( x , 1.000000 ) , 1 )
IN
( SELECT
'x' , 'x'
WHERE ( ( 'x' ) )
UNION
SELECT 1 , x
HAVING 1 != 1
)
( x , 1.000000 ) is not a scalar here ... should this have produced an error on name resolution phase?
ERROR 1241 (21000): Operand should contain 2 column(s)
Sergei Petrunia
added a comment - If I change the query in any way, e.g.
WHERE ( 'x' )
to WHERE 1 , I get the correct result:
ERROR 1241 (21000): Operand should contain 2 column(s)
#0 my_error (nr=1241, MyFlags=0) at /home/psergey/dev-git2/10.4-fix1/mysys/my_error.c:109
#1 0x00005555560fe14e in Item::check_cols (this=0x7fff74016498, c=2) at /home/psergey/dev-git2/10.4-fix1/sql/item.cc:953
#2 0x00005555561ca1ac in Item_in_subselect::create_row_in_to_exists_cond (this=0x7fff74017d00, join=0x7fff74019468, where_item=0x7fff74019968, having_item=0x7ff
#3 0x00005555561cb8ad in Item_in_subselect::create_in_to_exists_cond (this=0x7fff74017d00, join_arg=0x7fff74019468) at /home/psergey/dev-git2/10.4-fix1/sql/item
#4 0x0000555555f9aa11 in JOIN::choose_tableless_subquery_plan (this=0x7fff74019468) at /home/psergey/dev-git2/10.4-fix1/sql/opt_subselect.cc:6763
Sergei Petrunia
added a comment - - edited In the failing query:
JOIN::choose_tableless_subquery_plan() is called with select_number=2.
It reaches this point:
/*
Both group by queries and non-group by queries without aggregate
functions produce empty subquery result. There is no need to further
rewrite the subquery because it will not be executed at all.
*/
exec_const_cond= 0;
=> return FALSE;
It does NOT reach these lines:
if (in_subs->create_in_to_exists_cond(this) ||
in_subs->inject_in_to_exists_cond(this))
While for the subquery with WHERE 1 is does reach them, and we get here:
if (select_lex->ref_pointer_array[i]->
=> check_cols(left_expr->element_index(i)->cols()))
in here:
#0 my_error (nr=1241, MyFlags=0) at /home/psergey/dev-git2/10.4-fix1/mysys/my_error.c:109
#1 0x00005555560fe14e in Item::check_cols (this=0x7fff74016498, c=2) at /home/psergey/dev-git2/10.4-fix1/sql/item.cc:953
#2 0x00005555561ca1ac in Item_in_subselect::create_row_in_to_exists_cond (this=0x7fff74017d00, join=0x7fff74019468, where_item=0x7fff74019968, having_item=0x7ff
#3 0x00005555561cb8ad in Item_in_subselect::create_in_to_exists_cond (this=0x7fff74017d00, join_arg=0x7fff74019468) at /home/psergey/dev-git2/10.4-fix1/sql/item
#4 0x0000555555f9aa11 in JOIN::choose_tableless_subquery_plan (this=0x7fff74019468) at /home/psergey/dev-git2/10.4-fix1/sql/opt_subselect.cc:6763
Thanks! I repeated on 10.4-11.2:
Version: '10.4.32-MariaDB-debug-log'
231009 15:22:32 [ERROR] mysqld got signal 11 ;
Server version: 10.4.32-MariaDB-debug-log source revision: 0c7af6a2a19343cb9d4fedbd7165b8f73bc4cf96
sigaction.c:0(__restore_rt)[0x7f0ec71dc420]
sql/sql_bitmap.h:118(Bitmap<64u>::set_bit(unsigned int))[0x55de76e6efa3]
sql/table.cc:7984(TABLE::add_tmp_key(unsigned int, unsigned int, unsigned int (*)(unsigned char*), unsigned char*, bool))[0x55de77317475]
sql/sql_expression_cache.cc:143(Expression_cache_tmptable::init())[0x55de774e68c2]
sql/item.cc:8638(Item_cache_wrapper::init_on_demand())[0x55de77825e89]
sql/item.cc:8761(Item_cache_wrapper::check_cache())[0x55de77826cc0]
sql/item.cc:8824(Item_cache_wrapper::val_int())[0x55de778277e6]
sql/sql_type.cc:7106(Type_handler::Item_send_long(Item*, Protocol*, st_value*) const)[0x55de7755a330]
sql/sql_type.h:5192(Type_handler_long::Item_send(Item*, Protocol*, st_value*) const)[0x55de77574a3c]
sql/item.h:1045(Item::send(Protocol*, st_value*))[0x55de76d0c5e4]
sql/item.cc:8682(Item_cache_wrapper::send(Protocol*, st_value*))[0x55de77826484]
sql/protocol.cc:1038(Protocol::send_result_set_row(List<Item>*))[0x55de76cfdf63]
sql/sql_class.cc:3138(select_send::send_data(List<Item>&))[0x55de76eb0d83]
sql/sql_select.cc:22098(end_send(JOIN*, st_join_table*, bool))[0x55de7712150b]
sql/sql_select.cc:20363(do_select(JOIN*, Procedure*))[0x55de77115869]
sql/sql_select.cc:4605(JOIN::exec_inner())[0x55de770a3adc]
sql/sql_select.cc:4388(JOIN::exec())[0x55de770a110c]
sql/sql_select.cc:4828(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*))[0x55de770a52e8]
sql/sql_select.cc:442(handle_select(THD*, LEX*, select_result*, unsigned long))[0x55de77075de0]
sql/sql_parse.cc:6475(execute_sqlcom_select(THD*, TABLE_LIST*))[0x55de76fe1be4]
sql/sql_parse.cc:3978(mysql_execute_command(THD*))[0x55de76fcf35b]
sql/sql_parse.cc:8012(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x55de76feb0bf]
sql/sql_parse.cc:1860(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x55de76fc14e5]
sql/sql_parse.cc:1378(do_command(THD*))[0x55de76fbe010]
sql/sql_connect.cc:1420(do_handle_one_connection(CONNECT*))[0x55de773cbdeb]
sql/sql_connect.cc:1325(handle_one_connection)[0x55de773cb68f]
perfschema/pfs.cc:1871(pfs_spawn_thread)[0x55de78076274]
nptl/pthread_create.c:478(start_thread)[0x7f0ec71d0609]
Query (0x62b0000a1420): SELECT ( ( x , 1 ) , 1 ) IN ( SELECT 'x' , 'x' WHERE 0 UNION SELECT 1 , x HAVING 0) FROM ( SELECT 1 x ) x