diff options
author | unknown <timour@askmonty.org> | 2013-02-13 11:58:16 +0200 |
---|---|---|
committer | unknown <timour@askmonty.org> | 2013-02-13 11:58:16 +0200 |
commit | d4b1e8f31a2d0e71a79c2b81b3a303c769f68cd0 (patch) | |
tree | c636bec2b06d5eb4fe1a9cb242328856e249f9bc /mysql-test/t/group_min_max.test | |
parent | 3a0b25bb07e39d183202fa710ed8bc23a00ad162 (diff) | |
download | mariadb-git-d4b1e8f31a2d0e71a79c2b81b3a303c769f68cd0.tar.gz |
Fix for MDEV-4140
Analysis:
Range analysis detects that the subquery is expensive and doesn't
build a range access method. Later, the applicability test for loose
scan doesn't take that into account, and builds a loose scan method
without a range scan on the min/max column. As a result loose scan
fetches the first key in each group, rather than the first key that
satisfies the condition on the min/max column.
Solution:
Since there is no SEL_ARG tree to be used for the min/max column,
it is not possible to use loose scan if the min/max column is compared
with an expensive scalar subquery. Make the test for loose scan
applicability to be in sync with the range analysis code by testing if
the min/max argument is compared with an expensive predicate.
Diffstat (limited to 'mysql-test/t/group_min_max.test')
-rw-r--r-- | mysql-test/t/group_min_max.test | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test index d081ad6e09b..28d375f7dda 100644 --- a/mysql-test/t/group_min_max.test +++ b/mysql-test/t/group_min_max.test @@ -1239,4 +1239,26 @@ SELECT b, min(a) FROM t1 WHERE (a > '0' AND (a > '1' OR b = 'd')) GROUP BY b; drop table t1; +--echo # +--echo # MDEV-4140 Wrong result with GROUP BY + multipart key + MIN/MAX loose scan and a subquery +--echo # + +CREATE TABLE t1 (a int, b int, KEY (b, a)) ; +INSERT INTO t1 VALUES (0,99),(9,99),(4,0),(7,0),(99,0),(7,0),(8,0),(99,0),(1,0); +CREATE TABLE t2 (c int) ; +INSERT INTO t2 VALUES (0),(1); + +EXPLAIN +SELECT MIN(a), b FROM t1 WHERE a > 0 GROUP BY b; +SELECT MIN(a), b FROM t1 WHERE a > 0 GROUP BY b; +EXPLAIN +SELECT MIN(a), b FROM t1 WHERE a > ( SELECT c FROM t2 WHERE c = 0 ) GROUP BY b; +SELECT MIN(a), b FROM t1 WHERE a > ( SELECT c FROM t2 WHERE c = 0 ) GROUP BY b; +# this test is for 5.5 to ensure that the subquery is expensive +EXPLAIN +SELECT MIN(a), b FROM t1 WHERE a > ( SELECT min(c) FROM t2, t1 t1a, t1 t1b WHERE c = 0 ) GROUP BY b; +SELECT MIN(a), b FROM t1 WHERE a > ( SELECT min(c) FROM t2, t1 t1a, t1 t1b WHERE c = 0 ) GROUP BY b; + +drop table t1, t2; + --echo End of 5.3 tests |