mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 20:12:31 +01:00
Bug #48472: Loose index scan inappropriately chosen for some
WHERE conditions check_group_min_max() checks if the loose index scan optimization is applicable for a given WHERE condition, that is if the MIN/MAX attribute participates only in range predicates comparing the corresponding field with constants. The problem was that it considered the whole predicate suitable for the loose index scan optimization as soon as it encountered a constant as a predicate argument. This is obviously wrong for cases when a constant is the first argument of a predicate which does not satisfy the above condition. Fixed check_group_min_max() so that all arguments of the input predicate are considered to decide if it passes the test, even though a constant has already been encountered. mysql-test/r/group_min_max.result: Added a test case for bug #48472. mysql-test/t/group_min_max.test: Added a test case for bug #48472. sql/opt_range.cc: Fixed check_group_min_max() so that all arguments of the input predicate are considered to decide if it passes the test, even though a constant has already been encountered.
This commit is contained in:
parent
58ee6c80eb
commit
8cfa50e677
3 changed files with 28 additions and 1 deletions
|
@ -2480,4 +2480,15 @@ SELECT a, MAX(b) FROM t WHERE b > 0 AND b < 2 GROUP BY a;
|
|||
a MAX(b)
|
||||
2 1
|
||||
DROP TABLE t;
|
||||
#
|
||||
# Bug #48472: Loose index scan inappropriately chosen for some WHERE
|
||||
# conditions
|
||||
#
|
||||
CREATE TABLE t (a INT, b INT, INDEX (a,b));
|
||||
INSERT INTO t VALUES (2,0), (2,0), (2,1), (2,1);
|
||||
INSERT INTO t SELECT * FROM t;
|
||||
SELECT a, MAX(b) FROM t WHERE 0=b+0 GROUP BY a;
|
||||
a MAX(b)
|
||||
2 0
|
||||
DROP TABLE t;
|
||||
End of 5.0 tests
|
||||
|
|
|
@ -991,5 +991,17 @@ SELECT a, MAX(b) FROM t WHERE b > 0 AND b < 2 GROUP BY a;
|
|||
|
||||
DROP TABLE t;
|
||||
|
||||
--echo #
|
||||
--echo # Bug #48472: Loose index scan inappropriately chosen for some WHERE
|
||||
--echo # conditions
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t (a INT, b INT, INDEX (a,b));
|
||||
INSERT INTO t VALUES (2,0), (2,0), (2,1), (2,1);
|
||||
INSERT INTO t SELECT * FROM t;
|
||||
|
||||
SELECT a, MAX(b) FROM t WHERE 0=b+0 GROUP BY a;
|
||||
|
||||
DROP TABLE t;
|
||||
|
||||
--echo End of 5.0 tests
|
||||
|
|
|
@ -8244,7 +8244,11 @@ check_group_min_max_predicates(COND *cond, Item_field *min_max_arg_item,
|
|||
}
|
||||
else if (cur_arg->const_item())
|
||||
{
|
||||
DBUG_RETURN(TRUE);
|
||||
/*
|
||||
For predicates of the form "const OP expr" we also have to check 'expr'
|
||||
to make a decision.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
else
|
||||
DBUG_RETURN(FALSE);
|
||||
|
|
Loading…
Reference in a new issue