summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/ps_1general.result11
-rw-r--r--mysql-test/t/ps_1general.test10
-rw-r--r--sql/item.cc2
-rw-r--r--sql/sql_select.cc5
4 files changed, 22 insertions, 6 deletions
diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result
index d2f740a06f4..0a3d16cf48e 100644
--- a/mysql-test/r/ps_1general.result
+++ b/mysql-test/r/ps_1general.result
@@ -777,3 +777,14 @@ execute stmt1 ;
prepare stmt1 from ' select * from t5 ' ;
execute stmt1 ;
drop table t1, t5, t9;
+#
+# testcase for bug#11765413 - Crash with dependent subquery and
+# prepared statement
+create table t1 (c1 int);
+insert into t1 values (1);
+prepare stmt1 from "select 1 from t1 where 1=(select 1 from t1 having c1)";
+execute stmt1;
+1
+1
+drop prepare stmt1;
+drop table t1;
diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test
index b9e84d8d7df..812b1b5ff94 100644
--- a/mysql-test/t/ps_1general.test
+++ b/mysql-test/t/ps_1general.test
@@ -827,6 +827,16 @@ execute stmt1 ;
drop table t1, t5, t9;
+--echo #
+--echo # testcase for bug#11765413 - Crash with dependent subquery and
+--echo # prepared statement
+create table t1 (c1 int);
+insert into t1 values (1);
+prepare stmt1 from "select 1 from t1 where 1=(select 1 from t1 having c1)";
+execute stmt1;
+drop prepare stmt1;
+drop table t1;
+
##### RULES OF THUMB TO PRESERVE THE SYSTEMATICS OF THE PS TEST CASES #####
#
# 0. You don't have the time to
diff --git a/sql/item.cc b/sql/item.cc
index 4d80a153785..e0e7a4288da 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -6839,7 +6839,7 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
if (from_field != not_found_field)
{
Item_field* fld;
- if (!(fld= new Item_field(thd, last_checked_context, from_field)))
+ if (!(fld= new Item_field(from_field)))
goto error;
thd->change_item_tree(reference, fld);
mark_as_dependent(thd, last_checked_context->select_lex,
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 57bb9a311d7..b4489ddc81e 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -718,8 +718,6 @@ JOIN::prepare(Item ***rref_pointer_array,
if (having)
{
- Query_arena backup, *arena;
- arena= thd->activate_stmt_arena_if_needed(&backup);
nesting_map save_allow_sum_func= thd->lex->allow_sum_func;
thd->where="having clause";
thd->lex->allow_sum_func|= 1 << select_lex_arg->nest_level;
@@ -735,9 +733,6 @@ JOIN::prepare(Item ***rref_pointer_array,
(having->fix_fields(thd, &having) ||
having->check_cols(1)));
select_lex->having_fix_field= 0;
- select_lex->having= having;
- if (arena)
- thd->restore_active_arena(arena, &backup);
if (having_fix_rc || thd->is_error())
DBUG_RETURN(-1); /* purecov: inspected */