Commit d134e085 authored by unknown's avatar unknown

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.
parent 312132a9
......@@ -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;
......@@ -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;
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment