|
The failing assert is here:
bool Item_subselect::const_item() const
|
{
|
DBUG_ASSERT(thd);
|
We get thd==NULL.
It is assigned in Item_subselect constructor.
It is set to a non-NULL value in fix_fields(). However the object for which the
assertion has failed (that is, *this) has fixed=false.
Put a breakpoint in Item_subselect::Item_subselect
Start debugging the query, stop at the 4th breakpoint hit.
(gdb) wher
|
#0 Item_subselect::Item_subselect (this=0x7fff6c01fd60, thd_arg=0x7fff6c000d50) at /home/psergey/dev-git/10.4-cl2/sql/item_subselect.cc:59
|
#1 0x00005555561b805d in Item_exists_subselect::Item_exists_subselect (this=0x7fff6c01fd60, thd_arg=0x7fff6c000d50) at /home/psergey/dev-git/10.4-cl2/sql/item_subselect.h:394
|
#2 0x00005555561a63ca in Item_in_subselect::Item_in_subselect (this=0x7fff6c01fd60, thd=0x7fff6c000d50, left_exp=0x7fff6c01fca0, select_lex=0x7fff6c017e68) at /home/psergey/dev-git/10.4-cl2/sql/item_subselect.cc:1487
|
#3 0x00005555561ad4b5 in Item_exists_subselect::exists2in_processor (this=0x7fff6c019d70, opt_arg=0x7fff6c000d50) at /home/psergey/dev-git/10.4-cl2/sql/item_subselect.cc:3056
|
#4 0x00005555561a3939 in Item_subselect::walk (this=0x7fff6c019d70, processor=&virtual table offset 1024, walk_subquery=false, argument=0x7fff6c000d50) at /home/psergey/dev-git/10.4-cl2/sql/item_subselect.cc:712
|
#5 0x0000555555cdc27f in Item_args::walk_args (this=0x7fff6c01e158, processor=&virtual table offset 1024, walk_subquery=false, arg=0x7fff6c000d50) at /home/psergey/dev-git/10.4-cl2/sql/item.h:2555
|
#6 0x0000555555cdc863 in Item_func_or_sum::walk (this=0x7fff6c01e0d0, processor=&virtual table offset 1024, walk_subquery=false, arg=0x7fff6c000d50) at /home/psergey/dev-git/10.4-cl2/sql/item.h:5147
|
#7 0x000055555611c439 in Item_cond::walk (this=0x7fff6c017d30, processor=&virtual table offset 1024, walk_subquery=false, arg=0x7fff6c000d50) at /home/psergey/dev-git/10.4-cl2/sql/item_cmpfunc.cc:4984
|
#8 0x0000555555db5e05 in JOIN::optimize_inner (this=0x7fff6c01cbf8) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:1845
|
#9 0x0000555555db51a2 in JOIN::optimize (this=0x7fff6c01cbf8) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:1610
|
#10 0x0000555555d3b12f in st_select_lex::optimize_unflattened_subqueries (this=0x7fff6c0146b0, const_only=false) at /home/psergey/dev-git/10.4-cl2/sql/sql_lex.cc:4200
|
#11 0x0000555555f5a444 in JOIN::optimize_unflattened_subqueries (this=0x7fff6c01bae8) at /home/psergey/dev-git/10.4-cl2/sql/opt_subselect.cc:5520
|
#12 0x0000555555db99db in JOIN::optimize_stage2 (this=0x7fff6c01bae8) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:2833
|
#13 0x0000555555db7956 in JOIN::optimize_inner (this=0x7fff6c01bae8) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:2289
|
#14 0x0000555555db51a2 in JOIN::optimize (this=0x7fff6c01bae8) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:1610
|
#15 0x0000555555dc064a in mysql_select (thd=0x7fff6c000d50, tables=0x7fff6c01ab60, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7fff6c01bac0, unit=0x7fff6c004c78, select_lex=0x7fff6c0146b0) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:4673
|
Let's continue execution until we're back in Item_exists_subselect::exists2in_processor
Here, we get an error condition here:
if (optimizer->fix_left(thd))
|
We exit up to the st_select_lex::optimize_unflattened_subqueries() (frame #10):
res= inner_join->optimize();
|
if (!inner_join->cleaned)
|
sl->update_used_tables();
|
The first line above is the call we've left.
The last line is where we crash. I am not sure if it's spelled explicitly
somewhere but it seems fairly obvious that one must not call update_used_tables()
for items for which fix_fields() call didn't finish successfully.
|
|
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
|
index eb22534f4fb..90f9ea70851 100644
|
--- a/sql/sql_lex.cc
|
+++ b/sql/sql_lex.cc
|
@@ -4197,7 +4197,8 @@ bool st_select_lex::optimize_unflattened_subqueries(bool const_only)
|
sl->options|= SELECT_DESCRIBE;
|
inner_join->select_options|= SELECT_DESCRIBE;
|
}
|
- res= inner_join->optimize();
|
+ if ((res= inner_join->optimize()))
|
+ return TRUE;
|
if (!inner_join->cleaned)
|
sl->update_used_tables();
|
sl->update_correlated_cache();
|
This makes the crash go away.
|
|
... but now the query returns this error:
ERROR 1235 (42000): This version of MariaDB doesn't yet support 'SUBQUERY in ROW in left expression of IN/ALL/ANY'
|
which seems incorrect as the query doesn't have the properties described.
|
|
http://lists.askmonty.org/pipermail/commits/2020-July/014289.html.
sanja, please review. Which version should this go into? EXISTS-to-IN was introduced into 10.0, but 10.0 was EOLed... 10.1?
|
|
Looks like a duplicate of MDEV-20557.
|
|
OK to push
|
|
The fix will go into 10.1 (and subsequent versions)
|
|
Attempt to apply the patch to 10.1 causes this:
mysqld: /home/psergey/dev-git/10.1/sql/item_subselect.cc:6750: void Item_subselect::init_expr_cache_tracker(THD*): Assertion `qw' failed.
|
|
Thread 29 "mysqld" received signal SIGABRT, Aborted.
|
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
|
#1 0x00007ffff5b6a8b1 in __GI_abort () at abort.c:79
|
#2 0x00007ffff5b5a42a in __assert_fail_base (fmt=0x7ffff5ce1a38 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x5555564761dc "qw", file=file@entry=0x555556474b80 "/home/psergey/dev-git/10.1/sql/item_subselect.cc", line=line@entry=6750, function=function@entry=0x555556477d80 <Item_subselect::init_expr_cache_tracker(THD*)::__PRETTY_FUNCTION__> "void Item_subselect::init_expr_cache_tracker(THD*)") at assert.c:92
|
#3 0x00007ffff5b5a4a2 in __GI___assert_fail (assertion=0x5555564761dc "qw", file=0x555556474b80 "/home/psergey/dev-git/10.1/sql/item_subselect.cc", line=6750, function=0x555556477d80 <Item_subselect::init_expr_cache_tracker(THD*)::__PRETTY_FUNCTION__> "void Item_subselect::init_expr_cache_tracker(THD*)") at assert.c:101
|
#4 0x0000555555d33aeb in Item_subselect::init_expr_cache_tracker (this=0x7ffeba022a00, thd=0x7ffeb6b88070) at /home/psergey/dev-git/10.1/sql/item_subselect.cc:6750
|
#5 0x0000555555d252b1 in Item_singlerow_subselect::expr_cache_insert_transformer (this=0x7ffeba022a00, tmp_thd=0x7ffeb6b88070, unused=0x0) at /home/psergey/dev-git/10.1/sql/item_subselect.cc:1249
|
#6 0x0000555555c9617e in Item::transform (this=0x7ffeba022a00, thd=0x7ffeb6b88070, transformer=&virtual Item::expr_cache_insert_transformer(THD*, unsigned char*), arg=0x0) at /home/psergey/dev-git/10.1/sql/item.cc:745
|
#7 0x0000555555ca6df7 in Item_ref::transform (this=0x7ffeba135f20, thd=0x7ffeb6b88070, transformer=&virtual Item::expr_cache_insert_transformer(THD*, unsigned char*), arg=0x0) at /home/psergey/dev-git/10.1/sql/item.cc:7098
|
#8 0x0000555555ce5811 in Item_args::transform_args (this=0x7ffeba025f18, thd=0x7ffeb6b88070, transformer=&virtual table offset 1056, arg=0x0) at /home/psergey/dev-git/10.1/sql/item_func.cc:319
|
#9 0x0000555555ce58f0 in Item_func::transform (this=0x7ffeba025e90, thd=0x7ffeb6b88070, transformer=&virtual table offset 1056, argument=0x0) at /home/psergey/dev-git/10.1/sql/item_func.cc:355
|
#10 0x0000555555cc3a0e in Item_cond::transform (this=0x7ffeba1393f0, thd=0x7ffeb6b88070, transformer=&virtual table offset 1056, arg=0x0) at /home/psergey/dev-git/10.1/sql/item_cmpfunc.cc:4843
|
#11 0x0000555555a82ce1 in JOIN::setup_subquery_caches (this=0x7ffeba134cc8) at /home/psergey/dev-git/10.1/sql/sql_select.cc:2263
|
#12 0x0000555555a815df in JOIN::optimize_inner (this=0x7ffeba134cc8) at /home/psergey/dev-git/10.1/sql/sql_select.cc:1855
|
#13 0x0000555555a7e858 in JOIN::optimize (this=0x7ffeba134cc8) at /home/psergey/dev-git/10.1/sql/sql_select.cc:1059
|
#14 0x0000555555a358c5 in st_select_lex::optimize_unflattened_subqueries (this=0x7ffeb6b8c2c0, const_only=false) at /home/psergey/dev-git/10.1/sql/sql_lex.cc:3805
|
#15 0x0000555555bd5d9c in JOIN::optimize_unflattened_subqueries (this=0x7ffeba134088) at /home/psergey/dev-git/10.1/sql/opt_subselect.cc:5334
|
#16 0x0000555555a81584 in JOIN::optimize_inner (this=0x7ffeba134088) at /home/psergey/dev-git/10.1/sql/sql_select.cc:1849
|
#17 0x0000555555a7e858 in JOIN::optimize (this=0x7ffeba134088) at /home/psergey/dev-git/10.1/sql/sql_select.cc:1059
|
#18 0x0000555555a8712d in mysql_select (thd=0x7ffeb6b88070, rref_pointer_array=0x7ffeb6b8c568, tables=0x7ffeba0264c0, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7ffeba026bf8, unit=0x7ffeb6b8bbb8, select_lex=0x7ffeb6b8c2c0) at /home/psergey/dev-git/10.1/sql/sql_select.cc:3487
|
#19 0x0000555555a7c922 in handle_select (thd=0x7ffeb6b88070, lex=0x7ffeb6b8baf8, result=0x7ffeba026bf8, setup_tables_done_option=0) at /home/psergey/dev-git/10.1/sql/sql_select.cc:377
|
#20 0x0000555555a4c390 in execute_sqlcom_select (thd=0x7ffeb6b88070, all_tables=0x7ffeba0264c0) at /home/psergey/dev-git/10.1/sql/sql_parse.cc:5682
|
#21 0x0000555555a43055 in mysql_execute_command (thd=0x7ffeb6b88070) at /home/psergey/dev-git/10.1/sql/sql_parse.cc:3029
|
#22 0x0000555555a4fea8 in mysql_parse (thd=0x7ffeb6b88070, rawbuf=0x7ffeba021088 "select\n (select country_id from location where location_code = cl1.cntr_dest) as dest_cntry,\n (select \n max(container_id) \n from cntr_leg as cl2 \n where\n cl2.container_id = cl1.container_"..., length=447, parser_state=0x7ffff7ed35e0) at /home/psergey/dev-git/10.1/sql/sql_parse.cc:7200
|
|
|
Basically, Item_subselect::init_expr_cache_tracker fails, because the Explain Data Structure is not yet created for the query.
On 10.3, we also enter Item_subselect::init_expr_cache_tracker , but the Explain Data Structure is already present as it has been created here:
#0 create_explain_query (lex=0x7fff60004b58, mem_root=0x7fff60006298) at /home/psergey/dev-git/10.3-cl/sql/sql_explain.cc:2431
|
#1 0x0000555555df626f in create_explain_query_if_not_exists (lex=0x7fff60004b58, mem_root=0x7fff60006298) at /home/psergey/dev-git/10.3-cl/sql/sql_explain.cc:2439
|
#2 0x0000555555c883a4 in JOIN::optimize_inner (this=0x7fff6001a0b0) at /home/psergey/dev-git/10.3-cl/sql/sql_select.cc:1665
|
#3 0x0000555555c87c83 in JOIN::optimize (this=0x7fff6001a0b0) at /home/psergey/dev-git/10.3-cl/sql/sql_select.cc:1497
|
#4 0x0000555555c91d54 in mysql_select (thd=0x7fff60000d50, tables=0x7fff60019a58, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7fff60019530, unit=0x7fff60004c18, select_lex=0x7fff600053a0) at /home/psergey/dev-git/10.3-cl/sql/sql_select.cc:4301
|
#5 0x0000555555c833c9 in handle_select (thd=0x7fff60000d50, lex=0x7fff60004b58, result=0x7fff60019530, setup_tables_done_option=0) at /home/psergey/dev-git/10.3-cl/sql/sql_select.cc:370
|
#6 0x0000555555c4acab in execute_sqlcom_select (thd=0x7fff60000d50, all_tables=0x7fff60019a58) at /home/psergey/dev-git/10.3-cl/sql/sql_parse.cc:6294
|
#7 0x0000555555c413f4 in mysql_execute_command (thd=0x7fff60000d50) at /home/psergey/dev-git/10.3-cl/sql/sql_parse.cc:3820
|
#8 0x0000555555c4efb6 in mysql_parse (thd=0x7fff60000d50, rawbuf=0x7fff600139b8 "select (select country_id from location where location_code = cl1.cntr_dest) as dest_cntry, (select max(container_id) from cntr_leg as cl2 where cl2.container_id = cl1.container_"..., length=447, parser_state=0x7fffd981e5c0, is_com_multi=false, is_next_command=false) at /home/psergey/dev-git/10.3-cl/sql/sql_parse.cc:7818
|
... note that the create_explain_query_if_not_exists() call is inside a
if (sel->first_cond_optimization)
|
{
|
block.
Indeed, if I run the test query inside a PREPARE; EXECUTE; EXECUTE block, then 10.3 crashes in the same way as 10.1 does.
|