1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
|
#********************************************************
# wl6455: GIS Datatypes covers the following tests.
# DDL: ALTER PRIMARY, DROP KEY,INDEX,COLUMN TYPE etc
# INSERT/SELECT operations with WKT & WKB functions
# SELECT/DELETE/UPDATE with =,>,< predicate conditions
# Datatypes with Procedure (IN/INOUT/OUT,Cursors,Trigger)
# Datatypes with Aggregate functions
# File Formts Compressed & Dynamic
# All Geometric functions.
#********************************************************
--source include/have_geometry.inc
--source include/have_innodb.inc
--source include/have_partition.inc
SET default_storage_engine=InnoDB;
SET innodb_strict_mode=OFF;
#
# Spatial objects
#
CREATE TABLE gis_point (fid INTEGER NOT NULL PRIMARY KEY, g POINT) ENGINE=InnoDB;
CREATE TABLE gis_line (fid INTEGER NOT NULL PRIMARY KEY, g LINESTRING) ENGINE=InnoDB;
CREATE TABLE gis_polygon (fid INTEGER NOT NULL PRIMARY KEY, g POLYGON) ENGINE=InnoDB;
CREATE TABLE gis_multi_point (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOINT) ENGINE=InnoDB;
CREATE TABLE gis_multi_line (fid INTEGER NOT NULL PRIMARY KEY, g MULTILINESTRING) ENGINE=InnoDB;
CREATE TABLE gis_multi_polygon (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOLYGON) ENGINE=InnoDB;
CREATE TABLE gis_geometrycollection (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRYCOLLECTION) ENGINE=InnoDB;
CREATE TABLE gis_geometry (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRY) ENGINE=InnoDB;
SHOW FIELDS FROM gis_point;
SHOW FIELDS FROM gis_line;
SHOW FIELDS FROM gis_polygon;
SHOW FIELDS FROM gis_multi_point;
SHOW FIELDS FROM gis_multi_line;
SHOW FIELDS FROM gis_multi_polygon;
SHOW FIELDS FROM gis_geometrycollection;
SHOW FIELDS FROM gis_geometry;
--echo #INSERT using all WKT & WKB functions
INSERT INTO gis_point VALUES
(101, ST_PointFromText('POINT(10 10)')),
(102, ST_PointFromText('POINT(20 10)')),
(103, ST_PointFromText('POINT(20 20)')),
(104, ST_PointFromWKB(ST_AsWKB(ST_PointFromText('POINT(10 20)'))));
INSERT INTO gis_line VALUES
(105, ST_LineFromText('LINESTRING(0 0,0 10,10 0)')),
(106, ST_LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)')),
(107, ST_LineStringFromWKB(ST_AsWKB(LineString(Point(10, 10), Point(40, 10)))));
INSERT INTO gis_polygon VALUES
(108, ST_PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')),
(109, ST_PolyFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10))')),
(110, ST_PolyFromWKB(ST_AsWKB(Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0))))));
INSERT INTO gis_multi_point VALUES
(111, ST_MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)')),
(112, ST_MPointFromText('MULTIPOINT(1 1,11 11,11 21,21 21)')),
(113, ST_MPointFromWKB(ST_AsWKB(MultiPoint(Point(3, 6), Point(4, 10)))));
INSERT INTO gis_multi_line VALUES
(114, ST_MultiLineStringFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))')),
(115, ST_MLineFromText('MULTILINESTRING((10 48,10 21,10 0))')),
(116, ST_MLineFromWKB(ST_AsWKB(MultiLineString(LineString(Point(1, 2), Point(3, 5)), LineString(Point(2, 5), Point(5, 8), Point(21, 7))))));
INSERT INTO gis_multi_polygon VALUES
(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)))')),
(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)))')),
(119, ST_MPolyFromWKB(ST_AsWKB(MultiPolygon(Polygon(LineString(Point(0, 3), Point(3, 3), Point(3, 0), Point(0, 3)))))));
INSERT INTO gis_geometrycollection VALUES
(120, ST_GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')),
(121, ST_GeometryCollectionFromText('GEOMETRYCOLLECTION(POINT(10 10), LINESTRING(10 10,20 20))')),
(122, ST_GeometryFromWKB(ST_AsWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9))))));
--echo #check INSERT using SELECT query
INSERT into gis_geometry SELECT * FROM gis_point;
INSERT into gis_geometry SELECT * FROM gis_line;
INSERT into gis_geometry SELECT * FROM gis_polygon;
INSERT into gis_geometry SELECT * FROM gis_multi_point;
INSERT into gis_geometry SELECT * FROM gis_multi_line;
INSERT into gis_geometry SELECT * FROM gis_multi_polygon;
INSERT into gis_geometry SELECT * FROM gis_geometrycollection;
--echo #check format coversion functions & spatial values
SELECT fid, ST_AsText(g) FROM gis_point;
SELECT fid, ST_AsText(g) FROM gis_line;
SELECT fid, ST_AsText(g) FROM gis_polygon;
SELECT fid, ST_AsText(g) FROM gis_multi_point;
SELECT fid, ST_AsText(g) FROM gis_multi_line;
SELECT fid, ST_AsText(g) FROM gis_multi_polygon;
SELECT fid, ST_AsText(g) FROM gis_geometrycollection;
SELECT fid, ST_AsText(g) FROM gis_geometry;
--echo #2.1 check DDL functionality on GIS datatypes
CREATE TABLE tab(c1 POINT,c2 LINESTRING,c3 POLYGON,C4 MULTIPOINT,c5 MULTILINESTRING ,
c6 MULTIPOLYGON,c7 GEOMETRYCOLLECTION ,c8 GEOMETRY) ENGINE=InnoDB;
--echo #check information schema for all the columns refer to 14, except POINT which is 15
SELECT sc.name, sc.pos, sc.mtype
FROM information_schema.innodb_sys_columns sc
INNER JOIN information_schema.innodb_sys_tables st
ON sc.TABLE_ID=st.TABLE_ID
WHERE st.NAME='test/tab'
ORDER BY sc.name;
--echo #check Perform convesrion before INSERT using WKT functions
SET @c1=ST_PointFromText('POINT(10 10)');
SET @c2=ST_LineFromText('LINESTRING(10 10,20 20,30 30)');
SET @c3=ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))');
SET @c4=ST_MPointFromText('MULTIPOINT(0 0,5 5,10 10,20 20)');
SET @c5=ST_MLineFromText('MULTILINESTRING((1 1,2 2,3 3),(10 10,20 20,30 30))');
SET @c6=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)))');
SET @c7=ST_GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))');
SET @c8=ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))');
--echo #Insert the spatial values
INSERT INTO tab VALUES(@c1,@c2,@c3,@c4,@c5,@c6,@c7,@c8);
--echo #check index on GIS datatypes
CREATE INDEX idx1 on tab(c2(5) DESC) USING BTREE;
CREATE INDEX idx3 on tab(c3(5) ASC) USING BTREE;
CREATE UNIQUE INDEX idx2 on tab(c8(5) ASC) ;
--echo #check equality predicate on the index columns
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab
WHERE c2=ST_LineFromText('LINESTRING(10 10,20 20,30 30)');
--echo #check index with WKB function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8)
FROM tab WHERE c2=ST_LineStringFromWKB(ST_AsWKB(ST_LineFromText('LINESTRING(10 10,20 20,30 30)')));
--echo #check index with WKT function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab
WHERE c3=ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))');
--echo #check index with WKB function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8)
FROM tab
WHERE c3=ST_PolyFromWKB(ST_AsWkB(ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))')));
--echo #check index with WKT function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab
WHERE c8=ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))');
--echo #check index with WKB function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8)
FROM tab
WHERE c8=ST_GeometryFromWKB(ST_AsWKB(ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))')));
#--echo #check range predicate on the index columns
#--replace_column 10 #
#--error ER_WRONG_ARGUMENTS
#EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab
#WHERE c2>=ST_LineFromText('LINESTRING(10 10,20 20,30 30)');
#
#--replace_column 10 #
#--error ER_WRONG_ARGUMENTS
#EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab
#WHERE c3>=ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))');
#
#--replace_column 10 #
#--error ER_WRONG_ARGUMENTS
#EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab
#WHERE c8>=ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))');
--echo #check index with DELETE operation
--replace_column 10 #
EXPLAIN DELETE FROM tab
WHERE c8=ST_GeometryFromWKB(ST_AsWKB(ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))')));
--echo #check the spatial values
SELECT ST_AsText(c1) FROM tab;
SELECT ST_AsText(c2) FROM tab;
SELECT ST_AsText(c3) FROM tab;
SELECT ST_AsText(c4) FROM tab;
SELECT ST_AsText(c5) FROM tab;
SELECT ST_AsText(c6) FROM tab;
SELECT ST_AsText(c7) FROM tab;
SELECT ST_AsText(c8) From tab;
--echo #check by modify the column type
ALTER TABLE tab MODIFY COLUMN c1 Geometry;
ALTER TABLE tab MODIFY COLUMN c2 Geometry;
ALTER TABLE tab MODIFY COLUMN c3 Geometry;
ALTER TABLE tab MODIFY COLUMN c4 Geometry;
ALTER TABLE tab MODIFY COLUMN c5 Geometry;
ALTER TABLE tab MODIFY COLUMN c6 Geometry;
ALTER TABLE tab MODIFY COLUMN c7 Geometry;
--echo #check column datatypes
SHOW FIELDS FROM tab;
--echo #check the data after modify
SELECT ST_AsText(c1) FROM tab;
SELECT ST_AsText(c2) FROM tab;
SELECT ST_AsText(c3) FROM tab;
SELECT ST_AsText(c4) FROM tab;
SELECT ST_AsText(c5) FROM tab;
SELECT ST_AsText(c6) FROM tab;
SELECT ST_AsText(c7) FROM tab;
SELECT ST_AsText(c8) From tab;
--echo #check by modify the column type
ALTER TABLE tab MODIFY COLUMN c1 POINT;
ALTER TABLE tab MODIFY COLUMN c2 LINESTRING;
ALTER TABLE tab MODIFY COLUMN c3 POLYGON;
ALTER TABLE tab MODIFY COLUMN c4 MULTIPOINT;
ALTER TABLE tab MODIFY COLUMN c5 MULTILINESTRING;
ALTER TABLE tab MODIFY COLUMN c6 MULTIPOLYGON;
ALTER TABLE tab MODIFY COLUMN c7 GEOMETRYCOLLECTION;
--echo #check column datatypes
SHOW FIELDS FROM tab;
--echo #check the data after modify
SELECT ST_AsText(c1) FROM tab;
SELECT ST_AsText(c2) FROM tab;
SELECT ST_AsText(c3) FROM tab;
SELECT ST_AsText(c4) FROM tab;
SELECT ST_AsText(c5) FROM tab;
SELECT ST_AsText(c6) FROM tab;
SELECT ST_AsText(c7) FROM tab;
SELECT ST_AsText(c8) From tab;
--echo #check change the column type
ALTER TABLE tab MODIFY COLUMN c1 BLOB;
--echo #check column datatypes
SHOW CREATE TABLE tab;
--echo #check the data after modify
SELECT ST_AsText(c1) FROM tab;
--echo #change the column name
ALTER TABLE tab CHANGE COLUMN c1 c0 GEOMETRY ;
--echo #check column datatypes
SHOW FIELDS FROM tab;
--echo #add primary key
ALTER TABLE tab ADD PRIMARY KEY pk2(c8(5));
--echo #check columns
SHOW FIELDS FROM tab;
--echo #drop key
ALTER TABLE tab DROP PRIMARY KEY;
--echo #check columns
SHOW FIELDS FROM tab;
--echo #cleanup the table
TRUNCATE TABLE tab;
--echo #check with procedures
delimiter |;
--echo #crate proc with INOUT params
CREATE PROCEDURE geom_insert(IN c1 POINT,IN c2 LINESTRING,IN c3 POLYGON,
IN c4 MULTIPOINT,IN c5 MULTILINESTRING, IN c6 MULTIPOLYGON,IN c7 GEOMETRYCOLLECTION,
IN c8 GEOMETRY)
BEGIN
INSERT INTO tab VALUES(@c1,@c2,@c3,@c4,@c5,@c6,@c7,@c8);
END |
delimiter ;|
--echo #set the spatial values
SET @c1=ST_PointFromText('POINT(10 10)');
SET @c2=ST_LineFromText('LINESTRING(10 10,20 20,30 30)');
SET @c3=ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))');
SET @c4=ST_MPointFromText('MULTIPOINT(0 0,5 5,10 10,20 20)');
SET @c5=ST_MLineFromText('MULTILINESTRING((1 1,2 2,3 3),(10 10,20 20,30 30))');
SET @c6=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)))');
SET @c7=ST_GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))');
SET @c8=ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))');
--echo #call the proc
CALL geom_insert(@c1,@c2,@c3,@c4,@c5,@c6,@c7,@c8);
--echo #check the values ofter proc call
SELECT ST_AsText(c0) FROM tab;
SELECT ST_AsText(c2) FROM tab;
SELECT ST_AsText(c3) FROM tab;
SELECT ST_AsText(c4) FROM tab;
SELECT ST_AsText(c5) FROM tab;
SELECT ST_AsText(c6) FROM tab;
SELECT ST_AsText(c7) FROM tab;
SELECT ST_AsText(c8) From tab;
--echo #set the input spatial value
SET @c9=ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))');
delimiter |;
--echo #crate a proc with INOUT params and pass a value.
CREATE PROCEDURE geominout(INOUT c9 GEOMETRY)
BEGIN
SELECT ST_AsText(@c9);
SET c9=ST_GeomCollFromText('GeometryCollection(Point(10 10),LineString(20 20, 30 30))');
END|
delimiter ;|
--echo #call the proc and then change the spatial value of c8
CALL geominout(@c9);
--echo #now check the out spatial values should be changed to new values
SELECT ST_AsText(@c9);
#check GIS datatype with Triggers
--echo #delete the records
TRUNCATE TABLE tab;
--echo #create another table same as tab
CREATE TABLE tab2 AS SELECT * FROM tab;
--echo #check the table definition
SHOW CREATE TABLE tab2;
delimiter |;
--echo #create a tigger and populate the values into tab2
CREATE TRIGGER geom_trigger AFTER INSERT ON tab
FOR EACH ROW
BEGIN
INSERT INTO tab2 VALUES (@c1,@c2,@c3,@c4,@c5,@c6,@c7,@c8);
END|
delimiter ;|
--echo #set the spatial values
SET @c1=ST_PointFromText('POINT(10 10)');
SET @c2=ST_LineFromText('LINESTRING(10 10,20 20,30 30)');
SET @c3=ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))');
SET @c4=ST_MPointFromText('MULTIPOINT(0 0,5 5,10 10,20 20)');
SET @c5=ST_MLineFromText('MULTILINESTRING((1 1,2 2,3 3),(10 10,20 20,30 30))');
SET @c6=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)))');
SET @c7=ST_GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))');
SET @c8=ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))');
--echo #Insert the spatial values
INSERT INTO tab VALUES(@c1,@c2,@c3,@c4,@c5,@c6,@c7,@c8);
--echo #check the values whether populated
SELECT ST_AsText(c0) FROM tab2;
SELECT ST_AsText(c2) FROM tab2;
SELECT ST_AsText(c3) FROM tab2;
SELECT ST_AsText(c4) FROM tab2;
SELECT ST_AsText(c5) FROM tab2;
SELECT ST_AsText(c6) FROM tab2;
SELECT ST_AsText(c7) FROM tab2;
SELECT ST_AsText(c8) From tab2;
--echo #check Cursor with Geometry
delimiter |;
CREATE PROCEDURE geom_cursor()
BEGIN
DECLARE v GEOMETRY;
DECLARE c CURSOR FOR SELECT c8 FROM tab2;
OPEN c;
FETCH c INTO v;
CLOSE c;
SELECT ST_AsText(v);
END|
delimiter ;|
--echo # the following line was commented due the Bug#16282246
--echo # Once it is fixed, the comment will be removed.
--echo # right now bug fixing date is unknown.
#CALL geom_cursor();
--echo check self join
SELECT ST_AsText(a.c0),ST_AsText(a.c2),ST_AsText(a.c3)
FROM tab a,tab2 b WHERE a.c0=b.c0 AND a.c2=b.c2
AND a.c3=b.c3 AND a.c4=b.c4 AND a.c5=b.c5 AND a.c6=b.c6
AND a.c7=b.c7 AND a.c8=b.c8;
--echo #check equi join
SELECT ST_AsText(a.c2),ST_AsText(b.c2) FROM tab a,tab2 b WHERE a.c2=b.c2;
--echo #check DELETE stmt with Where clause and a constant predicate
DELETE FROM tab
Where c8=c8=ST_GeometryFromWKB(ST_AsWKB(ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))')));
--echo #check the data, should 0
SELECT COUNT(*) FROM tab;
--echo #check UPDATE stmt with Where clause and a constant predicate
SET @c8=ST_GeomCollFromText('GeometryCollection(Point(10 10),LineString(20 20, 30 30))');
UPDATE tab2 SET c8=@c8
WHERE c2=ST_LineStringFromWKB(ST_AsWKB(ST_LineFromText('LINESTRING(10 10,20 20,30 30)')));
--echo #check the column should be modified to LINESTRING(10 10,20 20,30 30)
SELECT ST_AsText(c8) From tab2;
--echo #check GIS datatypes with aggregate functions
SELECT COUNT(ST_AsText(g)) FROM gis_point;
SELECT COUNT(ST_AsText(g)) FROM gis_line;
SELECT COUNT(ST_AsText(g)) FROM gis_polygon;
SELECT COUNT(ST_AsText(g)) FROM gis_multi_point;
SELECT COUNT(ST_AsText(g)) FROM gis_multi_line;
SELECT COUNT(ST_AsText(g)) FROM gis_multi_polygon;
SELECT COUNT(ST_AsText(g)) FROM gis_geometrycollection;
SELECT COUNT(ST_AsText(g)) FROM gis_geometry;
SELECT SUM(ST_AsText(g)) FROM gis_point;
SELECT SUM(ST_AsText(g)) FROM gis_line;
SELECT AVG(ST_AsText(g)) FROM gis_polygon;
--echo #here it show some string value no meaning
SELECT MAX(ST_AsText(g)) FROM gis_multi_point;
--echo #here it show some string value no meaning
SELECT MIN(ST_AsText(g)) FROM gis_multi_line;
SELECT STD(ST_AsText(g)) FROM gis_multi_polygon;
SELECT COUNT(ST_AsText(g)) FROM gis_geometrycollection;
SELECT AVG(ST_AsText(g)) FROM gis_geometry;
--disable_warnings
--echo #check Datatypes with compression tables
CREATE TABLE tab3(c1 POINT,c2 LINESTRING,c3 POLYGON,C4 MULTIPOINT,c5 MULTILINESTRING ,
c6 MULTIPOLYGON,c7 GEOMETRYCOLLECTION ,c8 GEOMETRY) ENGINE=InnoDB
KEY_BLOCK_SIZE=8 ROW_FORMAT=COMPRESSED;
--echo #check file format
SHOW CREATE TABLE tab3;
ALTER TABLE tab3 KEY_BLOCK_SIZE=16 ROW_FORMAT=Dynamic;
--echo #check file format
SHOW CREATE TABLE tab3;
--echo #check information schema for all the columns refer to 14, except POINT which is 15
SELECT sc.name, sc.pos, sc.mtype
FROM information_schema.innodb_sys_columns sc
INNER JOIN information_schema.innodb_sys_tables st
ON sc.TABLE_ID=st.TABLE_ID
WHERE st.NAME='test/tab3'
ORDER BY sc.name;
--echo #check Perform convesrion before INSERT using WKT functions
SET @c1=ST_PointFromText('POINT(10 10)');
SET @c2=ST_LineFromText('LINESTRING(10 10,20 20,30 30)');
SET @c3=ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))');
SET @c4=ST_MPointFromText('MULTIPOINT(0 0,5 5,10 10,20 20)');
SET @c5=ST_MLineFromText('MULTILINESTRING((1 1,2 2,3 3),(10 10,20 20,30 30))');
SET @c6=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)))');
SET @c7=ST_GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))');
SET @c8=ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))');
--echo #Insert the spatial values
INSERT INTO tab3 VALUES(@c1,@c2,@c3,@c4,@c5,@c6,@c7,@c8);
--echo #check index on GIS datatypes
CREATE INDEX idx1 on tab3(c2(5) DESC) USING BTREE;
CREATE INDEX idx3 on tab3(c3(5) ASC) USING BTREE;
CREATE UNIQUE INDEX idx2 on tab3(c8(5) ASC) ;
--enable_warnings
--echo #check equality predicate on the index columns
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab3
WHERE c2=ST_LineFromText('LINESTRING(10 10,20 20,30 30)');
--echo #check index with WKB function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8)
FROM tab3 WHERE c2=ST_LineStringFromWKB(ST_AsWKB(ST_LineFromText('LINESTRING(10 10,20 20,30 30)')));
--echo #check index with WKT function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab3
WHERE c3=ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))');
--echo #check index with WKB function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8)
FROM tab3
WHERE c3=ST_PolyFromWKB(ST_AsWkB(ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))')));
--echo #check index with WKT function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab3
WHERE c8=ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))');
--echo #check index with WKB function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8)
FROM tab3
WHERE c8=ST_GeometryFromWKB(ST_AsWKB(ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))')));
# --echo #check range predicate on the index columns
# --replace_column 10 #
# --error ER_WRONG_ARGUMENTS
# EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab3
# WHERE c2>=ST_LineFromText('LINESTRING(10 10,20 20,30 30)');
#
# --replace_column 10 #
# --error ER_WRONG_ARGUMENTS
# EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab3
# WHERE c3>=ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))');
# --replace_column 10 #
# --error ER_WRONG_ARGUMENTS
# EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab3
# WHERE c8>=ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))');
--echo #check index with DELETE operation
--replace_column 10 #
EXPLAIN DELETE FROM tab3
WHERE c8=ST_GeometryFromWKB(ST_AsWKB(ST_GeomCollFromText('GeometryCollection(Point(1 1),LineString(2 2, 3 3))')));
--echo #check the spatial values
SELECT ST_AsText(c1) FROM tab3;
SELECT ST_AsText(c2) FROM tab3;
SELECT ST_AsText(c3) FROM tab3;
SELECT ST_AsText(c4) FROM tab3;
SELECT ST_AsText(c5) FROM tab3;
SELECT ST_AsText(c6) FROM tab3;
SELECT ST_AsText(c7) FROM tab3;
SELECT ST_AsText(c8) From tab3;
--echo #check with Row_format = Dynamic
--disable_warnings
ALTER TABLE tab3 ROW_FORMAT=Dynamic;
--enable_warnings
--echo #check file format
SHOW CREATE TABLE tab3;
--echo #check index with WKB function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8)
FROM tab3 WHERE c2=ST_LineStringFromWKB(ST_AsWKB(ST_LineFromText('LINESTRING(10 10,20 20,30 30)')));
--echo #check index with WKT function
--replace_column 10 #
EXPLAIN SELECT ST_ASText(c1),ST_AsText(c2),ST_AsText(c8) FROM tab3
WHERE c3=ST_PolyFromText('POLYGON((0 0,5 5,10 10,15 15,0 0),(10 10,20 20,30 30,40 40,10 10))');
--echo #check the Geometry property functions
SELECT fid, ST_Dimension(g) FROM gis_geometry;
SELECT fid, ST_GeometryType(g) FROM gis_geometry;
SELECT fid, ST_IsEmpty(g) FROM gis_geometry;
SELECT fid, ST_AsText(ST_Envelope(g)) FROM gis_geometry;
--replace_column 10 #
explain extended select ST_Dimension(g), ST_GeometryType(g), ST_IsEmpty(g), ST_AsText(ST_Envelope(g)) from gis_geometry;
--echo #check Geometry point functions
SELECT fid, ST_X(g) FROM gis_point;
SELECT fid, ST_Y(g) FROM gis_point;
--replace_column 10 #
explain extended select ST_X(g),ST_Y(g) FROM gis_point;
SELECT fid, ST_AsText(ST_StartPoint(g)) FROM gis_line;
SELECT fid, ST_AsText(ST_EndPoint(g)) FROM gis_line;
SELECT fid, ST_Length(g) FROM gis_line;
SELECT fid, ST_NumPoints(g) FROM gis_line;
SELECT fid, ST_AsText(ST_PointN(g, 2)) FROM gis_line;
SELECT fid, ST_IsClosed(g) FROM gis_line;
--replace_column 10 #
explain 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;
SELECT fid, ST_AsText(ST_Centroid(g)) FROM gis_polygon;
SELECT fid, ST_Area(g) FROM gis_polygon;
SELECT fid, ST_AsText(ST_ExteriorRing(g)) FROM gis_polygon;
SELECT fid, ST_NumInteriorRings(g) FROM gis_polygon;
SELECT fid, ST_AsText(ST_InteriorRingN(g, 1)) FROM gis_polygon;
--replace_column 10 #
explain 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;
SELECT fid, ST_IsClosed(g) FROM gis_multi_line;
SELECT fid, ST_AsText(ST_Centroid(g)) FROM gis_multi_polygon;
SELECT fid, ST_Area(g) FROM gis_multi_polygon;
SELECT fid, ST_NumGeometries(g) from gis_multi_point;
SELECT fid, ST_NumGeometries(g) from gis_multi_line;
SELECT fid, ST_NumGeometries(g) from gis_multi_polygon;
SELECT fid, ST_NumGeometries(g) from gis_geometrycollection;
--replace_column 10 #
explain extended SELECT fid, ST_NumGeometries(g) from gis_multi_point;
SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_point;
SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_line;
SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_polygon;
SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_geometrycollection;
SELECT fid, ST_AsText(ST_GeometryN(g, 1)) from gis_geometrycollection;
--replace_column 10 #
explain extended SELECT fid, ST_AsText(ST_GeometryN(g, 2)) from gis_multi_point;
SELECT g1.fid as first, g2.fid as second,
MBRWithin(g1.g, g2.g) as w, MBRContains(g1.g, g2.g) as c, MBROverlaps(g1.g, g2.g) as o,
MBREquals(g1.g, g2.g) as e, MBRDisjoint(g1.g, g2.g) as d, ST_Touches(g1.g, g2.g) as t,
MBRIntersects(g1.g, g2.g) as i, ST_Crosses(g1.g, g2.g) as r
FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second;
--replace_column 10 #
explain extended SELECT g1.fid as first, g2.fid as second,
MBRWithin(g1.g, g2.g) as w, MBRContains(g1.g, g2.g) as c, MBROverlaps(g1.g, g2.g) as o,
MBREquals(g1.g, g2.g) as e, MBRDisjoint(g1.g, g2.g) as d, ST_Touches(g1.g, g2.g) as t,
MBRIntersects(g1.g, g2.g) as i, ST_Crosses(g1.g, g2.g) as r
FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second;
--echo # check support of Foreign Key constraint
CREATE TABLE parent (id GEOMETRY NOT NULL,PRIMARY KEY (id(10))) ENGINE=INNODB;
--error ER_CANT_CREATE_TABLE
CREATE TABLE child (id GEOMETRY, parent_id GEOMETRY,
INDEX par_ind (parent_id(10)),
FOREIGN KEY (parent_id(10)) REFERENCES parent(id)
ON DELETE CASCADE
) ENGINE=INNODB;
--echo #check partition table support
--error 1178
CREATE TABLE emp2(
id GEOMETRY NOT NULL,
store_name VARCHAR(30),
parts VARCHAR(30),
store_id GEOMETRY
)
PARTITION BY LIST(store_id) (
PARTITION pNorth VALUES IN (10,20,30) ,
PARTITION pEast VALUES IN (40,50,60) ,
PARTITION pWest VALUES IN (70,80,100)
);
--echo #check start transaction commit & Rollback
START TRANSACTION;
DELETE FROM tab3;
ROLLBACK;
SELECT COUNT(*) FROM tab3;
START TRANSACTION;
DELETE FROM tab3;
COMMIT;
SELECT COUNT(*) FROM tab3;
DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point;
DROP TABLE gis_multi_line, gis_multi_polygon;
DROP TABLE gis_geometrycollection, gis_geometry;
DROP TABLE tab,tab2,tab3,parent;
DROP PROCEDURE geominout;
DROP PROCEDURE geom_insert;
DROP PROCEDURE geom_cursor;
|