Crash in check_simple_equality() with semijoin + materialization + prepared statements
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Fix Released
|
Critical
|
Sergey Petrunia |
Bug Description
backtrace:
#3 <signal handler called>
#4 0x0000000000747ad3 in check_simple_
#5 0x0000000000748515 in check_equality (thd=0x1890b1e8, item=0x18a1b5b8, cond_equal=
#6 0x000000000074860d in build_equal_
#7 0x0000000000748d85 in build_equal_items (thd=0x1890b1e8, cond=0x18990e20, inherited=0x0, join_list=
at sql_select.cc:11014
#8 0x0000000000748f4b in build_equal_items (thd=0x1890b1e8, cond=0x0, inherited=0x0, join_list=
#9 0x00000000007494cb in optimize_cond (join=0x18a23aa0, conds=0x0, join_list=
at sql_select.cc:12436
#10 0x000000000074e91e in JOIN::optimize (this=0x18a23aa0) at sql_select.cc:975
#11 0x0000000000639260 in Item_in_
#12 0x000000000074e104 in inject_jtbm_conds (join=0x18a1d880, join_list=
#13 0x000000000074e8d4 in JOIN::optimize (this=0x18a1d880) at sql_select.cc:973
#14 0x0000000000752cd1 in mysql_select (thd=0x1890b1e8, rref_pointer_
og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_
at sql_select.cc:2886
#15 0x00000000007591a0 in handle_select (thd=0x1890b1e8, lex=0x18a17858, result=0x18a1b7c0, setup_tables_
#16 0x00000000006a4dcc in execute_
#17 0x00000000006a6eac in mysql_execute_
#18 0x0000000000771fbb in Prepared_
#19 0x00000000007722c6 in Prepared_
at sql_prepare.cc:3416
#20 0x000000000077257f in mysql_sql_
#21 0x00000000006a6ed7 in mysql_execute_
#22 0x00000000006afc97 in mysql_parse (thd=0x1890b1e8, rawbuf=0x18990ca0 "EXECUTE st1", length=11, found_semicolon
#23 0x00000000006b0825 in dispatch_command (command=COM_QUERY, thd=0x1890b1e8, packet=0x18987929 "EXECUTE st1", packet_length=11) at sql_parse.cc:1221
#24 0x00000000006b1e4f in do_command (thd=0x1890b1e8) at sql_parse.cc:916
#25 0x000000000069c2e3 in handle_
#26 0x00000033b600673d in start_thread () from /lib64/
#27 0x00000033b58d40cd in clone () from /lib64/libc.so.6
explain:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <subquery2> const distinct_key distinct_key 5 const 1
1 PRIMARY t1 ALL NULL NULL NULL NULL 0 Using join buffer (flat, BNL join)
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
test case:
CREATE TABLE t1 ( a int );
CREATE TABLE t3 ( b int, c int) ;
CREATE TABLE t2 ( a int ) ;
CREATE TABLE t4 ( a int , c int) ;
SET SESSION optimizer_
PREPARE st1 FROM "
SELECT STRAIGHT_JOIN *
FROM t1
WHERE ( 3 ) IN (
SELECT t3.b
FROM t3
LEFT JOIN (
t2 STRAIGHT_JOIN t4 ON ( t4.c = t2.a )
) ON ( t4.a = t3.c )
);
";
EXECUTE st1;
EXECUTE st1;
bzr version-info
revision-id: <email address hidden>
date: 2011-10-06 01:21:15 +0400
build-date: 2011-10-06 08:58:27 +0300
revno: 3213
branch-nick: maria-5.3
Changed in maria: | |
assignee: | nobody → Sergey Petrunia (sergefp) |
milestone: | none → 5.3 |
Changed in maria: | |
status: | New → Confirmed |
importance: | Undecided → Critical |
Changed in maria: | |
status: | Confirmed → Fix Committed |
Changed in maria: | |
status: | Fix Committed → Fix Released |
The crash is caused by the following execution scenario:
PREPARE command: join_subqueries _to_semi_ joins() subq_to_ jtbm() >optimize( ) subquery_ plan() works. subq_to_ jtbm() so that >optimize( ) works:
thd->free_ list.
> parent subquery calls convert_
- it switches to statement' Arena. (AA)
- subquery is converted into a non-mergeable semi-join nest,
> convert_
> it calls child_join-
(this is necessary because of how JOIN::choose_
in particular, it may figure out that Materialization is not applicable after all
and this information needs to be returned to convert_
it aborts the conversion)
> child_join-
- switches to statement arena *AGAIN* (BB)
- it calls simplify_joins(), which converts the outer join into inner.
- while doing the above, it creates an Item_cond_and() object. The object is added into
From this point, the execution proceeds normally, except that double activation (at (AA) and (BB) ) and de-activation of statement mem_root leaves the Item_cond_and un-recorded in Statement's free_list. and->cleanup( ) is never called, and on next execution we get situation
As a consequence of this, Item_cond_
where
Item_cond_ and->fixed= TRUE and->list- >nth_element( 0)->fixed= FALSE and->list- >nth_element( 1)->fixed= FALSE
Item_cond_
Item_cond_
this causes us to assert when accessing one of Item_cond_and's chlldren.