Commit 24881437 authored by Monty's avatar Monty

Fixed bug found by bar where we didn't properely check length of last argument for BETWEEN

This should not have caused any notable errors in most cases.

After fix, we are not using keys to solve MIN/MAX if the string used for comparision is longer thant the column-
parent 9bb8b74e
...@@ -3869,5 +3869,21 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -3869,5 +3869,21 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL id 27 NULL 16 Using where; Using index 1 SIMPLE t1 index NULL id 27 NULL 16 Using where; Using index
DROP TABLE t1; DROP TABLE t1;
# #
# MIN() optimization didn't work correctly with BETWEEN when using too
# long strings.
#
create table t1 (a varchar(10), key (a)) engine=myisam;
insert into t1 values("bar"),("Cafe");
explain select min(a) from t1 where a between "a" and "Cafe2";
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
explain select min(a) from t1 where a between "a" and "Cafeeeeeeeeeeeeeeeeeeeeeeeeee";
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 13 NULL 2 Using where; Using index
explain select min(a) from t1 where a between "abbbbbbbbbbbbbbbbbbbb" and "Cafe2";
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 13 NULL 2 Using where; Using index
drop table t1;
#
# End of 10.1 tests # End of 10.1 tests
# #
...@@ -1596,6 +1596,17 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a BETWEEN DATE'2001-01-04' AND ...@@ -1596,6 +1596,17 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a BETWEEN DATE'2001-01-04' AND
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a BETWEEN '2001-01-04' AND DATE'2001-01-05' GROUP BY id; EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a BETWEEN '2001-01-04' AND DATE'2001-01-05' GROUP BY id;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MIN() optimization didn't work correctly with BETWEEN when using too
--echo # long strings.
--echo #
create table t1 (a varchar(10), key (a)) engine=myisam;
insert into t1 values("bar"),("Cafe");
explain select min(a) from t1 where a between "a" and "Cafe2";
explain select min(a) from t1 where a between "a" and "Cafeeeeeeeeeeeeeeeeeeeeeeeeee";
explain select min(a) from t1 where a between "abbbbbbbbbbbbbbbbbbbb" and "Cafe2";
drop table t1;
--echo # --echo #
--echo # End of 10.1 tests --echo # End of 10.1 tests
......
...@@ -578,7 +578,7 @@ bool simple_pred(Item_func *func_item, Item **args, bool *inv_order) ...@@ -578,7 +578,7 @@ bool simple_pred(Item_func *func_item, Item **args, bool *inv_order)
if (!item->const_item()) if (!item->const_item())
return 0; return 0;
args[i]= item; args[i]= item;
if (check_item1_shorter_item2(args[0], args[1])) if (check_item1_shorter_item2(args[0], args[i]))
return 0; return 0;
} }
} }
......
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