Skip to content

Commit

Permalink
MDEV-8599 "WHERE varchar_field LIKE temporal_const" does not use rang…
Browse files Browse the repository at this point in the history
…e optimizer
  • Loading branch information
Alexander Barkov committed Aug 12, 2015
1 parent 6e091dc commit 9d884fd
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 170 deletions.
25 changes: 25 additions & 0 deletions mysql-test/r/func_like.result
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,30 @@ Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 10.0) and (`test`.`t1`.`a` like 10.00))
DROP TABLE t1;
#
# MDEV-8599 "WHERE varchar_field LIKE temporal_const" does not use range optimizer
#
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1, KEY(a)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('00:00:00');
INSERT INTO t1 VALUES ('00:00:01');
INSERT INTO t1 VALUES ('00:00:02');
INSERT INTO t1 VALUES ('00:00:03');
INSERT INTO t1 VALUES ('00:00:04');
INSERT INTO t1 VALUES ('00:00:05');
INSERT INTO t1 VALUES ('00:00:06');
INSERT INTO t1 VALUES ('00:00:07');
EXPLAIN SELECT * FROM t1 WHERE a LIKE '00:00:00';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 13 NULL 1 Using where; Using index
EXPLAIN SELECT * FROM t1 WHERE a LIKE TIME'00:00:00';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 13 NULL 1 Using where; Using index
SELECT * FROM t1 WHERE a LIKE '00:00:00';
a
00:00:00
SELECT * FROM t1 WHERE a LIKE TIME'00:00:00';
a
00:00:00
DROP TABLE t1;
#
# End of 10.1 tests
#
19 changes: 19 additions & 0 deletions mysql-test/t/func_like.test
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ SELECT * FROM t1 WHERE a=10.0 AND a LIKE 10.00;
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=10.0 AND a LIKE 10.00;
DROP TABLE t1;

--echo #
--echo # MDEV-8599 "WHERE varchar_field LIKE temporal_const" does not use range optimizer
--echo #
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1, KEY(a)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('00:00:00');
INSERT INTO t1 VALUES ('00:00:01');
INSERT INTO t1 VALUES ('00:00:02');
INSERT INTO t1 VALUES ('00:00:03');
INSERT INTO t1 VALUES ('00:00:04');
INSERT INTO t1 VALUES ('00:00:05');
INSERT INTO t1 VALUES ('00:00:06');
INSERT INTO t1 VALUES ('00:00:07');
EXPLAIN SELECT * FROM t1 WHERE a LIKE '00:00:00';
EXPLAIN SELECT * FROM t1 WHERE a LIKE TIME'00:00:00';
SELECT * FROM t1 WHERE a LIKE '00:00:00';
SELECT * FROM t1 WHERE a LIKE TIME'00:00:00';
DROP TABLE t1;


--echo #
--echo # End of 10.1 tests
--echo #
14 changes: 14 additions & 0 deletions sql/item_cmpfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class Arg_comparator: public Sql_alloc
friend class Item_func;
};


class SEL_ARG;
struct KEY_PART;

class Item_bool_func :public Item_int_func
{
protected:
Expand Down Expand Up @@ -147,6 +151,9 @@ class Item_bool_func :public Item_int_func
SEL_TREE *get_ne_mm_tree(RANGE_OPT_PARAM *param,
Field *field, Item *lt_value, Item *gt_value,
Item_result cmp_type);
virtual SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *param, Field *field,
KEY_PART *key_part,
Item_func::Functype type, Item *value);
public:
Item_bool_func() :Item_int_func() {}
Item_bool_func(Item *a) :Item_int_func(a) {}
Expand Down Expand Up @@ -1437,6 +1444,9 @@ class Item_func_null_predicate :public Item_bool_func
DBUG_ENTER("Item_func_null_predicate::get_func_mm_tree");
DBUG_RETURN(get_mm_parts(param, field, functype(), value, cmp_type));
}
SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *param, Field *field,
KEY_PART *key_part,
Item_func::Functype type, Item *value);
public:
Item_func_null_predicate(Item *a) :Item_bool_func(a) { }
void add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level,
Expand Down Expand Up @@ -1552,6 +1562,10 @@ class Item_func_like :public Item_bool_func2
DTCollation cmp_collation;
String cmp_value1, cmp_value2;
bool with_sargable_pattern() const;
protected:
SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *param, Field *field,
KEY_PART *key_part,
Item_func::Functype type, Item *value);
public:
int escape;

Expand Down
Loading

0 comments on commit 9d884fd

Please sign in to comment.