diff --git a/mysql-test/r/gis-rtree.result b/mysql-test/r/gis-rtree.result index c394aec8851..22c30479125 100644 --- a/mysql-test/r/gis-rtree.result +++ b/mysql-test/r/gis-rtree.result @@ -1576,3 +1576,23 @@ a ASTEXT(b) 0 POINT(1 1) DROP TABLE t1; End of 5.1 tests +CREATE TABLE t1 ( +l LINESTRING NOT NULL, +SPATIAL KEY(l) +) ENGINE = myisam; +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(0 0, 1 1)')); +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(1 1, 2 2)')); +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(2 2, 3 3)')); +SELECT COUNT(*) FROM t1 IGNORE INDEX(l) WHERE MBRContains(l, GEOMFROMTEXT('POINT(0 0)')); +COUNT(*) +1 +SELECT COUNT(*) FROM t1 IGNORE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l); +COUNT(*) +1 +SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRContains(l, GEOMFROMTEXT('POINT(0 0)')); +COUNT(*) +1 +SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l); +COUNT(*) +1 +DROP TABLE t1; diff --git a/mysql-test/t/gis-rtree.test b/mysql-test/t/gis-rtree.test index 731efe5648e..404f0447f56 100644 --- a/mysql-test/t/gis-rtree.test +++ b/mysql-test/t/gis-rtree.test @@ -956,3 +956,23 @@ SELECT a, ASTEXT(b) FROM t1; DROP TABLE t1; --echo End of 5.1 tests + +# +# MDEV-4521 MBRContains, MBRWithin no longer work with geometries of different type. +# +CREATE TABLE t1 ( + l LINESTRING NOT NULL, + SPATIAL KEY(l) +) ENGINE = myisam; + +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(0 0, 1 1)')); +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(1 1, 2 2)')); +INSERT INTO t1 VALUES(GeomFromText('LINESTRING(2 2, 3 3)')); + +SELECT COUNT(*) FROM t1 IGNORE INDEX(l) WHERE MBRContains(l, GEOMFROMTEXT('POINT(0 0)')); +SELECT COUNT(*) FROM t1 IGNORE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l); + +SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRContains(l, GEOMFROMTEXT('POINT(0 0)')); +SELECT COUNT(*) FROM t1 FORCE INDEX(l) WHERE MBRWithin(GEOMFROMTEXT('POINT(0 0)'), l); + +DROP TABLE t1; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 1209e7c9223..5d71ec71903 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -7294,6 +7294,14 @@ static SEL_TREE *get_full_func_mm_tree(RANGE_OPT_PARAM *param, param->current_table); DBUG_ENTER("get_full_func_mm_tree"); +#ifdef HAVE_SPATIAL + if (field_item->field->type() == MYSQL_TYPE_GEOMETRY) + { + /* We have to be able to store all sorts of spatial features here */ + ((Field_geom*) field_item->field)->geom_type= Field::GEOM_GEOMETRY; + } +#endif /*HAVE_SPATIAL*/ + for (uint i= 0; i < cond_func->arg_count; i++) { Item *arg= cond_func->arguments()[i]->real_item();