Commit 55d8ee5f authored by Alexander Barkov's avatar Alexander Barkov

MDEV-8239 Reverse spatial operations OP(const, field) do not get optimized

Moving Item_func_spatial_rel from Item_bool_func to Item_bool_func2.
to make OP(const,field) use indexes.
- MBR functions supported OP(const,field) optimization in 10.0,
but were inintentionally broken in an earlier 10.1 change that introduced
a common parent for Item_func_spatial_mbr_rel and Item_func_spatial_precise_rel.
- Precise functions never supported optimization for OP(const,field).
Now both MBR and precise functions support OP(const,field) optimization.
parent cb5f32eb
...@@ -1596,3 +1596,27 @@ SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)' ...@@ -1596,3 +1596,27 @@ SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'
COUNT(*) COUNT(*)
1 1
DROP TABLE t1; DROP TABLE t1;
#
# Start of 10.1 tests
#
#
# MDEV-8239 Reverse spatial operations OP(const, field) do not get optimized
#
CREATE TABLE t1 (a GEOMETRY NOT NULL, SPATIAL KEY(a)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (Point(1,2)),(Point(1,3));
EXPLAIN SELECT * FROM t1 WHERE MBRINTERSECTS(a,Point(1,2));
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 34 NULL 1 Using where
EXPLAIN SELECT * FROM t1 WHERE ST_INTERSECTS(a,Point(1,2));
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 34 NULL 1 Using where
EXPLAIN SELECT * FROM t1 WHERE MBRINTERSECTS(Point(1,2),a);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 34 NULL 1 Using where
EXPLAIN SELECT * FROM t1 WHERE ST_INTERSECTS(Point(1,2),a);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 34 NULL 1 Using where
DROP TABLE t1;
#
# End of 10.1 tests
#
...@@ -976,3 +976,23 @@ SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRContains(l, GEOMFROMTEXT('POINT( ...@@ -976,3 +976,23 @@ SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRContains(l, GEOMFROMTEXT('POINT(
SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l); SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l);
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # Start of 10.1 tests
--echo #
--echo #
--echo # MDEV-8239 Reverse spatial operations OP(const, field) do not get optimized
--echo #
CREATE TABLE t1 (a GEOMETRY NOT NULL, SPATIAL KEY(a)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (Point(1,2)),(Point(1,3));
EXPLAIN SELECT * FROM t1 WHERE MBRINTERSECTS(a,Point(1,2));
EXPLAIN SELECT * FROM t1 WHERE ST_INTERSECTS(a,Point(1,2));
EXPLAIN SELECT * FROM t1 WHERE MBRINTERSECTS(Point(1,2),a);
EXPLAIN SELECT * FROM t1 WHERE ST_INTERSECTS(Point(1,2),a);
DROP TABLE t1;
--echo #
--echo # End of 10.1 tests
--echo #
...@@ -297,11 +297,6 @@ public: ...@@ -297,11 +297,6 @@ public:
virtual enum Functype rev_functype() const { return UNKNOWN_FUNC; } virtual enum Functype rev_functype() const { return UNKNOWN_FUNC; }
bool have_rev_func() const { return rev_functype() != UNKNOWN_FUNC; } bool have_rev_func() const { return rev_functype() != UNKNOWN_FUNC; }
virtual inline void print(String *str, enum_query_type query_type)
{
Item_func::print_op(str, query_type);
}
bool is_null() { return MY_TEST(args[0]->is_null() || args[1]->is_null()); } bool is_null() { return MY_TEST(args[0]->is_null() || args[1]->is_null()); }
COND *remove_eq_conds(THD *thd, Item::cond_result *cond_value, COND *remove_eq_conds(THD *thd, Item::cond_result *cond_value,
bool top_level); bool top_level);
...@@ -318,6 +313,10 @@ public: ...@@ -318,6 +313,10 @@ public:
{ {
allowed_arg_cols= 0; // Fetch this value from first argument allowed_arg_cols= 0; // Fetch this value from first argument
} }
void print(String *str, enum_query_type query_type)
{
Item_func::print_op(str, query_type);
}
Item *neg_transformer(THD *thd); Item *neg_transformer(THD *thd);
virtual Item *negated_item(); virtual Item *negated_item();
bool subst_argument_checker(uchar **arg) bool subst_argument_checker(uchar **arg)
...@@ -1505,6 +1504,10 @@ public: ...@@ -1505,6 +1504,10 @@ public:
escape_used_in_parsing(escape_used), use_sampling(0) {} escape_used_in_parsing(escape_used), use_sampling(0) {}
longlong val_int(); longlong val_int();
enum Functype functype() const { return LIKE_FUNC; } enum Functype functype() const { return LIKE_FUNC; }
void print(String *str, enum_query_type query_type)
{
Item_func::print_op(str, query_type);
}
optimize_type select_optimize() const; optimize_type select_optimize() const;
CHARSET_INFO *compare_collation() const CHARSET_INFO *compare_collation() const
{ return cmp_collation.collation; } { return cmp_collation.collation; }
......
...@@ -272,19 +272,18 @@ public: ...@@ -272,19 +272,18 @@ public:
Spatial relations Spatial relations
*/ */
class Item_func_spatial_rel: public Item_bool_func class Item_func_spatial_rel: public Item_bool_func2
{ {
protected: protected:
enum Functype spatial_rel; enum Functype spatial_rel;
String tmp_value1, tmp_value2; String tmp_value1, tmp_value2;
public: public:
Item_func_spatial_rel(Item *a, Item *b, enum Functype sp_rel) Item_func_spatial_rel(Item *a, Item *b, enum Functype sp_rel)
:Item_bool_func(a, b), spatial_rel(sp_rel) :Item_bool_func2(a, b), spatial_rel(sp_rel)
{ } { }
enum Functype functype() const { return spatial_rel; } enum Functype functype() const { return spatial_rel; }
enum Functype rev_functype() const { return spatial_rel; } enum Functype rev_functype() const { return spatial_rel; }
bool is_null() { (void) val_int(); return null_value; } bool is_null() { (void) val_int(); return null_value; }
optimize_type select_optimize() const { return OPTIMIZE_OP; }
void add_key_fields(JOIN *join, KEY_FIELD **key_fields, void add_key_fields(JOIN *join, KEY_FIELD **key_fields,
uint *and_level, table_map usable_tables, uint *and_level, table_map usable_tables,
SARGABLE_PARAM **sargables) SARGABLE_PARAM **sargables)
......
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