Skip to content

Commit d47d30b

Browse files
author
Tor Didriksen
committed
Bug#12603141: JOIN::flatten_subqueries asrt/simplify_joins sig11/...
Bug#12603457: SEGFAULT IN REINIT_STMT_BEFORE_USE These bugs are (almost) duplicates (depends empty/non-empty tables) When preparing a prepared statement, we need to save a copy of WHERE and HAVING condition trees in the prep_where and prep_having fields of SELECT_LEX. However, the semantic analysis needs to wrap some Item_field objects using Item_ref objects, which are scoped for the lifetime of the preparation. This is usually not a problem, but when the Item_field is the root object of the condition, the Item_ref object is attempted saved in prep_where or prep_having. The destructor for the Item_ref is called at the end of the preparation, so that when execution of the statement is performed, the destroyed Item_ref object will be referenced.
1 parent d189bda commit d47d30b

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

mysql-test/r/ps.result

+26
Original file line numberDiff line numberDiff line change
@@ -3722,6 +3722,32 @@ FROM (SELECT 1 UNION SELECT 2) t;
37223722
#
37233723
# End of 5.5 tests.
37243724
#
3725+
# Bug#12603141: JOIN::flatten_subqueries asrt/simplify_joins sig11/...
3726+
# Bug#12603457: SEGFAULT IN REINIT_STMT_BEFORE_USE
3727+
#
3728+
CREATE TABLE t1(a INTEGER);
3729+
CREATE TABLE t2(a INTEGER);
3730+
PREPARE stmt FROM '
3731+
SELECT (SELECT 1 FROM t2 WHERE ot.a) AS d
3732+
FROM t1 AS ot
3733+
GROUP BY d';
3734+
EXECUTE stmt;
3735+
d
3736+
EXECUTE stmt;
3737+
d
3738+
INSERT INTO t1 VALUES (0),(1),(2);
3739+
INSERT INTO t2 VALUES (1);
3740+
EXECUTE stmt;
3741+
d
3742+
NULL
3743+
1
3744+
EXECUTE stmt;
3745+
d
3746+
NULL
3747+
1
3748+
DEALLOCATE PREPARE stmt;
3749+
DROP TABLE t1, t2;
3750+
#
37253751
# Bug#12661349 assert in protocol::end_statement
37263752
#
37273753
# Note: This test case should be run with --ps-protocol

mysql-test/t/ps.test

+25
Original file line numberDiff line numberDiff line change
@@ -3327,6 +3327,31 @@ FROM (SELECT 1 UNION SELECT 2) t;
33273327
--echo #
33283328
--echo # End of 5.5 tests.
33293329

3330+
--echo #
3331+
--echo # Bug#12603141: JOIN::flatten_subqueries asrt/simplify_joins sig11/...
3332+
--echo # Bug#12603457: SEGFAULT IN REINIT_STMT_BEFORE_USE
3333+
--echo #
3334+
3335+
CREATE TABLE t1(a INTEGER);
3336+
CREATE TABLE t2(a INTEGER);
3337+
3338+
PREPARE stmt FROM '
3339+
SELECT (SELECT 1 FROM t2 WHERE ot.a) AS d
3340+
FROM t1 AS ot
3341+
GROUP BY d';
3342+
3343+
EXECUTE stmt;
3344+
EXECUTE stmt;
3345+
3346+
INSERT INTO t1 VALUES (0),(1),(2);
3347+
INSERT INTO t2 VALUES (1);
3348+
3349+
EXECUTE stmt;
3350+
EXECUTE stmt;
3351+
3352+
DEALLOCATE PREPARE stmt;
3353+
DROP TABLE t1, t2;
3354+
33303355
###########################################################################
33313356

33323357

sql/sql_lex.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3113,12 +3113,12 @@ void st_select_lex::fix_prepare_information(THD *thd, Item **conds,
31133113
}
31143114
if (*conds)
31153115
{
3116-
prep_where= *conds;
3116+
prep_where= (*conds)->real_item();
31173117
*conds= where= prep_where->copy_andor_structure(thd);
31183118
}
31193119
if (*having_conds)
31203120
{
3121-
prep_having= *having_conds;
3121+
prep_having= (*having_conds)->real_item();
31223122
*having_conds= having= prep_having->copy_andor_structure(thd);
31233123
}
31243124
fix_prepare_info_in_table_list(thd, table_list.first);

sql/sql_select.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,8 @@ JOIN::optimize()
19091909
conds= simplify_joins(this, join_list, conds, TRUE, FALSE);
19101910
build_bitmap_for_nested_joins(join_list, 0);
19111911

1912-
sel->prep_where= conds ? conds->copy_andor_structure(thd) : 0;
1912+
sel->prep_where=
1913+
conds ? conds->real_item()->copy_andor_structure(thd) : NULL;
19131914

19141915
if (arena)
19151916
thd->restore_active_arena(arena, &backup);

0 commit comments

Comments
 (0)