Fix for bug #6462 "Same request on same data returns different

results." a.k.a. "Proper cleanup of subqueries is missing for SET and DO
statements". (Version #2 with after-review fixes).

To perform proper cleanup for statements that can contain subqueries 
but don't have main select we must call free_undelaid_joins().
parent a2177a2f
......@@ -1990,3 +1990,18 @@ ac
700
NULL
drop tables t1,t2;
create table t1 (a int not null, b int not null, c int, primary key (a,b));
insert into t1 values (1,1,1), (2,2,2), (3,3,3);
set @b:= 0;
explain select sum(a) from t1 where b > @b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 8 NULL 3 Using where; Using index
set @a:= (select sum(a) from t1 where b > @b);
explain select a from t1 where c=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
do @a:= (select sum(a) from t1 where b > @b);
explain select a from t1 where c=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
drop table t1;
......@@ -1282,3 +1282,22 @@ INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'
SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
SELECT b.ac FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
drop tables t1,t2;
#
# Test for bug #6462. "Same request on same data returns different
# results." a.k.a. "Proper cleanup of subqueries is missing for
# SET and DO statements".
#
create table t1 (a int not null, b int not null, c int, primary key (a,b));
insert into t1 values (1,1,1), (2,2,2), (3,3,3);
set @b:= 0;
# Let us check that subquery will use covering index
explain select sum(a) from t1 where b > @b;
# This should not crash -debug server due to failing assertion
set @a:= (select sum(a) from t1 where b > @b);
# And this should not falsely report index usage
explain select a from t1 where c=2;
# Same for DO statement
do @a:= (select sum(a) from t1 where b > @b);
explain select a from t1 where c=2;
drop table t1;
......@@ -2703,13 +2703,18 @@ int sql_set_variables(THD *thd, List<set_var_base> *var_list)
while ((var=it++))
{
if ((error=var->check(thd)))
DBUG_RETURN(error);
goto err;
}
if (thd->net.report_error)
DBUG_RETURN(1);
it.rewind();
while ((var=it++))
error|= var->update(thd); // Returns 0, -1 or 1
if (!thd->net.report_error)
{
it.rewind();
while ((var= it++))
error|= var->update(thd); // Returns 0, -1 or 1
}
else
error= 1;
err:
free_underlaid_joins(thd, &thd->lex->select_lex);
DBUG_RETURN(error);
}
......
......@@ -29,6 +29,7 @@ int mysql_do(THD *thd, List<Item> &values)
DBUG_RETURN(-1);
while ((value = li++))
value->val_int();
free_underlaid_joins(thd, &thd->lex->select_lex);
thd->clear_error(); // DO always is OK
send_ok(thd);
DBUG_RETURN(0);
......
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