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(). mysql-test/r/subselect.result: Added 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". mysql-test/t/subselect.test: Added 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". sql/set_var.cc: Added missing cleanup of joins used in subqueries to SET statement. sql/sql_do.cc: Added missing cleanup of joins used in subqueries to DO statement.
This commit is contained in:
parent
fe37a1472c
commit
4389be7557
@ -1990,3 +1990,18 @@ ac
|
|||||||
700
|
700
|
||||||
NULL
|
NULL
|
||||||
drop tables t1,t2;
|
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.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;
|
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;
|
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++))
|
while ((var=it++))
|
||||||
{
|
{
|
||||||
if ((error=var->check(thd)))
|
if ((error=var->check(thd)))
|
||||||
DBUG_RETURN(error);
|
goto err;
|
||||||
}
|
}
|
||||||
if (thd->net.report_error)
|
if (!thd->net.report_error)
|
||||||
DBUG_RETURN(1);
|
{
|
||||||
it.rewind();
|
it.rewind();
|
||||||
while ((var=it++))
|
while ((var= it++))
|
||||||
error|= var->update(thd); // Returns 0, -1 or 1
|
error|= var->update(thd); // Returns 0, -1 or 1
|
||||||
|
}
|
||||||
|
else
|
||||||
|
error= 1;
|
||||||
|
err:
|
||||||
|
free_underlaid_joins(thd, &thd->lex->select_lex);
|
||||||
DBUG_RETURN(error);
|
DBUG_RETURN(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ int mysql_do(THD *thd, List<Item> &values)
|
|||||||
DBUG_RETURN(-1);
|
DBUG_RETURN(-1);
|
||||||
while ((value = li++))
|
while ((value = li++))
|
||||||
value->val_int();
|
value->val_int();
|
||||||
|
free_underlaid_joins(thd, &thd->lex->select_lex);
|
||||||
thd->clear_error(); // DO always is OK
|
thd->clear_error(); // DO always is OK
|
||||||
send_ok(thd);
|
send_ok(thd);
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user