Re: Wrong result with aggregate + varchar key
After adding another row into the table t1:
INSERT INTO t1 VALUES ('b', 'b');
similar problems with comparison predicates and with BETWEEN easily can be demonstrated:
MariaDB [test]> EXPLAIN
-> SELECT MIN(f1) FROM t1 WHERE f1 >= 'abc';
-------------------------------------------------------------------+
| id |
select_type |
table |
type |
possible_keys |
key |
key_len |
ref |
rows |
Extra |
-------------------------------------------------------------------+
| 1 |
SIMPLE |
t1 |
ALL |
NULL |
NULL |
NULL |
NULL |
2 |
Using where |
-------------------------------------------------------------------+
1 row in set (0.00 sec)
MariaDB [test]> SELECT MIN(f1) FROM t1 WHERE f1 >= 'abc';
---------
---------
---------
1 row in set (0.00 sec)
MariaDB [test]>
MariaDB [test]> EXPLAIN
-> SELECT MIN(f2) FROM t1 WHERE f2 >= 'abc';
------------------------------------------------------------------------------------+
| id |
select_type |
table |
type |
possible_keys |
key |
key_len |
ref |
rows |
Extra |
------------------------------------------------------------------------------------+
| 1 |
SIMPLE |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
Select tables optimized away |
------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
MariaDB [test]> SELECT MIN(f2) FROM t1 WHERE f2 >= 'abc';
---------
---------
---------
1 row in set (0.00 sec)
MariaDB [test]>
MariaDB [test]> EXPLAIN
-> SELECT MIN(f1) FROM t1 WHERE f1 BETWEEN 'abc' AND 'b' ;
-------------------------------------------------------------------+
| id |
select_type |
table |
type |
possible_keys |
key |
key_len |
ref |
rows |
Extra |
-------------------------------------------------------------------+
| 1 |
SIMPLE |
t1 |
ALL |
NULL |
NULL |
NULL |
NULL |
2 |
Using where |
-------------------------------------------------------------------+
1 row in set (0.00 sec)
MariaDB [test]> SELECT MIN(f1) FROM t1 WHERE f1 BETWEEN 'abc' AND 'b' ;
---------
---------
---------
1 row in set (0.00 sec)
MariaDB [test]>
MariaDB [test]> EXPLAIN
-> SELECT MIN(f2) FROM t1 WHERE f2 BETWEEN 'abc' AND 'b' ;
-------------------------------------------------------------------------------+
| id |
select_type |
table |
type |
possible_keys |
key |
key_len |
ref |
rows |
Extra |
-------------------------------------------------------------------------------+
| 1 |
SIMPLE |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
No matching min/max row |
-------------------------------------------------------------------------------+
1 row in set (0.00 sec)
MariaDB [test]> SELECT MIN(f2) FROM t1 WHERE f2 BETWEEN 'abc' AND 'b' ;
---------
---------
---------
1 row in set (0.00 sec)
Re: Wrong result with aggregate + varchar key
Still reproducible on 5.1, 5.2, 5.3, 5.5. Also reproducible on MySQL-5.1.60 and MySQL-5.5.19.