summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <dlenev@brandersnatch.localdomain>2004-11-22 13:05:10 +0300
committerunknown <dlenev@brandersnatch.localdomain>2004-11-22 13:05:10 +0300
commit4389be7557d4367cbdc9ec64c4ce4494e54e2822 (patch)
tree1468219151ed11a517ea8241f83b9f4b8f952ff2
parentfe37a1472c22b0a48244b932664925cad68f3e96 (diff)
downloadmariadb-git-4389be7557d4367cbdc9ec64c4ce4494e54e2822.tar.gz
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.
-rw-r--r--mysql-test/r/subselect.result15
-rw-r--r--mysql-test/t/subselect.test19
-rw-r--r--sql/set_var.cc17
-rw-r--r--sql/sql_do.cc1
4 files changed, 46 insertions, 6 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 32d482f5a32..53b92fe50f1 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -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;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index e0f6fcbf515..19bfaa6194a 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -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;
diff --git a/sql/set_var.cc b/sql/set_var.cc
index a97506ad07c..bc0f2c2a02c 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -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);
}
diff --git a/sql/sql_do.cc b/sql/sql_do.cc
index 25a8359f3d2..0d4529fb29e 100644
--- a/sql/sql_do.cc
+++ b/sql/sql_do.cc
@@ -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);