BUG#901032: Wrong result for MIN/MAX on an indexed column with materialization and semijoin

- opt_sum_query() should not assume that join tables from sj-materialization
  have known numbers of rows.
This commit is contained in:
Sergey Petrunya 2011-12-08 02:12:48 +04:00
parent 7414a0b6d6
commit 49ecc88069
4 changed files with 41 additions and 1 deletions

View File

@ -1728,6 +1728,19 @@ FROM t4 , t5
);
f1 f5
DROP TABLE t1, t2, t3, t4, t5;
#
# BUG#901032: Wrong result for MIN/MAX on an indexed column with materialization and semijoin
#
CREATE TABLE t1 ( a INT, KEY(a) );
INSERT INTO t1 VALUES (1);
CREATE TABLE t2 ( b INT );
INSERT INTO t2 VALUES (2);
CREATE TABLE t3 ( c INT );
INSERT INTO t3 VALUES (2);
SELECT MIN(a) FROM t1, t2 WHERE b IN (SELECT c FROM t3 GROUP BY c);
MIN(a)
1
DROP TABLE t1,t2,t3;
# This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp;
set @subselect_mat_test_optimizer_switch_value=null;

View File

@ -1764,5 +1764,18 @@ FROM t4 , t5
);
f1 f5
DROP TABLE t1, t2, t3, t4, t5;
#
# BUG#901032: Wrong result for MIN/MAX on an indexed column with materialization and semijoin
#
CREATE TABLE t1 ( a INT, KEY(a) );
INSERT INTO t1 VALUES (1);
CREATE TABLE t2 ( b INT );
INSERT INTO t2 VALUES (2);
CREATE TABLE t3 ( c INT );
INSERT INTO t3 VALUES (2);
SELECT MIN(a) FROM t1, t2 WHERE b IN (SELECT c FROM t3 GROUP BY c);
MIN(a)
1
DROP TABLE t1,t2,t3;
# This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp;

View File

@ -1428,6 +1428,19 @@ ON ( t2.f5 ) IN (
DROP TABLE t1, t2, t3, t4, t5;
--echo #
--echo # BUG#901032: Wrong result for MIN/MAX on an indexed column with materialization and semijoin
--echo #
CREATE TABLE t1 ( a INT, KEY(a) );
INSERT INTO t1 VALUES (1);
CREATE TABLE t2 ( b INT );
INSERT INTO t2 VALUES (2);
CREATE TABLE t3 ( c INT );
INSERT INTO t3 VALUES (2);
SELECT MIN(a) FROM t1, t2 WHERE b IN (SELECT c FROM t3 GROUP BY c);
DROP TABLE t1,t2,t3;
--echo # This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp;

View File

@ -299,7 +299,8 @@ int opt_sum_query(THD *thd,
is_exact_count= FALSE;
count= 1; // ensure count != 0
}
else if (tl->is_materialized_derived())
else if (tl->is_materialized_derived() ||
tl->jtbm_subselect)
{
/*
Can't remove a derived table as it's number of rows is just an