summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/ps.result11
-rw-r--r--mysql-test/t/ps.test14
-rw-r--r--sql/item_subselect.cc2
3 files changed, 27 insertions, 0 deletions
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index 4a4c8fe22e4..4cb32fa4644 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -471,3 +471,14 @@ select @var is null, @var is not null, @var;
execute stmt using @var, @var, @var;
? is null ? is not null ?
1 0 NULL
+create table t1 (pnum char(3));
+create table t2 (pnum char(3));
+prepare stmt from "select pnum from t2 having pnum in (select 'p1' from t1)";
+execute stmt;
+pnum
+execute stmt;
+pnum
+execute stmt;
+pnum
+deallocate prepare stmt;
+drop table t1, t2;
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index 51d1fd065cf..92bf4ece4e3 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -471,3 +471,17 @@ execute stmt using @var, @var, @var;
set @var=null;
select @var is null, @var is not null, @var;
execute stmt using @var, @var, @var;
+
+#
+# Bug#6873 "PS, having with subquery, crash during execute"
+# check that if we modify having subtree, we update JOIN->having pointer
+#
+create table t1 (pnum char(3));
+create table t2 (pnum char(3));
+prepare stmt from "select pnum from t2 having pnum in (select 'p1' from t1)";
+execute stmt;
+execute stmt;
+execute stmt;
+deallocate prepare stmt;
+drop table t1, t2;
+
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 1265d0b3557..69941b36ca0 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -155,6 +155,8 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
// did we changed top item of WHERE condition
if (unit->outer_select()->where == (*ref))
unit->outer_select()->where= substitution; // correct WHERE for PS
+ else if (unit->outer_select()->having == (*ref))
+ unit->outer_select()->having= substitution; // correct HAVING for PS
(*ref)= substitution;
substitution->name= name;