[Commits] d0e8b42: MDEV-12078 Using spatial index changes type from point to geometry

Alexey Botchkov holyfoot at askmonty.org
Tue Mar 14 14:37:45 EET 2017


revision-id: d0e8b427a1877392f3b90e00f2c7606608bac996 (mariadb-10.2.4-58-gd0e8b42)
parent(s): 7c7c0696e7eba3717a592c7c2c28c46af26e3e68
committer: Alexey Botchkov
timestamp: 2017-03-14 16:35:39 +0400
message:

MDEV-12078 Using spatial index changes type from point to geometry

        In get_mm_tree we have to change Field_geom::geom_type to
        GEOMETRY as we have to let storing all types of the spatial features
        in the field. So now we restore the original geom_type as it's
        done.

---
 mysql-test/r/gis-rt-precise.result | 22 ++++++++++++++++++++++
 mysql-test/t/gis-rt-precise.test   | 22 ++++++++++++++++++++++
 sql/opt_range.cc                   |  9 +++++++++
 3 files changed, 53 insertions(+)

diff --git a/mysql-test/r/gis-rt-precise.result b/mysql-test/r/gis-rt-precise.result
index 3f4f014..65583a0 100644
--- a/mysql-test/r/gis-rt-precise.result
+++ b/mysql-test/r/gis-rt-precise.result
@@ -60,3 +60,25 @@ fid	AsText(g)
 45	LINESTRING(51 51,60 60)
 DROP TABLE t1;
 End of 5.5 tests.
+CREATE TABLE t1 (
+coordinate point NOT NULL,
+SPATIAL KEY coordinate (coordinate)
+) ENGINE=Aria DEFAULT CHARSET=ascii PAGE_CHECKSUM=1;
+SHOW COLUMNS FROM t1;
+Field	Type	Null	Key	Default	Extra
+coordinate	point	NO	MUL	NULL	
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(0 0)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(10 0)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(10 10)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(0 10)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(5 5)"));
+SELECT astext(coordinate) FROM t1 WHERE ST_Intersects(ST_LineFromText("LINESTRING(0 0, 10 0, 10 10, 0 10)"), coordinate);
+astext(coordinate)
+POINT(0 0)
+POINT(10 0)
+POINT(10 10)
+POINT(0 10)
+SHOW COLUMNS FROM t1;
+Field	Type	Null	Key	Default	Extra
+coordinate	point	NO	MUL	NULL	
+DROP TABLE t1;
diff --git a/mysql-test/t/gis-rt-precise.test b/mysql-test/t/gis-rt-precise.test
index 4cae10a..9c26aa0 100644
--- a/mysql-test/t/gis-rt-precise.test
+++ b/mysql-test/t/gis-rt-precise.test
@@ -62,3 +62,25 @@ SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g,
 DROP TABLE t1;
 
 --echo End of 5.5 tests.
+
+#
+# MDEV-12078 Using spatial index changes type from point to geometry.
+#
+CREATE TABLE t1 (
+      coordinate point NOT NULL,
+      SPATIAL KEY coordinate (coordinate)
+) ENGINE=Aria DEFAULT CHARSET=ascii PAGE_CHECKSUM=1;
+   
+SHOW COLUMNS FROM t1;
+   
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(0 0)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(10 0)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(10 10)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(0 10)"));
+INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(5 5)"));
+   
+SELECT astext(coordinate) FROM t1 WHERE ST_Intersects(ST_LineFromText("LINESTRING(0 0, 10 0, 10 10, 0 10)"), coordinate);
+   
+SHOW COLUMNS FROM t1;
+   
+DROP TABLE t1;
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 61fe64c..397ce6f7e 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -7291,8 +7291,10 @@ SEL_TREE *Item_bool_func::get_full_func_mm_tree(RANGE_OPT_PARAM *param,
   table_map param_comp= ~(param->prev_tables | param->read_tables |
 		          param->current_table);
 #ifdef HAVE_SPATIAL
+  Field::geometry_type sav_geom_type;
   if (field_item->field->type() == MYSQL_TYPE_GEOMETRY)
   {
+    sav_geom_type= ((Field_geom*) field_item->field)->geom_type;
     /* We have to be able to store all sorts of spatial features here */
     ((Field_geom*) field_item->field)->geom_type= Field::GEOM_GEOMETRY;
   }
@@ -7323,6 +7325,13 @@ SEL_TREE *Item_bool_func::get_full_func_mm_tree(RANGE_OPT_PARAM *param,
       }
     }
   }
+
+#ifdef HAVE_SPATIAL
+  if (field_item->field->type() == MYSQL_TYPE_GEOMETRY)
+  {
+    ((Field_geom*) field_item->field)->geom_type= sav_geom_type;
+  }
+#endif /*HAVE_SPATIAL*/
   DBUG_RETURN(ftree);
 }
 


More information about the commits mailing list