1#*****************************************************************
2# The Orginal name of the testcase : gis.test
3# The following are the modification done
4# 1.SET default_storage_engine=InnoDB;
5# 2.MyiSam to Innodb where ever is required.
6# 3.Spatial index to Index as Innodb does not support
7#*****************************************************************
8--source include/have_innodb.inc
9-- source include/have_geometry.inc
10
11SET default_storage_engine=InnoDB;
12SET innodb_strict_mode=OFF;
13
14#
15# Spatial objects
16#
17
18CREATE TABLE gis_point  (fid INTEGER NOT NULL PRIMARY KEY, g POINT);
19CREATE TABLE gis_line  (fid INTEGER NOT NULL PRIMARY KEY, g LINESTRING);
20CREATE TABLE gis_polygon   (fid INTEGER NOT NULL PRIMARY KEY, g POLYGON);
21CREATE TABLE gis_multi_point (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOINT);
22CREATE TABLE gis_multi_line (fid INTEGER NOT NULL PRIMARY KEY, g MULTILINESTRING);
23CREATE TABLE gis_multi_polygon  (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOLYGON);
24CREATE TABLE gis_geometrycollection  (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRYCOLLECTION);
25CREATE TABLE gis_geometry (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRY);
26
27SHOW FIELDS FROM gis_point;
28SHOW FIELDS FROM gis_line;
29SHOW FIELDS FROM gis_polygon;
30SHOW FIELDS FROM gis_multi_point;
31SHOW FIELDS FROM gis_multi_line;
32SHOW FIELDS FROM gis_multi_polygon;
33SHOW FIELDS FROM gis_geometrycollection;
34SHOW FIELDS FROM gis_geometry;
35
36
37INSERT INTO gis_point VALUES
38(101, ST_PointFromText('POINT(10 10)')),
39(102, ST_PointFromText('POINT(20 10)')),
40(103, ST_PointFromText('POINT(20 20)')),
41(104, ST_PointFromWKB(ST_AsWKB(ST_PointFromText('POINT(10 20)'))));
42
43INSERT INTO gis_line VALUES
44(105, ST_LineFromText('LINESTRING(0 0,0 10,10 0)')),
45(106, ST_LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)')),
46(107, ST_LineStringFromWKB(ST_AsWKB(LineString(Point(10, 10), Point(40, 10)))));
47
48INSERT INTO gis_polygon VALUES
49(108, ST_PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')),
50(109, ST_PolyFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10))')),
51(110, ST_PolyFromWKB(ST_AsWKB(Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0))))));
52
53INSERT INTO gis_multi_point VALUES
54(111, ST_MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)')),
55(112, ST_MPointFromText('MULTIPOINT(1 1,11 11,11 21,21 21)')),
56(113, ST_MPointFromWKB(ST_AsWKB(MultiPoint(Point(3, 6), Point(4, 10)))));
57
58INSERT INTO gis_multi_line VALUES
59(114, ST_MultiLineStringFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))')),
60(115, ST_MLineFromText('MULTILINESTRING((10 48,10 21,10 0))')),
61(116, ST_MLineFromWKB(ST_AsWKB(MultiLineString(LineString(Point(1, 2), Point(3, 5)), LineString(Point(2, 5), Point(5, 8), Point(21, 7))))));
62
63
64INSERT INTO gis_multi_polygon VALUES
65(117, ST_MultiPolygonFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')),
66(118, ST_MPolyFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')),
67(119, ST_MPolyFromWKB(ST_AsWKB(MultiPolygon(Polygon(LineString(Point(0, 3), Point(3, 3), Point(3, 0), Point(0, 3)))))));
68
69INSERT INTO gis_geometrycollection VALUES
70(120, ST_GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')),
71(121, ST_GeometryFromWKB(ST_AsWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9))))));
72
73INSERT into gis_geometry SELECT * FROM gis_point;
74INSERT into gis_geometry SELECT * FROM gis_line;
75INSERT into gis_geometry SELECT * FROM gis_polygon;
76INSERT into gis_geometry SELECT * FROM gis_multi_point;
77INSERT into gis_geometry SELECT * FROM gis_multi_line;
78INSERT into gis_geometry SELECT * FROM gis_multi_polygon;
79INSERT into gis_geometry SELECT * FROM gis_geometrycollection;
80
81SELECT fid, ST_AsText(g) FROM gis_point;
82SELECT fid, ST_AsText(g) FROM gis_line;
83SELECT fid, ST_AsText(g) FROM gis_polygon;
84SELECT fid, ST_AsText(g) FROM gis_multi_point;
85SELECT fid, ST_AsText(g) FROM gis_multi_line;
86SELECT fid, ST_AsText(g) FROM gis_multi_polygon;
87SELECT fid, ST_AsText(g) FROM gis_geometrycollection;
88SELECT fid, ST_AsText(g) FROM gis_geometry;
89
90SELECT fid, ST_Dimension(g) FROM gis_geometry;
91SELECT fid, ST_GeometryType(g) FROM gis_geometry;
92SELECT fid, ST_IsEmpty(g) FROM gis_geometry;
93SELECT fid, ST_AsText(ST_Envelope(g)) FROM gis_geometry;
94--replace_column 10 #
95explain extended select ST_Dimension(g), ST_GeometryType(g), ST_IsEmpty(g), ST_AsText(ST_Envelope(g)) from gis_geometry;
96
97SELECT fid, ST_X(g) FROM gis_point;
98SELECT fid, ST_Y(g) FROM gis_point;
99--replace_column 10 #
100explain extended select ST_X(g),ST_Y(g) FROM gis_point;
101
102SELECT fid, ST_AsText(ST_StartPoint(g)) FROM gis_line;
103SELECT fid, ST_AsText(ST_EndPoint(g)) FROM gis_line;
104SELECT fid, ST_Length(g) FROM gis_line;
105SELECT fid, ST_NumPoints(g) FROM gis_line;
106SELECT fid, ST_AsText(ST_PointN(g, 2)) FROM gis_line;
107SELECT fid, ST_IsClosed(g) FROM gis_line;
108--replace_column 10 #
109explain extended select ST_AsText(ST_StartPoint(g)),ST_AsText(ST_EndPoint(g)),ST_Length(g),ST_NumPoints(g),ST_AsText(ST_PointN(g, 2)),ST_IsClosed(g) FROM gis_line;
110
111SELECT fid, ST_AsText(ST_Centroid(g)) FROM gis_polygon;
112SELECT fid, ST_Area(g) FROM gis_polygon;
113SELECT fid, ST_AsText(ST_ExteriorRing(g)) FROM gis_polygon;
114SELECT fid, ST_NumInteriorRings(g) FROM gis_polygon;
115SELECT fid, ST_AsText(ST_InteriorRingN(g, 1)) FROM gis_polygon;
116--replace_column 10 #
117explain extended select ST_AsText(ST_Centroid(g)),ST_Area(g),ST_AsText(ST_ExteriorRing(g)),ST_NumInteriorRings(g),ST_AsText(ST_InteriorRingN(g, 1)) FROM gis_polygon;
118
119SELECT fid, ST_IsClosed(g) FROM gis_multi_line;
120
121SELECT fid, ST_AsText(ST_Centroid(g)) FROM gis_multi_polygon;
122SELECT fid, ST_Area(g) FROM gis_multi_polygon;
123
124SELECT fid, ST_NumGeometries(g) from gis_multi_point;
125SELECT fid, ST_NumGeometries(g) from gis_multi_line;
126SELECT fid, ST_NumGeometries(g) from gis_multi_polygon;
127SELECT fid, ST_NumGeometries(g) from gis_geometrycollection;
128--replace_column 10 #
129explain extended SELECT fid, ST_NumGeometries(g) from gis_multi_point;
130
131SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_point;
132SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_line;
133SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_polygon;
134SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_geometrycollection;
135SELECT fid, ST_AsText(ST_GeometryN(g, 1)) from gis_geometrycollection;
136--replace_column 10 #
137explain extended SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_point;
138
139SELECT g1.fid as first, g2.fid as second,
140MBRWithin(g1.g, g2.g) as w, MBRContains(g1.g, g2.g) as c, MBROverlaps(g1.g, g2.g) as o,
141MBREquals(g1.g, g2.g) as e, MBRDisjoint(g1.g, g2.g) as d, ST_Touches(g1.g, g2.g) as t,
142MBRIntersects(g1.g, g2.g) as i, ST_Crosses(g1.g, g2.g) as r
143FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second;
144--replace_column 10 #
145explain extended SELECT g1.fid as first, g2.fid as second,
146MBRWithin(g1.g, g2.g) as w, MBRContains(g1.g, g2.g) as c, MBROverlaps(g1.g, g2.g) as o,
147MBREquals(g1.g, g2.g) as e, MBRDisjoint(g1.g, g2.g) as d, ST_Touches(g1.g, g2.g) as t,
148MBRIntersects(g1.g, g2.g) as i, ST_Crosses(g1.g, g2.g) as r
149FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second;
150
151DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry;
152
153#
154# Check that ALTER TABLE doesn't loose geometry type
155#
156CREATE TABLE t1 (
157  gp  point,
158  ln  linestring,
159  pg  polygon,
160  mp  multipoint,
161  mln multilinestring,
162  mpg multipolygon,
163  gc  geometrycollection,
164  gm  geometry
165);
166
167SHOW FIELDS FROM t1;
168ALTER TABLE t1 ADD fid INT NOT NULL;
169SHOW FIELDS FROM t1;
170DROP TABLE t1;
171
172SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)'))));
173explain extended SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_GeometryFromText('POINT(1 4)'))));
174explain extended SELECT ST_AsText(ST_GeometryFromWKB(ST_AsWKB(ST_PointFromText('POINT(1 4)'))));
175SELECT ST_SRID(ST_GeomFromText('LineString(1 1,2 2)',101));
176explain extended SELECT ST_SRID(ST_GeomFromText('LineString(1 1,2 2)',101));
177#select ST_issimple(MultiPoint(Point(3, 6), Point(4, 10))), ST_issimple(Point(3, 6)),ST_issimple(ST_PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')),ST_issimple(ST_GeometryFromText('POINT(1 4)')), ST_issimple(ST_AsWKB(ST_GeometryFromText('POINT(1 4)')));
178explain extended select ST_issimple(MultiPoint(Point(3, 6), Point(4, 10))), ST_issimple(Point(3, 6));
179
180create table t1 (a geometry not null);
181insert into t1 values (ST_GeomFromText('Point(1 2)'));
182-- error 1416
183insert into t1 values ('Garbage');
184-- error 1416
185insert IGNORE into t1 values ('Garbage');
186
187# Now we support spatial index
188alter table t1 add spatial index(a);
189
190drop table t1;
191
192#
193# Bug #5219: problem with range optimizer
194#
195
196create table t1(a geometry not null, index(a(5)));
197insert into t1 values
198(ST_GeomFromText('POINT(1 1)')), (ST_GeomFromText('POINT(3 3)')),
199(ST_GeomFromText('POINT(4 4)')), (ST_GeomFromText('POINT(6 6)'));
200select ST_AsText(a) from t1 where
201  MBRContains(ST_GeomFromText('Polygon((0 0, 0 2, 2 2, 2 0, 0 0))'), a)
202  or
203  MBRContains(ST_GeomFromText('Polygon((2 2, 2 5, 5 5, 5 2, 2 2))'), a);
204select ST_AsText(a) from t1 where
205  MBRContains(ST_GeomFromText('Polygon((0 0, 0 2, 2 2, 2 0, 0 0))'), a)
206  and
207  MBRContains(ST_GeomFromText('Polygon((0 0, 0 7, 7 7, 7 0, 0 0))'), a);
208drop table t1;
209
210CREATE TABLE t1 (Coordinates POINT NOT NULL, INDEX(Coordinates(10)));
211INSERT INTO t1 VALUES(ST_GeomFromText('POINT(383293632 1754448)'));
212INSERT INTO t1 VALUES(ST_GeomFromText('POINT(564952612 157516260)'));
213INSERT INTO t1 VALUES(ST_GeomFromText('POINT(903994614 180726515)'));
214INSERT INTO t1 VALUES(ST_GeomFromText('POINT(98128178 141127631)'));
215INSERT INTO t1 VALUES(ST_GeomFromText('POINT(862547902 799334546)'));
216INSERT INTO t1 VALUES(ST_GeomFromText('POINT(341989013 850270906)'));
217INSERT INTO t1 VALUES(ST_GeomFromText('POINT(803302376 93039099)'));
218INSERT INTO t1 VALUES(ST_GeomFromText('POINT(857439153 817431356)'));
219INSERT INTO t1 VALUES(ST_GeomFromText('POINT(319757546 343162742)'));
220INSERT INTO t1 VALUES(ST_GeomFromText('POINT(826341972 717484432)'));
221INSERT INTO t1 VALUES(ST_GeomFromText('POINT(305066789 201736238)'));
222INSERT INTO t1 VALUES(ST_GeomFromText('POINT(626068992 616241497)'));
223INSERT INTO t1 VALUES(ST_GeomFromText('POINT(55789424 755830108)'));
224INSERT INTO t1 VALUES(ST_GeomFromText('POINT(802874458 312435220)'));
225INSERT INTO t1 VALUES(ST_GeomFromText('POINT(153795660 551723671)'));
226INSERT INTO t1 VALUES(ST_GeomFromText('POINT(242207428 537089292)'));
227INSERT INTO t1 VALUES(ST_GeomFromText('POINT(553478119 807160039)'));
228INSERT INTO t1 VALUES(ST_GeomFromText('POINT(694605552 457472733)'));
229INSERT INTO t1 VALUES(ST_GeomFromText('POINT(987886554 792733729)'));
230INSERT INTO t1 VALUES(ST_GeomFromText('POINT(598600363 850434457)'));
231INSERT INTO t1 VALUES(ST_GeomFromText('POINT(592068275 940589376)'));
232INSERT INTO t1 VALUES(ST_GeomFromText('POINT(700705362 395370650)'));
233INSERT INTO t1 VALUES(ST_GeomFromText('POINT(33628474 558144514)'));
234INSERT INTO t1 VALUES(ST_GeomFromText('POINT(212802006 353386020)'));
235INSERT INTO t1 VALUES(ST_GeomFromText('POINT(901307256 39143977)'));
236INSERT INTO t1 VALUES(ST_GeomFromText('POINT(70870451 206374045)'));
237INSERT INTO t1 VALUES(ST_GeomFromText('POINT(240880214 696939443)'));
238INSERT INTO t1 VALUES(ST_GeomFromText('POINT(822615542 296669638)'));
239INSERT INTO t1 VALUES(ST_GeomFromText('POINT(452769551 625489999)'));
240INSERT INTO t1 VALUES(ST_GeomFromText('POINT(609104858 606565210)'));
241INSERT INTO t1 VALUES(ST_GeomFromText('POINT(177213669 851312285)'));
242INSERT INTO t1 VALUES(ST_GeomFromText('POINT(143654501 730691787)'));
243INSERT INTO t1 VALUES(ST_GeomFromText('POINT(658472325 838260052)'));
244INSERT INTO t1 VALUES(ST_GeomFromText('POINT(188164520 646358878)'));
245INSERT INTO t1 VALUES(ST_GeomFromText('POINT(630993781 786764883)'));
246INSERT INTO t1 VALUES(ST_GeomFromText('POINT(496793334 223062055)'));
247INSERT INTO t1 VALUES(ST_GeomFromText('POINT(727354258 197498696)'));
248INSERT INTO t1 VALUES(ST_GeomFromText('POINT(618432704 760982731)'));
249INSERT INTO t1 VALUES(ST_GeomFromText('POINT(755643210 831234710)'));
250INSERT INTO t1 VALUES(ST_GeomFromText('POINT(114368751 656950466)'));
251INSERT INTO t1 VALUES(ST_GeomFromText('POINT(870378686 185239202)'));
252INSERT INTO t1 VALUES(ST_GeomFromText('POINT(863324511 111258900)'));
253INSERT INTO t1 VALUES(ST_GeomFromText('POINT(882178645 685940052)'));
254INSERT INTO t1 VALUES(ST_GeomFromText('POINT(407928538 334948195)'));
255INSERT INTO t1 VALUES(ST_GeomFromText('POINT(311430051 17033395)'));
256INSERT INTO t1 VALUES(ST_GeomFromText('POINT(941513405 488643719)'));
257INSERT INTO t1 VALUES(ST_GeomFromText('POINT(868345680 85167906)'));
258INSERT INTO t1 VALUES(ST_GeomFromText('POINT(219335507 526818004)'));
259INSERT INTO t1 VALUES(ST_GeomFromText('POINT(923427958 407500026)'));
260INSERT INTO t1 VALUES(ST_GeomFromText('POINT(173176882 554421738)'));
261INSERT INTO t1 VALUES(ST_GeomFromText('POINT(194264908 669970217)'));
262INSERT INTO t1 VALUES(ST_GeomFromText('POINT(777483793 921619165)'));
263INSERT INTO t1 VALUES(ST_GeomFromText('POINT(867468912 395916497)'));
264INSERT INTO t1 VALUES(ST_GeomFromText('POINT(682601897 623112122)'));
265INSERT INTO t1 VALUES(ST_GeomFromText('POINT(227151206 796970647)'));
266INSERT INTO t1 VALUES(ST_GeomFromText('POINT(280062588 97529892)'));
267INSERT INTO t1 VALUES(ST_GeomFromText('POINT(982209849 143387099)'));
268INSERT INTO t1 VALUES(ST_GeomFromText('POINT(208788792 864388493)'));
269INSERT INTO t1 VALUES(ST_GeomFromText('POINT(829327151 616717329)'));
270INSERT INTO t1 VALUES(ST_GeomFromText('POINT(199336688 140757201)'));
271INSERT INTO t1 VALUES(ST_GeomFromText('POINT(633750724 140850093)'));
272INSERT INTO t1 VALUES(ST_GeomFromText('POINT(629400920 502096404)'));
273INSERT INTO t1 VALUES(ST_GeomFromText('POINT(226017998 848736426)'));
274INSERT INTO t1 VALUES(ST_GeomFromText('POINT(28914408 149445955)'));
275INSERT INTO t1 VALUES(ST_GeomFromText('POINT(256236452 202091290)'));
276INSERT INTO t1 VALUES(ST_GeomFromText('POINT(703867693 450501360)'));
277INSERT INTO t1 VALUES(ST_GeomFromText('POINT(872061506 481351486)'));
278INSERT INTO t1 VALUES(ST_GeomFromText('POINT(372120524 739530418)'));
279INSERT INTO t1 VALUES(ST_GeomFromText('POINT(877267982 54722420)'));
280INSERT INTO t1 VALUES(ST_GeomFromText('POINT(362642540 104419188)'));
281INSERT INTO t1 VALUES(ST_GeomFromText('POINT(851693067 642705127)'));
282INSERT INTO t1 VALUES(ST_GeomFromText('POINT(201949080 833902916)'));
283INSERT INTO t1 VALUES(ST_GeomFromText('POINT(786092225 410737872)'));
284INSERT INTO t1 VALUES(ST_GeomFromText('POINT(698291409 615419376)'));
285INSERT INTO t1 VALUES(ST_GeomFromText('POINT(27455201 897628096)'));
286INSERT INTO t1 VALUES(ST_GeomFromText('POINT(756176576 661205925)'));
287INSERT INTO t1 VALUES(ST_GeomFromText('POINT(38478189 385577496)'));
288INSERT INTO t1 VALUES(ST_GeomFromText('POINT(163302328 264496186)'));
289INSERT INTO t1 VALUES(ST_GeomFromText('POINT(234313922 192216735)'));
290INSERT INTO t1 VALUES(ST_GeomFromText('POINT(413942141 490550373)'));
291INSERT INTO t1 VALUES(ST_GeomFromText('POINT(394308025 117809834)'));
292INSERT INTO t1 VALUES(ST_GeomFromText('POINT(941051732 266369530)'));
293INSERT INTO t1 VALUES(ST_GeomFromText('POINT(599161319 313172256)'));
294INSERT INTO t1 VALUES(ST_GeomFromText('POINT(5899948 476429301)'));
295INSERT INTO t1 VALUES(ST_GeomFromText('POINT(367894677 368542487)'));
296INSERT INTO t1 VALUES(ST_GeomFromText('POINT(580848489 219587743)'));
297INSERT INTO t1 VALUES(ST_GeomFromText('POINT(11247614 782797569)'));
298drop table t1;
299
300create table t1 select ST_GeomFromWKB(POINT(1,3));
301show create table t1;
302drop table t1;
303
304SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
305
306CREATE TABLE `t1` (`object_id` bigint(20) unsigned NOT NULL default '0', `geo`
307geometry NOT NULL default '') ENGINE=InnoDB ;
308
309SET sql_mode = default;
310
311insert into t1 values ('85984',ST_GeomFromText('MULTIPOLYGON(((-115.006363
31236.305435,-114.992394 36.305202,-114.991219 36.305975,-114.991163
31336.306845,-114.989432 36.309452,-114.978275 36.312642,-114.977363
31436.311978,-114.975327 36.312344,-114.96502 36.31597,-114.963364
31536.313629,-114.961723 36.313721,-114.956398 36.316057,-114.951882
31636.320979,-114.947073 36.323475,-114.945207 36.326451,-114.945207
31736.326451,-114.944132 36.326061,-114.94003 36.326588,-114.924017
31836.334484,-114.923281 36.334146,-114.92564 36.331504,-114.94072
31936.319282,-114.945348 36.314812,-114.948091 36.314762,-114.951755
32036.316211,-114.952446 36.313883,-114.952644 36.309488,-114.944725
32136.313083,-114.93706 36.32043,-114.932478 36.323497,-114.924556
32236.327708,-114.922608 36.329715,-114.92009 36.328695,-114.912105
32336.323566,-114.901647 36.317952,-114.897436 36.313968,-114.895344
32436.309573,-114.891699 36.304398,-114.890569 36.303551,-114.886356
32536.302702,-114.885141 36.301351,-114.885709 36.297391,-114.892499
32636.290893,-114.902142 36.288974,-114.904941 36.288838,-114.905308
32736.289845,-114.906325 36.290395,-114.909916 36.289549,-114.914527
32836.287535,-114.918797 36.284423,-114.922982 36.279731,-114.924113
32936.277282,-114.924057 36.275817,-114.927733 36.27053,-114.929354
33036.269029,-114.929354 36.269029,-114.950856 36.268715,-114.950768
33136.264324,-114.960206 36.264293,-114.960301 36.268943,-115.006662
33236.268929,-115.008583 36.265619,-115.00665 36.264247,-115.006659
33336.246873,-115.006659 36.246873,-115.006838 36.247697,-115.010764
33436.247774,-115.015609 36.25113,-115.015765 36.254505,-115.029517
33536.254619,-115.038573 36.249317,-115.038573 36.249317,-115.023403
33636.25841,-115.023873 36.258994,-115.031845 36.259829,-115.03183
33736.261053,-115.025561 36.261095,-115.036417 36.274632,-115.033729
33836.276041,-115.032217 36.274851,-115.029845 36.273959,-115.029934
33936.274966,-115.025763 36.274896,-115.025406 36.281044,-115.028731
34036.284471,-115.036497 36.290377,-115.042071 36.291039,-115.026759
34136.298478,-115.008995 36.301966,-115.006363 36.305435),(-115.079835
34236.244369,-115.079735 36.260186,-115.076435 36.262369,-115.069758
34336.265,-115.070235 36.268757,-115.064542 36.268655,-115.061843
34436.269857,-115.062676 36.270693,-115.06305 36.272344,-115.059051
34536.281023,-115.05918 36.283008,-115.060591 36.285246,-115.061913
34636.290022,-115.062499 36.306353,-115.062499 36.306353,-115.060918
34736.30642,-115.06112 36.289779,-115.05713 36.2825,-115.057314
34836.279446,-115.060779 36.274659,-115.061366 36.27209,-115.057858
34936.26557,-115.055805 36.262883,-115.054688 36.262874,-115.047335
35036.25037,-115.044234 36.24637,-115.052434 36.24047,-115.061734
35136.23507,-115.061934 36.22677,-115.061934 36.22677,-115.061491
35236.225267,-115.062024 36.218194,-115.060134 36.218278,-115.060133
35336.210771,-115.057833 36.210771,-115.057433 36.196271,-115.062233
35436.196271,-115.062233 36.190371,-115.062233 36.190371,-115.065533
35536.190371,-115.071333 36.188571,-115.098331 36.188275,-115.098331
35636.188275,-115.098435 36.237569,-115.097535 36.240369,-115.097535
35736.240369,-115.093235 36.240369,-115.089135 36.240469,-115.083135
35836.240569,-115.083135 36.240569,-115.079835
35936.244369)))')),('85998',ST_GeomFromText('MULTIPOLYGON(((-115.333107
36036.264587,-115.333168 36.280638,-115.333168 36.280638,-115.32226
36136.280643,-115.322538 36.274311,-115.327222 36.274258,-115.32733
36236.263026,-115.330675 36.262984,-115.332132 36.264673,-115.333107
36336.264587),(-115.247239 36.247066,-115.247438 36.218267,-115.247438
36436.218267,-115.278525 36.219263,-115.278525 36.219263,-115.301545
36536.219559,-115.332748 36.219197,-115.332757 36.220041,-115.332757
36636.220041,-115.332895 36.233514,-115.349023 36.233479,-115.351489
36736.234475,-115.353681 36.237021,-115.357106 36.239789,-115.36519
36836.243331,-115.368156 36.243487,-115.367389 36.244902,-115.364553
36936.246014,-115.359219 36.24616,-115.356186 36.248025,-115.353347
37036.248004,-115.350813 36.249507,-115.339673 36.25387,-115.333069
37136.255018,-115.333069 36.255018,-115.333042 36.247767,-115.279039
37236.248666,-115.263639 36.247466,-115.263839 36.252766,-115.261439
37336.252666,-115.261439 36.247366,-115.247239 36.247066)))'));
374
375# Expected result is 115.31877315203187, but IA64 returns 115.31877315203188
376# due to fused multiply-add instructions.
377--replace_result 115.29706047613604 115.2970604672862  36.23335611157958 36.23335610879993
378select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from
379t1 where object_id=85998;
380
381# Expected result is 36.3310176346905, but IA64 returns 36.3310176346904
382# due to fused multiply-add instructions.
383--replace_result 114.86854470090232 114.86854472054372 36.34725217627852 36.34725218253213
384select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from
385t1 where object_id=85984;
386
387drop table t1;
388
389create table t1 (fl geometry not null);
390--error 1416
391insert into t1 values (1);
392--error 1416
393insert into t1 values (1.11);
394--error 1416
395insert into t1 values ("qwerty");
396--error ER_BAD_NULL_ERROR
397insert into t1 values (ST_pointfromtext('point(1,1)'));
398
399drop table t1;
400
401select (ST_asWKT(ST_geomfromwkb((0x000000000140240000000000004024000000000000))));
402select (ST_asWKT(ST_geomfromwkb((0x010100000000000000000024400000000000002440))));
403
404--enable_metadata
405create table t1 (g GEOMETRY);
406select * from t1;
407select ST_asbinary(g) from t1;
408--disable_metadata
409drop table t1;
410
411create table t1 (a TEXT, b GEOMETRY NOT NULL, INDEX(b(5)));
412alter table t1 disable keys;
413--error 1263
414load data infile '../../std_data/bad_gis_data.dat' into table t1;
415alter table t1 enable keys;
416drop table t1;
417
418#
419# Bug #26038: is null and bad data
420#
421
422create table t1 (a int, b blob);
423insert into t1 values (1, ''), (2, NULL), (3, '1');
424select * from t1;
425
426--error ER_ILLEGAL_VALUE_FOR_TYPE
427select
428  ST_geometryfromtext(b) IS NULL, ST_geometryfromwkb(b) IS NULL, ST_astext(b) IS NULL,
429  ST_aswkb(b) IS NULL, ST_geometrytype(b) IS NULL, ST_centroid(b) IS NULL,
430  ST_envelope(b) IS NULL, ST_startpoint(b) IS NULL, ST_endpoint(b) IS NULL,
431  ST_exteriorring(b) IS NULL, ST_pointn(b, 1) IS NULL, ST_geometryn(b, 1) IS NULL,
432  ST_interiorringn(b, 1) IS NULL, multipoint(b) IS NULL, ST_isempty(b) IS NULL,
433  ST_issimple(b) IS NULL, ST_isclosed(b) IS NULL, ST_dimension(b) IS NULL,
434  ST_numgeometries(b) IS NULL, ST_numinteriorrings(b) IS NULL, ST_numpoints(b) IS NULL,
435  ST_area(b) IS NULL, ST_length(b) IS NULL, ST_srid(b) IS NULL, ST_x(b) IS NULL,
436  ST_y(b) IS NULL
437from t1;
438
439select
440  MBRwithin(b, b) IS NULL, MBRcontains(b, b) IS NULL, MBRoverlaps(b, b) IS NULL,
441  MBRequals(b, b) IS NULL, MBRdisjoint(b, b) IS NULL, ST_touches(b, b) IS NULL,
442  MBRintersects(b, b) IS NULL, ST_crosses(b, b) IS NULL
443from t1;
444
445--error ER_ILLEGAL_VALUE_FOR_TYPE
446select
447  point(b, b) IS NULL, linestring(b) IS NULL, polygon(b) IS NULL, multipoint(b) IS NULL,
448  multilinestring(b) IS NULL, multipolygon(b) IS NULL,
449  geometrycollection(b) IS NULL
450from t1;
451
452drop table t1;
453
454#
455# Bug #27164: Crash when mixing InnoDB and InnoDB Geospatial tables
456#
457CREATE TABLE t1(a POINT) ENGINE=InnoDB;
458INSERT INTO t1 VALUES (NULL);
459SELECT * FROM t1;
460DROP TABLE t1;
461
462#
463# Bug #30955 ST_geomfromtext() crasher
464#
465CREATE TABLE `t1` ( `col9` set('a'), `col89` date);
466INSERT IGNORE INTO `t1` VALUES ('','0000-00-00');
467select ST_geomfromtext(col9,col89) as a from t1;
468DROP TABLE t1;
469
470#
471# Bug #31158 Spatial, Union, LONGBLOB vs BLOB bug (crops data)
472#
473
474CREATE TABLE t1 (
475  geomdata polygon NOT NULL,
476  KEY index_geom (geomdata(10))
477) ENGINE=InnoDB DEFAULT CHARSET=latin2 DELAY_KEY_WRITE=1 ROW_FORMAT=FIXED;
478
479CREATE TABLE t2 (
480  geomdata polygon NOT NULL,
481  KEY index_geom (geomdata(10))
482) ENGINE=InnoDB DEFAULT CHARSET=latin2 DELAY_KEY_WRITE=1 ROW_FORMAT=FIXED;
483
484CREATE TABLE t3
485select
486    ST_aswkb(ws.geomdata) AS geomdatawkb
487  from
488    t1 ws
489union
490  select
491    ST_aswkb(ws.geomdata) AS geomdatawkb
492  from
493    t2 ws;
494
495describe t3;
496
497drop table t1;
498drop table t2;
499drop table t3;
500
501#
502# Bug #30284 spatial key corruption
503#
504
505create table t1(col1 geometry default null,col15 geometrycollection not
506null, index(col15(5)),index(col1(15)))engine=InnoDB;
507# --error ER_CANT_CREATE_GEOMETRY_OBJECT
508insert into t1 set col15 = ST_GeomFromText('POINT(6 5)');
509# --error ER_CANT_CREATE_GEOMETRY_OBJECT
510insert into t1 set col15 = ST_GeomFromText('POINT(6 5)');
511check table t1 extended;
512drop table t1;
513
514--echo End of 4.1 tests
515
516#
517# Bug #12281 (Geometry: crash in trigger)
518#
519
520create table t1 (s1 geometry not null,s2 char(100));
521create trigger t1_bu before update on t1 for each row set new.s1 = null;
522--error 1048
523insert into t1 values (null,null);
524drop table t1;
525
526#
527# Bug #10499 (function creation with GEOMETRY datatype)
528#
529--disable_warnings
530drop procedure if exists fn3;
531--enable_warnings
532create function fn3 () returns point deterministic return ST_GeomFromText("point(1 1)");
533show create function fn3;
534select ST_astext(fn3());
535drop function fn3;
536
537#
538# Bug #12267 (primary key over GIS)
539#
540create table t1(pt POINT);
541alter table t1 add primary key pti(pt);
542drop table t1;
543create table t1(pt GEOMETRY);
544--error 1170
545alter table t1 add primary key pti(pt);
546alter table t1 add primary key pti(pt(20));
547drop table t1;
548
549
550create table t1 select ST_GeomFromText('point(1 1)');
551desc t1;
552drop table t1;
553
554#
555# Bug #20691 (DEFAULT over NOT NULL field)
556#
557create table t1 (g geometry not null);
558--error ER_CANT_CREATE_GEOMETRY_OBJECT
559insert into t1 values(default);
560drop table t1;
561
562#
563# Bug #27300: create view with geometry functions lost columns types
564#
565CREATE TABLE t1 (a GEOMETRY);
566CREATE VIEW v1 AS SELECT ST_GeomFromwkb(ST_ASBINARY(a)) FROM t1;
567CREATE VIEW v2 AS SELECT a FROM t1;
568DESCRIBE v1;
569DESCRIBE v2;
570
571DROP VIEW v1,v2;
572DROP TABLE t1;
573
574#
575# Bug#24563: MBROverlaps does not seem to function propertly
576# Bug#54888: MBROverlaps missing in 5.1?
577#
578
579# Test all MBR* functions and their non-MBR-prefixed aliases,
580# using shifted squares to verify the spatial relations.
581
582create table t1 (name VARCHAR(100), square GEOMETRY);
583
584INSERT INTO t1 VALUES("center", ST_GeomFromText('POLYGON (( 0 0, 0 2, 2 2, 2 0, 0 0))'));
585
586INSERT INTO t1 VALUES("small",  ST_GeomFromText('POLYGON (( 0 0, 0 1, 1 1, 1 0, 0 0))'));
587INSERT INTO t1 VALUES("big",    ST_GeomFromText('POLYGON (( 0 0, 0 3, 3 3, 3 0, 0 0))'));
588
589INSERT INTO t1 VALUES("up",     ST_GeomFromText('POLYGON (( 0 1, 0 3, 2 3, 2 1, 0 1))'));
590INSERT INTO t1 VALUES("up2",    ST_GeomFromText('POLYGON (( 0 2, 0 4, 2 4, 2 2, 0 2))'));
591INSERT INTO t1 VALUES("up3",    ST_GeomFromText('POLYGON (( 0 3, 0 5, 2 5, 2 3, 0 3))'));
592
593INSERT INTO t1 VALUES("down",   ST_GeomFromText('POLYGON (( 0 -1, 0  1, 2  1, 2 -1, 0 -1))'));
594INSERT INTO t1 VALUES("down2",  ST_GeomFromText('POLYGON (( 0 -2, 0  0, 2  0, 2 -2, 0 -2))'));
595INSERT INTO t1 VALUES("down3",  ST_GeomFromText('POLYGON (( 0 -3, 0 -1, 2 -1, 2 -3, 0 -3))'));
596
597INSERT INTO t1 VALUES("right",  ST_GeomFromText('POLYGON (( 1 0, 1 2, 3 2, 3 0, 1 0))'));
598INSERT INTO t1 VALUES("right2", ST_GeomFromText('POLYGON (( 2 0, 2 2, 4 2, 4 0, 2 0))'));
599INSERT INTO t1 VALUES("right3", ST_GeomFromText('POLYGON (( 3 0, 3 2, 5 2, 5 0, 3 0))'));
600
601INSERT INTO t1 VALUES("left",   ST_GeomFromText('POLYGON (( -1 0, -1 2,  1 2,  1 0, -1 0))'));
602INSERT INTO t1 VALUES("left2",  ST_GeomFromText('POLYGON (( -2 0, -2 2,  0 2,  0 0, -2 0))'));
603INSERT INTO t1 VALUES("left3",  ST_GeomFromText('POLYGON (( -3 0, -3 2, -1 2, -1 0, -3 0))'));
604
605SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrcontains  FROM t1 a1 JOIN t1 a2 ON MBRContains(   a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
606SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrdisjoint  FROM t1 a1 JOIN t1 a2 ON MBRDisjoint(   a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
607SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrequals     FROM t1 a1 JOIN t1 a2 ON MBREquals(      a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
608SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrintersect FROM t1 a1 JOIN t1 a2 ON MBRIntersects( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
609SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbroverlaps  FROM t1 a1 JOIN t1 a2 ON MBROverlaps(   a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
610SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrtouches   FROM t1 a1 JOIN t1 a2 ON MBRTouches(    a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
611SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrwithin    FROM t1 a1 JOIN t1 a2 ON MBRWithin(     a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
612
613SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS MBRcontains     FROM t1 a1 JOIN t1 a2 ON MBRContains(      a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
614SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS MBRdisjoint     FROM t1 a1 JOIN t1 a2 ON MBRDisjoint(      a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
615SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS MBRequals       FROM t1 a1 JOIN t1 a2 ON MBREquals(        a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
616SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS intersects    FROM t1 a1 JOIN t1 a2 ON MBRIntersects(    a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
617SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS MBRoverlaps     FROM t1 a1 JOIN t1 a2 ON MBROverlaps(      a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
618SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS ST_touches      FROM t1 a1 JOIN t1 a2 ON ST_Touches(       a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
619SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS MBRwithin       FROM t1 a1 JOIN t1 a2 ON MBRWithin(        a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name;
620
621# MBROverlaps needs a few more tests, with point and line dimensions
622
623SET @vert1   = ST_GeomFromText('POLYGON ((0 -2, 0 2, 0 -2))');
624SET @horiz1  = ST_GeomFromText('POLYGON ((-2 0, 2 0, -2 0))');
625SET @horiz2 = ST_GeomFromText('POLYGON ((-1 0, 3 0, -1 0))');
626SET @horiz3 = ST_GeomFromText('POLYGON ((2 0, 3 0, 2 0))');
627SET @point1 = ST_GeomFromText('POLYGON ((0 0))');
628SET @point2 = ST_GeomFromText('POLYGON ((-2 0))');
629
630SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS MBRoverlaps FROM t1 a1 WHERE MBROverlaps(a1.square, @vert1) GROUP BY a1.name;
631SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS MBRoverlaps FROM t1 a1 WHERE MBROverlaps(a1.square, @horiz1) GROUP BY a1.name;
632SELECT MBROverlaps(@horiz1, @vert1) FROM DUAL;
633SELECT MBROverlaps(@horiz1, @horiz2) FROM DUAL;
634SELECT MBROverlaps(@horiz1, @horiz3) FROM DUAL;
635SELECT MBROverlaps(@horiz1, @point1) FROM DUAL;
636SELECT MBROverlaps(@horiz1, @point2) FROM DUAL;
637
638DROP TABLE t1;
639
640#
641# Bug#28763: Selecting geometry fields in UNION caused server crash.
642#
643create table t1(f1 geometry, f2 polygon, f3 linestring);
644select f1 from t1 union select f1 from t1;
645insert into t1 (f2,f3) values (ST_GeomFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))'), ST_GeomFromText('LINESTRING(0 0,1 1,2 2)'));
646select ST_AsText(f2),ST_AsText(f3) from t1;
647select ST_AsText(a) from (select f2 as a from t1 union select f3 from t1) t;
648create table t2 as select f2 as a from t1 union select f3 from t1;
649desc t2;
650select ST_AsText(a) from t2;
651drop table t1, t2;
652
653#
654# Bug #29166: MYsql crash when query is run
655#
656
657# The test query itself is not logged : too large output.
658# The real test is the second query : see if the first hasn't crashed the
659# server
660--disable_query_log
661--disable_result_log
662SELECT ST_AsText(ST_GeometryFromText(CONCAT(
663  'MULTIPOLYGON(((',
664  REPEAT ('-0.00000000001234567890123456789012 -0.123456789012345678,', 1000),
665  '-0.00000000001234567890123456789012 -0.123456789012345678',
666  ')))'
667))) AS a;
668--enable_result_log
669--enable_query_log
670SELECT 1;
671
672-- source include/gis_keys.inc
673
674#
675# Bug #31155 gis types in union'd select cause crash
676#
677
678create table `t1` (`col002` point)engine=InnoDB;
679insert into t1 values (),(),();
680# --error ER_WRONG_ARGUMENTS
681select min(`col002`) from t1 union select `col002` from t1;
682drop table t1;
683
684--echo #
685--echo # Bug #47780: crash when comparing GIS items from subquery
686--echo #
687
688CREATE TABLE t1(a INT, b MULTIPOLYGON);
689INSERT INTO t1 VALUES
690  (0,
691   ST_GEOMFROMTEXT(
692    'multipolygon(((1 2,3 4,5 6,7 8,9 8,1 2,1 2),(7 6,5 4,3 2,1 2,3 4,7 6)))'));
693
694--echo # must not crash
695--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
696SELECT 1 FROM t1 WHERE a <> (SELECT ST_GEOMETRYCOLLECTIONFROMWKB(b) FROM t1);
697
698DROP TABLE t1;
699
700--echo #
701--echo # Bug #49250 : spatial btree index corruption and crash
702--echo # Part one : spatial syntax check
703--echo #
704
705--error ER_PARSE_ERROR
706CREATE TABLE t1(col1 MULTIPOLYGON NOT NULL,
707  SPATIAL INDEX USING BTREE (col1));
708CREATE TABLE t2(col1 MULTIPOLYGON NOT NULL);
709--error ER_PARSE_ERROR
710CREATE SPATIAL INDEX USING BTREE ON t2(col);
711--error ER_PARSE_ERROR
712ALTER TABLE t2 ADD SPATIAL INDEX USING BTREE (col1);
713
714DROP TABLE t2;
715
716--echo End of 5.0 tests
717
718
719#
720# Bug #11335 View redefines column types
721#
722create table t1 (f1 tinyint(1), f2 char(1), f3 varchar(1), f4 geometry, f5 datetime);
723create view v1 as select * from t1;
724desc v1;
725drop view v1;
726drop table t1;
727
728#
729# Bug#44684: valgrind reports invalid reads in
730# Item_func_spatial_collection::val_str
731#
732--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
733SELECT MultiPoint(12345,'');
734#SELECT MultiPoint(123451,'');
735#SELECT MultiPoint(1234512,'');
736#SELECT MultiPoint(12345123,'');
737
738--error ER_ILLEGAL_VALUE_FOR_TYPE
739#SELECT MultiLineString(12345,'');
740#SELECT MultiLineString(123451,'');
741#SELECT MultiLineString(1234512,'');
742#SELECT MultiLineString(12345123,'');
743
744--error ER_ILLEGAL_VALUE_FOR_TYPE
745#SELECT LineString(12345,'');
746#SELECT LineString(123451,'');
747#SELECT LineString(1234512,'');
748#SELECT LineString(12345123,'');
749
750--error ER_ILLEGAL_VALUE_FOR_TYPE
751#SELECT Polygon(12345,'');
752#SELECT Polygon(123451,'');
753#SELECT Polygon(1234512,'');
754#SELECT Polygon(12345123,'');
755
756#
757# Bug55531 crash with conversions of geometry types / strings
758#
759--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
760SELECT 1 FROM (SELECT GREATEST(1,GEOMETRYCOLLECTION('00000','00000')) b FROM DUAL) AS d WHERE (LINESTRING(d.b));
761
762
763--echo #
764--echo # BUG#51875: crash when loading data into geometry function ST_polyfromwkb
765--echo #
766SET @a=0x00000000030000000100000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440;
767SET @a=ST_POLYFROMWKB(@a);
768SET @a=0x00000000030000000000000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440;
769SET @a=ST_POLYFROMWKB(@a);
770
771
772#
773# Bug #57321    crashes and valgrind errors from spatial types
774#
775
776create table t1(a polygon NOT NULL)engine=InnoDB;
777--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
778insert into t1 values (ST_geomfromtext("point(0 1)"));
779--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
780insert into t1 values (ST_geomfromtext("point(1 0)"));
781select * from (select polygon(t1.a) as p from t1 order by t1.a) d;
782drop table t1;
783
784
785--echo #
786--echo # Test for bug #59888 "debug assertion when attempt to create spatial index
787--echo #                      on char > 31 bytes".
788--echo #
789create table t1(a char(32) not null) engine=InnoDB;
790#--error ER_SPATIAL_MUST_HAVE_GEOM_COL
791create index i on t1 (a(5));
792drop table t1;
793
794
795--echo End of 5.1 tests
796
797#
798# Bug #50574 5.5.ST_x allows spatial indexes on non-spatial
799#           columns, causing crashes!
800# Bug#11767480 SPATIAL INDEXES ON NON-SPATIAL COLUMNS
801#              CAUSE CRASHES.
802#
803CREATE TABLE t0 (a BINARY(32) NOT NULL);
804#--error ER_SPATIAL_MUST_HAVE_GEOM_COL
805CREATE UNIQUE INDEX i on t0 (a(10));
806INSERT INTO t0 VALUES (1);
807
808#--error ER_SPATIAL_MUST_HAVE_GEOM_COL
809CREATE TABLE t1(
810  col0 BINARY NOT NULL,
811  col2 TIMESTAMP,
812  INDEX i1 (col0)
813) ENGINE=InnoDB;
814
815# Test other ways to add indices
816CREATE TABLE t2 (
817  col0 BINARY NOT NULL,
818  col2 TIMESTAMP
819) ENGINE=InnoDB;
820
821#--error ER_SPATIAL_MUST_HAVE_GEOM_COL
822CREATE INDEX idx0 ON t1(col0);
823
824#--error ER_SPATIAL_MUST_HAVE_GEOM_COL
825#ALTER TABLE t1 ADD INDEX i1 (col0);
826
827CREATE TABLE t3 (
828  col0 INTEGER NOT NULL,
829  col1 POINT,
830  col2 POINT
831);
832
833# --error ER_TOO_MANY_KEY_PARTS
834--error ER_WRONG_ARGUMENTS
835CREATE SPATIAL INDEX idx0 ON t2 (col1, col2);
836
837
838CREATE TABLE t4 (
839  col0 INTEGER NOT NULL,
840  col1 POINT,
841  col2 LINESTRING,
842  INDEX i1 (col1(5), col2(5))
843);
844
845# cleanup
846DROP TABLE IF EXISTS t0, t1, t2, t3,t4;
847
848
849--echo #
850--echo # BUG#12414917 - ST_ISCLOSED() CRASHES ON 64-BIT BUILDS
851--echo #
852# --error ER_GIS_DATA_WRONG_ENDIANESS
853SELECT ST_ISCLOSED(CONVERT(CONCAT('     ', 0x2), BINARY(20)));
854
855--echo #
856--echo # BUG#12537203 - CRASH WHEN SUBSELECTING GLOBAL VARIABLES IN
857--echo # GEOMETRY FUNCTION ARGUMENTS
858--echo #
859--replace_regex /non geometric .* value/non geometric '' value/
860--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
861SELECT GEOMETRYCOLLECTION((SELECT @@OLD));
862
863
864--echo End of 5.1 tests
865
866
867--echo #
868--echo # Bug#11908153: CRASH AND/OR VALGRIND ERRORS IN FIELD_BLOB::GET_KEY_IMAGE
869--echo #
870
871CREATE TABLE g1
872(a geometry NOT NULL, UNIQUE KEY i (a(151))) engine=InnoDB;
873
874INSERT INTO g1 VALUES (ST_geomfromtext('point(1 1)'));
875INSERT INTO g1 VALUES (ST_geomfromtext('point(1 2)'));
876
877FLUSH TABLES;
878
879--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
880SELECT 1 FROM g1
881FORCE INDEX(i) WHERE a = date_sub(now(), interval 2808.4 year_month)
882;
883
884DROP TABLE g1;
885
886--echo #
887--echo # Bug#13013970 MORE CRASHES IN FIELD_BLOB::GET_KEY_IMAGE
888--echo #
889
890CREATE TABLE g1(a TEXT NOT NULL, KEY(a(255)));
891
892INSERT INTO g1 VALUES ('a'),('a');
893SELECT 1 FROM g1 WHERE a >= ANY
894(SELECT 1 FROM g1 WHERE a = ST_geomfromtext('') OR a) ;
895
896DROP TABLE g1;
897
898--echo End of 5.5 tests
899
900
901# Conformance tests
902#
903# C.3.3 Geometry types and functions
904#
905
906--disable_warnings
907DROP DATABASE IF EXISTS gis_ogs;
908--enable_warnings
909
910CREATE DATABASE gis_ogs;
911USE gis_ogs;
912
913--echo #
914--echo # C.3.3.1 Geometry types and functions schema construction
915--echo #
916
917# TODO: WL#2377
918#CREATE TABLE spatial_ref_sys (
919#ST_srid INTEGER NOT NULL PRIMARY KEY,
920#auth_name CHARACTER VARYING,
921#auth_srid INTEGER,
922#srtext CHARACTER VARYING(2048));
923
924CREATE TABLE lakes (
925  fid INTEGER NOT NULL PRIMARY KEY,
926  name CHARACTER VARYING(64),
927  shore POLYGON);
928
929CREATE TABLE road_segments (
930  fid INTEGER NOT NULL PRIMARY KEY,
931  name CHARACTER VARYING(64),
932  aliases CHARACTER VARYING(64),
933  num_lanes INTEGER,
934  centerline LINESTRING);
935
936CREATE TABLE divided_routes (
937  fid INTEGER NOT NULL PRIMARY KEY,
938  name CHARACTER VARYING(64),
939  num_lanes INTEGER,
940  centerlines MULTILINESTRING);
941
942CREATE TABLE forests (
943  fid INTEGER NOT NULL PRIMARY KEY,
944  name CHARACTER VARYING(64),
945  boundary MULTIPOLYGON);
946
947CREATE TABLE bridges (
948  fid INTEGER NOT NULL PRIMARY KEY,
949  name CHARACTER VARYING(64),
950  position POINT);
951
952CREATE TABLE streams (
953  fid INTEGER NOT NULL PRIMARY KEY,
954  name CHARACTER VARYING(64),
955  centerline LINESTRING);
956
957CREATE TABLE buildings (
958  fid INTEGER NOT NULL PRIMARY KEY,
959  address CHARACTER VARYING(64),
960  position POINT,
961  footprint POLYGON);
962
963CREATE TABLE ponds (
964  fid INTEGER NOT NULL PRIMARY KEY,
965  name CHARACTER VARYING(64),
966  type CHARACTER VARYING(64),
967  shores MULTIPOLYGON);
968
969CREATE TABLE named_places (
970  fid INTEGER NOT NULL PRIMARY KEY,
971  name CHARACTER VARYING(64),
972  boundary POLYGON);
973
974CREATE TABLE map_neatlines (
975  fid INTEGER NOT NULL PRIMARY KEY,
976  neatline POLYGON);
977
978--echo #
979--echo # C.3.3.2 Geometry types and functions schema data loading
980--echo #
981
982# TODO: WL#2377
983#-- Spatial Reference System
984#INSERT INTO spatial_ref_sys VALUES
985#(101, 'POSC', 32214, 'PROJCS["UTM_ZONE_14N",
986#GEOGCS["World Geodetic System 72",
987#DATUM["WGS_72",
988#ELLIPSOID["NWL_10D", 6378135, 298.26]],
989#PRIMEM["Greenwich", 0],
990#UNIT["Meter", 1.0]],
991#PROJECTION["Transverse_Mercator"],
992#PARAMETER["False_Easting", 500000.0],
993#PARAMETER["False_Northing", 0.0],
994#PARAMETER["Central_Meridian", -99.0],
995#PARAMETER["Scale_Factor", 0.9996],
996#PARAMETER["Latitude_of_origin", 0.0],
997#UNIT["Meter", 1.0]]');
998
999--echo # Lakes
1000INSERT INTO lakes VALUES (
1001101, 'BLUE LAKE',
1002ST_PolyFromText(
1003'POLYGON(
1004(52 18,66 23,73 9,48 6,52 18),
1005(59 18,67 18,67 13,59 13,59 18)
1006)',
1007101));
1008
1009
1010--echo # Road Segments
1011
1012INSERT INTO road_segments VALUES(102, 'Route 5', NULL, 2,
1013ST_LineFromText(
1014'LINESTRING( 0 18, 10 21, 16 23, 28 26, 44 31 )' ,101));
1015
1016INSERT INTO road_segments VALUES(103, 'Route 5', 'Main Street', 4,
1017ST_LineFromText(
1018'LINESTRING( 44 31, 56 34, 70 38 )' ,101));
1019
1020INSERT INTO road_segments VALUES(104, 'Route 5', NULL, 2,
1021ST_LineFromText(
1022'LINESTRING( 70 38, 72 48 )' ,101));
1023
1024INSERT INTO road_segments VALUES(105, 'Main Street', NULL, 4,
1025ST_LineFromText(
1026'LINESTRING( 70 38, 84 42 )' ,101));
1027
1028INSERT INTO road_segments VALUES(106, 'Dirt Road by Green Forest', NULL,
10291,
1030ST_LineFromText(
1031'LINESTRING( 28 26, 28 0 )',101));
1032
1033--echo # DividedRoutes
1034
1035INSERT INTO divided_routes VALUES(119, 'Route 75', 4,
1036ST_MLineFromText(
1037'MULTILINESTRING((10 48,10 21,10 0),
1038(16 0,16 23,16 48))', 101));
1039
1040--echo # Forests
1041
1042INSERT INTO forests VALUES(109, 'Green Forest',
1043ST_MPolyFromText(
1044'MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),
1045(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))',
1046101));
1047
1048--echo # Bridges
1049
1050INSERT INTO bridges VALUES(110, 'Cam Bridge', ST_PointFromText(
1051'POINT( 44 31 )', 101));
1052
1053--echo # Streams
1054
1055INSERT INTO streams VALUES(111, 'Cam Stream',
1056ST_LineFromText(
1057'LINESTRING( 38 48, 44 41, 41 36, 44 31, 52 18 )', 101));
1058
1059INSERT INTO streams VALUES(112, NULL,
1060ST_LineFromText(
1061'LINESTRING( 76 0, 78 4, 73 9 )', 101));
1062
1063--echo # Buildings
1064
1065INSERT INTO buildings VALUES(113, '123 Main Street',
1066ST_PointFromText(
1067'POINT( 52 30 )', 101),
1068ST_PolyFromText(
1069'POLYGON( ( 50 31, 54 31, 54 29, 50 29, 50 31) )', 101));
1070
1071INSERT INTO buildings VALUES(114, '215 Main Street',
1072ST_PointFromText(
1073'POINT( 64 33 )', 101),
1074ST_PolyFromText(
1075'POLYGON( ( 66 34, 62 34, 62 32, 66 32, 66 34) )', 101));
1076
1077
1078--echo # Ponds
1079
1080INSERT INTO ponds VALUES(120, NULL, 'Stock Pond',
1081ST_MPolyFromText(
1082'MULTIPOLYGON( ( ( 24 44, 22 42, 24 40, 24 44) ),
1083( ( 26 44, 26 40, 28 42, 26 44) ) )', 101));
1084
1085--echo # Named Places
1086
1087INSERT INTO named_places VALUES(117, 'Ashton',
1088ST_PolyFromText(
1089'POLYGON( ( 62 48, 84 48, 84 30, 56 30, 56 34, 62 48) )', 101));
1090
1091INSERT INTO named_places VALUES(118, 'Goose Island',
1092ST_PolyFromText(
1093'POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )', 101));
1094
1095--echo # Map Neatlines
1096
1097INSERT INTO map_neatlines VALUES(115,
1098ST_PolyFromText(
1099'POLYGON( ( 0 0, 0 48, 84 48, 84 0, 0 0 ) )', 101));
1100
1101--echo #
1102--echo # C.3.3.3 Geometry types and functions schema test queries
1103--echo
1104
1105# TODO: WL#2377
1106#--echo # Conformance Item T1
1107#SELECT f_table_name
1108#FROM geometry_columns;
1109#
1110#--echo # Conformance Item T2
1111#SELECT f_geometry_column
1112#FROM geometry_columns
1113#WHERE f_table_name = 'streams';
1114#
1115#--echo # Conformance Item T3
1116#SELECT coord_dimension
1117#FROM geometry_columns
1118#WHERE f_table_name = 'streams';
1119#
1120#--echo # Conformance Item T4
1121#
1122#SELECT ST_srid
1123#FROM geometry_columns
1124#WHERE f_table_name = 'streams';
1125#
1126#--echo # Conformance Item T5
1127#
1128#SELECT srtext
1129#FROM SPATIAL_REF_SYS
1130#WHERE ST_SRID = 101;
1131#
1132
1133
1134--echo # Conformance Item T6
1135# TODO: ST_Dimension() alias
1136SELECT ST_Dimension(shore)
1137FROM lakes
1138WHERE name = 'Blue Lake';
1139
1140--echo # Conformance Item T7
1141# TODO: ST_GeometryType() alias
1142SELECT ST_GeometryType(centerlines)
1143FROM divided_routes
1144WHERE name = 'Route 75';
1145
1146--echo # Conformance Item T8
1147# TODO: ST_AsText() alias
1148SELECT ST_AsText(boundary)
1149FROM named_places
1150WHERE name = 'Goose Island';
1151
1152--echo # Conformance Item T9
1153# TODO: ST_AsBinary(), ST_PolyFromWKB() aliases
1154SELECT ST_AsText(ST_PolyFromWKB(ST_AsBinary(boundary),101))
1155FROM named_places
1156WHERE name = 'Goose Island';
1157
1158--echo # Conformance Item T10
1159# TODO: ST_SRID() alias
1160SELECT ST_SRID(boundary)
1161FROM named_places
1162WHERE name = 'Goose Island';
1163
1164--echo # Conformance Item T11
1165# TODO: ST_IsEmpty() alias
1166SELECT ST_IsEmpty(centerline)
1167FROM road_segments
1168WHERE name = 'Route 5'
1169AND aliases = 'Main Street';
1170
1171# FIXME: get wrong result:0, expected 1.
1172#--echo # Conformance Item T12
1173# TODO: ST_IsSimple() alias
1174#SELECT ST_IsSimple(shore)
1175#FROM lakes
1176#WHERE name = 'Blue Lake';
1177
1178# TODO: WL#2377
1179#--echo # Conformance Item T13
1180#SELECT ST_AsText(Boundary((boundary),101)
1181#FROM named_places
1182#WHERE name = 'Goose Island';
1183
1184--echo # Conformance Item T14
1185# TODO: ST_Envelope( ) alias
1186# FIXME: we get anticlockwise, GIS suggests clockwise
1187SELECT ST_AsText(ST_Envelope(boundary))
1188FROM named_places
1189WHERE name = 'Goose Island';
1190
1191--echo # Conformance Item T15
1192# TODO: ST_X() alias
1193SELECT ST_X(position)
1194FROM bridges
1195WHERE name = 'Cam Bridge';
1196
1197--echo # Conformance Item T16
1198# TODO: ST_Y() alias
1199SELECT ST_Y(position)
1200FROM bridges
1201WHERE name = 'Cam Bridge';
1202
1203--echo # Conformance Item T17
1204# TODO: ST_StartPoint() alias
1205SELECT ST_AsText(ST_StartPoint(centerline))
1206FROM road_segments
1207WHERE fid = 102;
1208
1209--echo # Conformance Item T18
1210# TODO: ST_EndPoint
1211SELECT ST_AsText(ST_EndPoint(centerline))
1212FROM road_segments
1213WHERE fid = 102;
1214
1215# TODO: WL#2377
1216#--echo # Conformance Item T19
1217# TODO: ST_LineFromWKB() alias
1218#SELECT ST_IsClosed(LineFromWKB(ST_AsBinary(Boundary(boundary)),ST_SRID(boundary)))
1219#FROM named_places
1220#WHERE name = 'Goose Island';
1221
1222# TODO: WL#2377
1223#--echo # Conformance Item T20
1224#SELECT IsRing(LineFromWKB(ST_AsBinary(Boundary(boundary)),ST_SRID(boundary)))
1225#FROM named_places
1226#WHERE name = 'Goose Island';
1227
1228--echo # Conformance Item T21
1229# TODO: ST_Length() alias
1230SELECT ST_Length(centerline)
1231FROM road_segments
1232WHERE fid = 106;
1233
1234--echo # Conformance Item T22
1235# TODO: ST_NumPoints() alias
1236SELECT ST_NumPoints(centerline)
1237FROM road_segments
1238WHERE fid = 102;
1239
1240--echo # Conformance Item T23
1241# TODO: ST_PointN() alias
1242SELECT ST_AsText(ST_PointN(centerline, 1))
1243FROM road_segments
1244WHERE fid = 102;
1245
1246--echo # Conformance Item T24
1247# TODO: ST_Centroid() alias
1248SELECT ST_AsText(ST_Centroid(boundary))
1249FROM named_places
1250WHERE name = 'Goose Island';
1251
1252# TODO: WL#2377
1253#--echo # Conformance Item T25
1254#SELECT MBRContains(boundary, PointOnSurface(boundary))
1255#FROM named_places
1256#WHERE name = 'Goose Island';
1257
1258--echo # Conformance Item T26
1259# TODO: ST_Area() alias
1260SELECT ST_Area(boundary)
1261FROM named_places
1262WHERE name = 'Goose Island';
1263
1264--echo # Conformance Item T27
1265# TODO: ST_ExteriorRing() alias
1266SELECT ST_AsText(ST_ExteriorRing(shore))
1267FROM lakes
1268WHERE name = 'Blue Lake';
1269
1270--echo # Conformance Item T28
1271# TODO: ST_NumInteriorRings() alias
1272SELECT ST_NumInteriorRings(shore)
1273FROM lakes
1274WHERE name = 'Blue Lake';
1275
1276--echo # Conformance Item T29
1277# TODO: ST_InteriorRingN() alias
1278SELECT ST_AsText(ST_InteriorRingN(shore, 1))
1279FROM lakes
1280WHERE name = 'Blue Lake';
1281
1282--echo # Conformance Item T30
1283# TODO: ST_NumGeometries() alias
1284SELECT ST_NumGeometries(centerlines)
1285FROM divided_routes
1286WHERE name = 'Route 75';
1287
1288--echo # Conformance Item T31
1289# TODO: ST_GeometryN() alias
1290SELECT ST_AsText(ST_GeometryN(centerlines, 2))
1291FROM divided_routes
1292WHERE name = 'Route 75';
1293
1294--echo # Conformance Item T32
1295# TODO: ST_IsClosed() alias
1296SELECT ST_IsClosed(centerlines)
1297FROM divided_routes
1298WHERE name = 'Route 75';
1299
1300--echo # Conformance Item T33
1301# TODO: ST_Length() alias
1302SELECT ST_Length(centerlines)
1303FROM divided_routes
1304WHERE name = 'Route 75';
1305
1306--echo # Conformance Item T34
1307# TODO: ST_Centroid() alias
1308SELECT ST_AsText(ST_Centroid(shores))
1309FROM ponds
1310WHERE fid = 120;
1311
1312# TODO: WL#2377
1313#--echo # Conformance Item T35
1314#SELECT MBRContains(shores, PointOnSurface(shores))
1315#FROM ponds
1316#WHERE fid = 120;
1317
1318--echo # Conformance Item T36
1319# TODO: ST_Area() alias
1320SELECT ST_Area(shores)
1321FROM ponds
1322WHERE fid = 120;
1323
1324--echo # Conformance Item T37
1325# TODO: ST_PolyFromText() alias
1326# --error ER_GIS_DIFFERENT_SRIDS
1327SELECT ST_Equals(boundary,
1328ST_PolyFromText('POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )',1))
1329FROM named_places
1330WHERE name = 'Goose Island';
1331
1332--echo # Conformance Item T37
1333--echo # Geometry arguments' SRIDs must be identical.
1334SELECT ST_Equals(boundary,
1335ST_PolyFromText('POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )',101))
1336FROM named_places
1337WHERE name = 'Goose Island';
1338
1339
1340--echo # Conformance Item T38
1341SELECT ST_Disjoint(centerlines, boundary)
1342FROM divided_routes, named_places
1343WHERE divided_routes.name = 'Route 75'
1344AND named_places.name = 'Ashton';
1345
1346--echo # Conformance Item T39
1347SELECT ST_Touches(centerline, shore)
1348FROM streams, lakes
1349WHERE streams.name = 'Cam Stream'
1350AND lakes.name = 'Blue Lake';
1351
1352# FIXME: wrong result: get 0, expected 1
1353#--echo # Conformance Item T40
1354#SELECT ST_Within(boundary, footprint)
1355#FROM named_places, buildings
1356#WHERE named_places.name = 'Ashton'
1357#AND buildings.address = '215 Main Street';
1358
1359# FIXME: wrong result: get 0, expected 1
1360#--echo # Conformance Item T41
1361#SELECT ST_Overlaps(forests.boundary, named_places.boundary)
1362#FROM forests, named_places
1363#WHERE forests.name = 'Green Forest'
1364#AND named_places.name = 'Ashton';
1365
1366--echo # Conformance Item T42
1367# FIXME: TODO: ST_Crosses() alias
1368SELECT ST_Crosses(road_segments.centerline, divided_routes.centerlines)
1369FROM road_segments, divided_routes
1370WHERE road_segments.fid = 102
1371AND divided_routes.name = 'Route 75';
1372
1373--echo # Conformance Item T43
1374SELECT ST_Intersects(road_segments.centerline, divided_routes.centerlines)
1375FROM road_segments, divided_routes
1376WHERE road_segments.fid = 102
1377AND divided_routes.name = 'Route 75';
1378
1379--echo # Conformance Item T44
1380SELECT ST_Contains(forests.boundary, named_places.boundary)
1381FROM forests, named_places
1382WHERE forests.name = 'Green Forest'
1383AND named_places.name = 'Ashton';
1384
1385# TODO: WL#2377
1386#--echo # Conformance Item T45
1387#SELECT Relate(forests.boundary, named_places.boundary, 'TTTTTTTTT')
1388#FROM forests, named_places
1389#WHERE forests.name = 'Green Forest'
1390#AND named_places.name = 'Ashton';
1391
1392--echo # Conformance Item T46
1393SELECT ST_Distance(position, boundary)
1394FROM bridges, named_places
1395WHERE bridges.name = 'Cam Bridge'
1396AND named_places.name = 'Ashton';
1397
1398# FIXME: wrong result: NULL, expected 12
1399#--echo # Conformance Item T47
1400#SELECT ST_AsText(ST_Intersection(centerline, shore))
1401#FROM streams, lakes
1402#WHERE streams.name = 'Cam Stream'
1403#AND lakes.name = 'Blue Lake';
1404
1405--echo # Conformance Item T48
1406SELECT ST_AsText(ST_Difference(named_places.boundary, forests.boundary))
1407FROM named_places, forests
1408WHERE named_places.name = 'Ashton'
1409AND forests.name = 'Green Forest';
1410
1411#--echo # Conformance Item T49
1412SELECT ST_AsText(ST_Union(shore, boundary))
1413FROM lakes, named_places
1414WHERE lakes.name = 'Blue Lake'
1415AND named_places.name = 'Goose Island';
1416
1417--echo # Conformance Item T50
1418SELECT ST_AsText(ST_SymDifference(shore, boundary))
1419FROM lakes, named_places
1420WHERE lakes.name = 'Blue Lake'
1421AND named_places.name = 'Ashton';
1422
1423--echo # Conformance Item T51
1424SELECT count(*)
1425FROM buildings, bridges
1426WHERE ST_Contains(ST_Buffer(bridges.position, 15.0), buildings.footprint) = 1;
1427
1428# TODO: WL#2377
1429#--echo # Conformance Item T52
1430#SELECT ST_AsText(ConvexHull(shore))
1431#FROM lakes
1432#WHERE lakes.name = 'Blue Lake';
1433
1434DROP DATABASE gis_ogs;
1435
1436--echo #
1437--echo # Bug#13362660 ASSERTION `FIELD_POS < FIELD_COUNT' FAILED. IN PROTOCOL_TEXT::STORE
1438--echo #
1439
1440--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
1441SELECT ST_Union('', ''), md5(1);
1442