Details
Description
Test case:
CREATE TABLE t1 (f1 INT, f2 VARCHAR(1), KEY(f2,f1)) ENGINE=InnoDB; |
INSERT INTO t1 VALUES |
(7,'v'),(0,'s'),(9,'l'),(4,'c'); |
 |
SELECT MAX(f1), f2 FROM t1 WHERE f2 LIKE 'c%' AND f1 <> 9 GROUP BY f2; |
Actual result:
MAX(f1) f2
|
4 c
|
4 c
|
Expected result:
MAX(f1) f2
|
4 c
|
Note: The test case is not minimal, first 4 rows should be enough to reproduce the issue on MariaDB. But this test case is universal for all of MySQL/MariaDB versions (MySQL 5.7 requires all the rows)
EXPLAIN:
SELECT MAX(f1), f2 FROM t1 WHERE f2 LIKE 'c%' AND f1 <> 9 GROUP BY f2; |
id select_type table type possible_keys key key_len ref rows filtered Extra |
1 SIMPLE t1 range f2 f2 9 NULL 2 100.00 Using where; Using index for group-by |
Warnings:
|
Note 1003 select max(`test`.`t1`.`f1`) AS `MAX(f1)`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` where ((`test`.`t1`.`f2` like 'c%') and (`test`.`t1`.`f1` <> 9)) group by `test`.`t1`.`f2` |