Commit 49ecc880 authored by Sergey Petrunya's avatar Sergey Petrunya

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.
parent 7414a0b6
...@@ -1728,6 +1728,19 @@ FROM t4 , t5 ...@@ -1728,6 +1728,19 @@ FROM t4 , t5
); );
f1 f5 f1 f5
DROP TABLE t1, t2, t3, t4, t5; 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: # This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp; set optimizer_switch=@subselect_sj_mat_tmp;
set @subselect_mat_test_optimizer_switch_value=null; set @subselect_mat_test_optimizer_switch_value=null;
......
...@@ -1764,5 +1764,18 @@ FROM t4 , t5 ...@@ -1764,5 +1764,18 @@ FROM t4 , t5
); );
f1 f5 f1 f5
DROP TABLE t1, t2, t3, t4, t5; 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: # This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp; set optimizer_switch=@subselect_sj_mat_tmp;
...@@ -1428,6 +1428,19 @@ ON ( t2.f5 ) IN ( ...@@ -1428,6 +1428,19 @@ ON ( t2.f5 ) IN (
DROP TABLE t1, t2, t3, t4, t5; 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: --echo # This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp; set optimizer_switch=@subselect_sj_mat_tmp;
......
...@@ -299,7 +299,8 @@ int opt_sum_query(THD *thd, ...@@ -299,7 +299,8 @@ int opt_sum_query(THD *thd,
is_exact_count= FALSE; is_exact_count= FALSE;
count= 1; // ensure count != 0 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 Can't remove a derived table as it's number of rows is just an
......
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