Skip to content

Commit a250331

Browse files
author
Sergey Glukhov
committed
Bug#16095534 CRASH: PREPARED STATEMENT CRASHES IN ITEM_BOOL_FUNC2::FIX_LENGTH_AND_DEC
The problem happened due to broken left expression in Item_in_optimizer object. In case of the bug left expression is runtime created Item_outer_ref item which is deleted at the end of the statement and one of Item_in_optimizer arguments becomes bad when re-executed. The fix is to use real_item() instead of original left expression. Note: It feels a bit weird that after preparing, the field is directly part of the generated Item_func_eq, whereas in execution it is replaced with an Item_outer_ref wrapper object.
1 parent 068e667 commit a250331

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

sql/item_subselect.cc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,15 @@ Item_in_subselect::single_value_transformer(JOIN *join,
10541054
if (upper_item)
10551055
upper_item->set_sub_test(item);
10561056
}
1057-
/* fix fields is already called for left expression */
1058-
substitution= func->create(left_expr, subs);
1057+
/*
1058+
fix fields is already called for left expression.
1059+
Note that real_item() should be used instead of
1060+
original left expression because left_expr can be
1061+
runtime created Ref item which is deleted at the end
1062+
of the statement. Thus one of 'substitution' arguments
1063+
can be broken in case of PS.
1064+
*/
1065+
substitution= func->create(left_expr->real_item(), subs);
10591066
DBUG_RETURN(RES_OK);
10601067
}
10611068

@@ -1249,8 +1256,16 @@ Item_in_subselect::single_value_transformer(JOIN *join,
12491256
// select and is not outer anymore.
12501257
item->walk(&Item::remove_dependence_processor, 0,
12511258
(uchar *) select_lex->outer_select());
1252-
item= func->create(left_expr, item);
1253-
// fix_field of item will be done in time of substituting
1259+
item= func->create(left_expr->real_item(), item);
1260+
/*
1261+
fix_field of substitution item will be done in time of
1262+
substituting.
1263+
Note that real_item() should be used instead of
1264+
original left expression because left_expr can be
1265+
runtime created Ref item which is deleted at the end
1266+
of the statement. Thus one of 'substitution' arguments
1267+
can be broken in case of PS.
1268+
*/
12541269
substitution= item;
12551270
have_to_be_excluded= 1;
12561271
if (thd->lex->describe)

0 commit comments

Comments
 (0)