From 998209d36b93e1a0b6e2078b004a0cdbbaf5a712 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 9 Dec 2004 00:37:17 +0300 Subject: [PATCH] A fix and test case for Bug#6873 "PS, having with subquery, crash during execute" mysql-test/r/ps.result: Test results updated (Bug#6873) mysql-test/t/ps.test: A test case for Bug#6873 "PS, having with subquery, crash during execute". sql/item_subselect.cc: If we transform having subtree, modify SELECT_LEX::having pointer to point to the new having tree root. --- mysql-test/r/ps.result | 11 +++++++++++ mysql-test/t/ps.test | 14 ++++++++++++++ sql/item_subselect.cc | 2 ++ 3 files changed, 27 insertions(+) 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;