Skip to content

Commit d0e8b42

Browse files
author
Alexey Botchkov
committed
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.
1 parent 7c7c069 commit d0e8b42

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

mysql-test/r/gis-rt-precise.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,25 @@ fid AsText(g)
6060
45 LINESTRING(51 51,60 60)
6161
DROP TABLE t1;
6262
End of 5.5 tests.
63+
CREATE TABLE t1 (
64+
coordinate point NOT NULL,
65+
SPATIAL KEY coordinate (coordinate)
66+
) ENGINE=Aria DEFAULT CHARSET=ascii PAGE_CHECKSUM=1;
67+
SHOW COLUMNS FROM t1;
68+
Field Type Null Key Default Extra
69+
coordinate point NO MUL NULL
70+
INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(0 0)"));
71+
INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(10 0)"));
72+
INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(10 10)"));
73+
INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(0 10)"));
74+
INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(5 5)"));
75+
SELECT astext(coordinate) FROM t1 WHERE ST_Intersects(ST_LineFromText("LINESTRING(0 0, 10 0, 10 10, 0 10)"), coordinate);
76+
astext(coordinate)
77+
POINT(0 0)
78+
POINT(10 0)
79+
POINT(10 10)
80+
POINT(0 10)
81+
SHOW COLUMNS FROM t1;
82+
Field Type Null Key Default Extra
83+
coordinate point NO MUL NULL
84+
DROP TABLE t1;

mysql-test/t/gis-rt-precise.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,25 @@ SELECT fid, AsText(g) FROM t1 WHERE ST_Within(g,
6262
DROP TABLE t1;
6363

6464
--echo End of 5.5 tests.
65+
66+
#
67+
# MDEV-12078 Using spatial index changes type from point to geometry.
68+
#
69+
CREATE TABLE t1 (
70+
coordinate point NOT NULL,
71+
SPATIAL KEY coordinate (coordinate)
72+
) ENGINE=Aria DEFAULT CHARSET=ascii PAGE_CHECKSUM=1;
73+
74+
SHOW COLUMNS FROM t1;
75+
76+
INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(0 0)"));
77+
INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(10 0)"));
78+
INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(10 10)"));
79+
INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(0 10)"));
80+
INSERT INTO t1 (coordinate) VALUES(ST_PointFromText("POINT(5 5)"));
81+
82+
SELECT astext(coordinate) FROM t1 WHERE ST_Intersects(ST_LineFromText("LINESTRING(0 0, 10 0, 10 10, 0 10)"), coordinate);
83+
84+
SHOW COLUMNS FROM t1;
85+
86+
DROP TABLE t1;

sql/opt_range.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7291,8 +7291,10 @@ SEL_TREE *Item_bool_func::get_full_func_mm_tree(RANGE_OPT_PARAM *param,
72917291
table_map param_comp= ~(param->prev_tables | param->read_tables |
72927292
param->current_table);
72937293
#ifdef HAVE_SPATIAL
7294+
Field::geometry_type sav_geom_type;
72947295
if (field_item->field->type() == MYSQL_TYPE_GEOMETRY)
72957296
{
7297+
sav_geom_type= ((Field_geom*) field_item->field)->geom_type;
72967298
/* We have to be able to store all sorts of spatial features here */
72977299
((Field_geom*) field_item->field)->geom_type= Field::GEOM_GEOMETRY;
72987300
}
@@ -7323,6 +7325,13 @@ SEL_TREE *Item_bool_func::get_full_func_mm_tree(RANGE_OPT_PARAM *param,
73237325
}
73247326
}
73257327
}
7328+
7329+
#ifdef HAVE_SPATIAL
7330+
if (field_item->field->type() == MYSQL_TYPE_GEOMETRY)
7331+
{
7332+
((Field_geom*) field_item->field)->geom_type= sav_geom_type;
7333+
}
7334+
#endif /*HAVE_SPATIAL*/
73267335
DBUG_RETURN(ftree);
73277336
}
73287337

0 commit comments

Comments
 (0)