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)'
COUNT(*)
1
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(
SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l);
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 @@ class Item_bool_func2 :public Item_bool_func
virtual enum Functype rev_functype() const { return 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()); }
COND *remove_eq_conds(THD *thd, Item::cond_result *cond_value,
bool top_level);
......@@ -318,6 +313,10 @@ class Item_bool_rowready_func2 :public Item_bool_func2
{
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);
virtual Item *negated_item();
bool subst_argument_checker(uchar **arg)
......@@ -1505,6 +1504,10 @@ class Item_func_like :public Item_bool_func2
escape_used_in_parsing(escape_used), use_sampling(0) {}
longlong val_int();
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;
CHARSET_INFO *compare_collation() const
{ return cmp_collation.collation; }
......
......@@ -272,19 +272,18 @@ class Item_func_spatial_collection: public Item_geometry_func
Spatial relations
*/
class Item_func_spatial_rel: public Item_bool_func
class Item_func_spatial_rel: public Item_bool_func2
{
protected:
enum Functype spatial_rel;
String tmp_value1, tmp_value2;
public:
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 rev_functype() const { return spatial_rel; }
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,
uint *and_level, table_map usable_tables,
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