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
|
#
# Test when the POINT is on B-TREE
#
CREATE TABLE t1(fid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, p POINT, KEY(p)) ENGINE=InnoDB;
INSERT INTO t1 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)'))));
SELECT ST_AsText(p) FROM t1;
ST_AsText(p)
POINT(10 10)
POINT(20 10)
POINT(20 20)
POINT(10 20)
SELECT ST_AsText(p) FROM t1 WHERE p = ST_PointFromText('POINT(20 20)');
ST_AsText(p)
POINT(20 20)
INSERT INTO t1 VALUES
(201, ST_PointFromText('POINT(100.32374832 101.23741821)')),
(202, ST_PointFromText('POINT(102.43287328 100.23489233)')),
(203, ST_PointFromText('POINT(101.43284962 100.45892392)')),
(204, ST_PointFromWKB(ST_AsWKB(ST_PointFromText('POINT(103.43718640 105.248206478)')))),
(205, ST_PointFromText('POINT(101.43284962 100.45892392)')),
(206, ST_PointFromWKB(ST_AsWKB(ST_PointFromText('POINT(103.43718640 105.248206478)'))));
SELECT ST_AsText(p), COUNT(*) FROM t1 GROUP BY p;
ST_AsText(p) COUNT(*)
POINT(10 10) 1
POINT(10 20) 1
POINT(20 10) 1
POINT(20 20) 1
POINT(101.43284962 100.45892392) 2
POINT(100.32374832 101.23741821) 1
POINT(102.43287328 100.23489233) 1
POINT(103.4371864 105.248206478) 2
TRUNCATE t1;
SELECT * FROM t1;
fid p
INSERT INTO t1(p) VALUES(ST_PointFromText('POINT(10 10)')),
(ST_PointFromText('POINT(10 20)')),
(ST_PointFromText('POINT(10 40)')),
(ST_PointFromText('POINT(10 60)')),
(ST_PointFromText('POINT(20 15)')),
(ST_PointFromText('POINT(30 10)')),
(ST_PointFromText('POINT(40 10)')),
(ST_PointFromText('POINT(50 10)')),
(ST_PointFromText('POINT(60 5)')),
(ST_PointFromText('POINT(60 10)')),
(ST_PointFromText('POINT(60 20)')),
(ST_PointFromText('POINT(60 100)')),
(ST_PointFromText('POINT(100 100)')),
(ST_PointFromText('POINT(80 60)')),
(ST_PointFromText('POINT(81 50)')),
(ST_PointFromText('POINT(82 70)')),
(ST_PointFromText('POINT(83 30)')),
(ST_PointFromText('POINT(20 100)')),
(ST_PointFromText('POINT(150 2000)')),
(ST_PointFromText('POINT(109 230)')),
(ST_PointFromText('POINT(280 250)')),
(ST_PointFromText('POINT(176 175)')),
(ST_PointFromText('POINT(200 10)')),
(NULL),
(NULL);
SELECT ST_AsText(p) FROM t1;
ST_AsText(p)
POINT(10 10)
POINT(10 20)
POINT(10 40)
POINT(10 60)
POINT(20 15)
POINT(30 10)
POINT(40 10)
POINT(50 10)
POINT(60 5)
POINT(60 10)
POINT(60 20)
POINT(60 100)
POINT(100 100)
POINT(80 60)
POINT(81 50)
POINT(82 70)
POINT(83 30)
POINT(20 100)
POINT(150 2000)
POINT(109 230)
POINT(280 250)
POINT(176 175)
POINT(200 10)
NULL
NULL
SELECT COUNT(*) FROM t1;
COUNT(*)
25
SELECT ST_AsText(p) FROM t1;
ST_AsText(p)
POINT(10 10)
POINT(10 20)
POINT(10 40)
POINT(10 60)
POINT(20 15)
POINT(30 10)
POINT(40 10)
POINT(50 10)
POINT(60 5)
POINT(60 10)
POINT(60 20)
POINT(60 100)
POINT(100 100)
POINT(80 60)
POINT(81 50)
POINT(82 70)
POINT(83 30)
POINT(20 100)
POINT(150 2000)
POINT(109 230)
POINT(280 250)
POINT(176 175)
POINT(200 10)
NULL
NULL
SELECT COUNT(*) FROM t1;
COUNT(*)
25
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
INSERT INTO t1(p) SELECT p FROM t1;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT COUNT(*) FROM t1;
COUNT(*)
102400
SELECT ST_AsText(p), COUNT(*) FROM t1 GROUP BY p;
ST_AsText(p) COUNT(*)
NULL 8192
POINT(10 10) 4096
POINT(10 20) 4096
POINT(10 40) 4096
POINT(10 60) 4096
POINT(20 15) 4096
POINT(20 100) 4096
POINT(30 10) 4096
POINT(40 10) 4096
POINT(50 10) 4096
POINT(60 5) 4096
POINT(60 10) 4096
POINT(60 20) 4096
POINT(60 100) 4096
POINT(80 60) 4096
POINT(100 100) 4096
POINT(176 175) 4096
POINT(200 10) 4096
POINT(81 50) 4096
POINT(109 230) 4096
POINT(82 70) 4096
POINT(280 250) 4096
POINT(83 30) 4096
POINT(150 2000) 4096
SELECT COUNT(*) FROM t1 WHERE p = ST_PointFromText('POINT(280 250)');
COUNT(*)
4096
DELETE FROM t1 WHERE p = ST_PointFromText('POINT(280 250)');
SELECT COUNT(*) FROM t1 WHERE p = ST_PointFromText('POINT(280 250)');
COUNT(*)
0
SELECT COUNT(*) FROM t1 WHERE p = ST_PointFromText('POINT(60 5)');
COUNT(*)
4096
DELETE FROM t1 WHERE P = ST_PointFromText('POINT(60 5)');
SELECT COUNT(*) FROM t1 WHERE p = ST_PointFromText('POINT(60 5)');
COUNT(*)
0
SELECT ST_AsText(p), COUNT(*) FROM t1 WHERE p = ST_PointFromText('POINT(60 10)') OR p = ST_PointFromText('POINT(60 20)') OR p = ST_PointFromText('POINT(60 30)') GROUP BY p;
ST_AsText(p) COUNT(*)
POINT(60 10) 4096
POINT(60 20) 4096
UPDATE t1 SET p = ST_PointFromText('POINT(101 102)') WHERE p = ST_PointFromText('POINT(60 10)') OR p = ST_PointFromText('POINT(60 20)') OR p = ST_PointFromText('POINT(60 30)');
SELECT ST_AsText(p), COUNT(*) FROM t1 WHERE p = ST_PointFromText('POINT(60 10)') OR p = ST_PointFromText('POINT(60 20)') OR p = ST_PointFromText('POINT(60 30)') GROUP BY p;
ST_AsText(p) COUNT(*)
SELECT COUNT(*) FROM t1 WHERE p = ST_PointFromText('POINT(101 102)');
COUNT(*)
8192
SELECT COUNT(*) FROM t1 WHERE p IS NULL;
COUNT(*)
8192
UPDATE t1 SET p = ST_PointFromText('POINT(160 160)') WHERE p IS NULL;
SELECT COUNT(*) FROM t1 WHERE p IS NULL;
COUNT(*)
0
SELECT COUNT(*) FROM t1 WHERE p = ST_PointFromText('POINT(160 160)');
COUNT(*)
8192
SELECT ST_AsText(p), COUNT(*) FROM t1 GROUP BY p;
ST_AsText(p) COUNT(*)
POINT(10 10) 4096
POINT(10 20) 4096
POINT(10 40) 4096
POINT(10 60) 4096
POINT(20 15) 4096
POINT(20 100) 4096
POINT(30 10) 4096
POINT(40 10) 4096
POINT(50 10) 4096
POINT(60 100) 4096
POINT(80 60) 4096
POINT(100 100) 4096
POINT(160 160) 8192
POINT(176 175) 4096
POINT(200 10) 4096
POINT(81 50) 4096
POINT(101 102) 8192
POINT(109 230) 4096
POINT(82 70) 4096
POINT(83 30) 4096
POINT(150 2000) 4096
SELECT COUNT(*) FROM t1;
COUNT(*)
94208
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1;
#
# Test when POINT is used in spatial index
#
SET @ls1 = ST_GeomFromText('LINESTRING(0 20, 10 0)');
SET @ls2 = ST_GeomFromText('LINESTRING(0 0, 10 20)');
SET @ls3 = ST_GeomFromText('LINESTRING(20 -40, 21 -42)');
SET @ls4 = ST_GeomFromText('LINESTRING(20 -42, 21 -40)');
SET @poly1 = ST_GeomFromText('POLYGON((2 2, 2 10, 10 10, 10 2, 2 2))');
SET @poly2 = ST_GeomFromText('POLYGON((0 0, -5 0, -4 -1, -6 -15, -3 -15, 0 0))');
SET @poly3 = ST_GeomFromText('POLYGON((10.0 10.0, 20.5 20, 20.5 50, 32.0 64.0, 32.3 64.6, 5 60, 10 10))');
SET @poly4 = ST_GeomFromText('POLYGON((0 10, -10 10, -10 -10, 0 -10, 0 10))');
SET @p1 = ST_PointFromText('POINT(0 0)');
SET @mpoly = ST_GeomFromText('MULTIPOLYGON(((3 3, 3 16, 16 16, 16 3, 3 3)), ((10 10, 10 50, 50 50, 50 10, 10 10)))');
CREATE TABLE gis_point (p1 POINT NOT NULL, p2 POINT NOT NULL, SPATIAL KEY k1 (p1), SPATIAL KEY k2 (p2)) ENGINE=InnoDB;
INSERT INTO gis_point VALUES
(ST_PointFromText('POINT(1 2)'), ST_PointFromText('POINT(-1 -3)')),
(ST_PointFromText('POINT(2 4)'), ST_PointFromText('POINT(-2 -6)')),
(ST_PointFromText('POINT(3 6)'), ST_PointFromText('POINT(-3 -9)')),
(ST_PointFromText('POINT(4 8)'), ST_PointFromText('POINT(-4 -12)')),
(ST_PointFromText('POINT(5 10)'), ST_PointFromText('POINT(-5 -15)')),
(ST_PointFromText('POINT(6 12)'), ST_PointFromText('POINT(-6 -18)')),
(ST_PointFromText('POINT(7 14)'), ST_PointFromText('POINT(-7 -21)')),
(ST_PointFromText('POINT(8 16)'), ST_PointFromText('POINT(0 0)')),
(ST_PointFromText('POINT(9 18)'), ST_PointFromText('POINT(-4 2)')),
(ST_PointFromText('POINT(10 21)'), ST_PointFromText('POINT(-6 3)')),
(ST_PointFromText('POINT(20.5 41)'), ST_PointFromText('POINT(-8 4)')),
(ST_PointFromText('POINT(26.25 57)'), ST_PointFromText('POINT(1 2)')),
(ST_PointFromText('POINT(32.1234 64.2468)'), ST_PointFromText('POINT(-1 -1)'));
'The ORDER BY for spatial index will use filesort'
EXPLAIN SELECT ST_AsText(p1), ST_AsText(p2) FROM gis_point ORDER BY p1, p2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE gis_point ALL NULL NULL NULL NULL # Using filesort
SELECT ST_AsText(p1), ST_AsText(p2) FROM gis_point ORDER BY p1, p2;
ST_AsText(p1) ST_AsText(p2)
POINT(2 4) POINT(-2 -6)
POINT(3 6) POINT(-3 -9)
POINT(4 8) POINT(-4 -12)
POINT(5 10) POINT(-5 -15)
POINT(6 12) POINT(-6 -18)
POINT(7 14) POINT(-7 -21)
POINT(8 16) POINT(0 0)
POINT(9 18) POINT(-4 2)
POINT(10 21) POINT(-6 3)
POINT(1 2) POINT(-1 -3)
POINT(26.25 57) POINT(1 2)
POINT(20.5 41) POINT(-8 4)
POINT(32.1234 64.2468) POINT(-1 -1)
'Try to do IDU on the table and verify the result'
DELETE FROM gis_point WHERE ST_Equals(p2, ST_PointFromText('POINT(-8 4)'));
INSERT INTO gis_point VALUES(ST_PointFromText('POINT(20.5 -41)'), ST_PointFromText('POINT(8 -4)'));
SELECT ST_AsText(p1) AS 'Expect (32.1234 64.2468)' FROM gis_point WHERE ST_TOUCHES(@poly3, p1) AND MBRWithin(p2, @poly4);
Expect (32.1234 64.2468)
POINT(32.1234 64.2468)
UPDATE gis_point SET p1 = ST_PointFromText('POINT(20.5 41)'), p2 = ST_PointFromText('POINT(-8 4)') WHERE ST_Intersection(@ls3, @ls4) = p1;
SELECT ST_AsText(p1) AS 'Expect (32.1234 64.2468) AND (20.5 41)' FROM gis_point WHERE ST_TOUCHES(@poly3, p1) AND MBRWithin(p2, @poly4);
Expect (32.1234 64.2468) AND (20.5 41)
POINT(32.1234 64.2468)
POINT(20.5 41)
CHECK TABLE gis_point;
Table Op Msg_type Msg_text
test.gis_point check status OK
============================================================
Use a trx to test the IDU on the table and verify the result
============================================================
START TRANSACTION;
DELETE FROM gis_point WHERE ST_Equals(p2, ST_PointFromText('POINT(-8 4)'));
INSERT INTO gis_point VALUES(ST_PointFromText('POINT(20.5 -41)'), ST_PointFromText('POINT(8 -4)'));
SELECT ST_AsText(p1) AS 'Expect (32.1234 64.2468)' FROM gis_point WHERE ST_TOUCHES(@poly3, p1) AND MBRWithin(p2, @poly4);
Expect (32.1234 64.2468)
POINT(32.1234 64.2468)
UPDATE gis_point SET p1 = ST_PointFromText('POINT(20.5 49)'), p2 = ST_PointFromText('POINT(-8 4)') WHERE ST_Intersection(@ls3, @ls4) = p1;
SELECT ST_AsText(p1) AS 'Expect (32.1234 64.2468) AND (20.5 49)' FROM gis_point WHERE ST_TOUCHES(@poly3, p1) AND MBRWithin(p2, @poly4);
Expect (32.1234 64.2468) AND (20.5 49)
POINT(32.1234 64.2468)
POINT(20.5 49)
ROLLBACK;
SELECT ST_AsText(p1) AS 'Expect (32.1234 64.2468) AND (20.5 41)' FROM gis_point WHERE ST_TOUCHES(@poly3, p1) AND MBRWithin(p2, @poly4);
Expect (32.1234 64.2468) AND (20.5 41)
POINT(32.1234 64.2468)
POINT(20.5 41)
CHECK TABLE gis_point;
Table Op Msg_type Msg_text
test.gis_point check status OK
=======================================================
Enlarge the table by inserting the same data and verify
=======================================================
INSERT INTO gis_point SELECT * FROM gis_point;
INSERT INTO gis_point SELECT * FROM gis_point;
INSERT INTO gis_point SELECT * FROM gis_point;
INSERT INTO gis_point SELECT * FROM gis_point;
INSERT INTO gis_point SELECT * FROM gis_point;
INSERT INTO gis_point SELECT * FROM gis_point;
INSERT INTO gis_point SELECT * FROM gis_point;
INSERT INTO gis_point SELECT * FROM gis_point;
INSERT INTO gis_point SELECT * FROM gis_point;
INSERT INTO gis_point SELECT * FROM gis_point;
CHECK TABLE gis_point;
Table Op Msg_type Msg_text
test.gis_point check status OK
SELECT COUNT(*), ST_AsText(p1), ST_AsText(p2) FROM gis_point GROUP BY p1, p2;
COUNT(*) ST_AsText(p1) ST_AsText(p2)
1024 POINT(2 4) POINT(-2 -6)
1024 POINT(3 6) POINT(-3 -9)
1024 POINT(4 8) POINT(-4 -12)
1024 POINT(5 10) POINT(-5 -15)
1024 POINT(6 12) POINT(-6 -18)
1024 POINT(7 14) POINT(-7 -21)
1024 POINT(8 16) POINT(0 0)
1024 POINT(9 18) POINT(-4 2)
1024 POINT(10 21) POINT(-6 3)
1024 POINT(1 2) POINT(-1 -3)
1024 POINT(26.25 57) POINT(1 2)
1024 POINT(20.5 41) POINT(-8 4)
1024 POINT(32.1234 64.2468) POINT(-1 -1)
SELECT COUNT(*), ST_AsText(p1) FROM gis_point WHERE ST_Intersection(@ls1, @ls2) = p1 GROUP BY p1;
COUNT(*) ST_AsText(p1)
1024 POINT(5 10)
SELECT COUNT(*), ST_AsText(p1) FROM gis_point WHERE MBRWithin(p1, @poly1) GROUP BY p1;
COUNT(*) ST_AsText(p1)
1024 POINT(3 6)
1024 POINT(4 8)
SELECT COUNT(*), ST_AsText(p2) FROM gis_point WHERE ST_Contains(@poly2, p2) GROUP BY p2;
COUNT(*) ST_AsText(p2)
1024 POINT(0 0)
1024 POINT(-2 -6)
1024 POINT(-3 -9)
1024 POINT(-4 -12)
1024 POINT(-5 -15)
1024 POINT(-1 -3)
1024 POINT(-1 -1)
SELECT COUNT(*), ST_AsText(p2) FROM gis_point WHERE ST_Equals(p2, @p1) GROUP BY p2;
COUNT(*) ST_AsText(p2)
1024 POINT(0 0)
SELECT COUNT(*), ST_AsText(p1) FROM gis_point WHERE ST_TOUCHES(@poly3, p1) AND MBRWithin(p2, @poly4) GROUP BY p1;
COUNT(*) ST_AsText(p1)
1024 POINT(20.5 41)
1024 POINT(32.1234 64.2468)
SELECT COUNT(*), ST_AsText(p1), ST_AsText(p2) FROM gis_point WHERE ST_Contains(@mpoly, p1) GROUP BY p1, p2;
COUNT(*) ST_AsText(p1) ST_AsText(p2)
1024 POINT(3 6) POINT(-3 -9)
1024 POINT(4 8) POINT(-4 -12)
1024 POINT(5 10) POINT(-5 -15)
1024 POINT(6 12) POINT(-6 -18)
1024 POINT(7 14) POINT(-7 -21)
1024 POINT(8 16) POINT(0 0)
1024 POINT(10 21) POINT(-6 3)
1024 POINT(20.5 41) POINT(-8 4)
SELECT COUNT(*), ST_AsText(p1), ST_AsText(p2) FROM gis_point WHERE ST_Contains(@mpoly, p1) AND NOT MBRWithin(p1, @mpoly) GROUP BY p1, p2;
COUNT(*) ST_AsText(p1) ST_AsText(p2)
1024 POINT(3 6) POINT(-3 -9)
======================================================================
Build another new table with the same schema, will insert data from this table to the orignal one
======================================================================
CREATE TABLE p(p1 POINT NOT NULL, p2 POINT NOT NULL, SPATIAL INDEX k1(p2)) ENGINE=InnoDB;
INSERT INTO p VALUES(ST_PointFromText('POINT(1000 -1000)'), ST_PointFromText('POINT(-201 203.56)'));
INSERT INTO p VALUES(ST_PointFromText('POINT(20.5 43.9832)'), ST_PointFromText('POINT(-0 0)'));
INSERT INTO p VALUES(ST_PointFromText('POINT(-4.2 -6.98)'), ST_PointFromText('POINT(-120.5 343.9832)'));
INSERT INTO p SELECT * FROM p WHERE MBRWithin(p1, ST_GeomFromText('POLYGON((0 0, 0 2000, 2000 2000, 2000 -2000, 0 -2000, 0 0))'));
INSERT INTO p SELECT * FROM p WHERE MBRWithin(p1, ST_GeomFromText('POLYGON((0 0, -10 0, -100 -100, 0 -50, 0 0))'));
SELECT COUNT(*), ST_AsText(p1), ST_AsText(p2) FROM p GROUP BY p1, p2;
COUNT(*) ST_AsText(p1) ST_AsText(p2)
2 POINT(1000 -1000) POINT(-201 203.56)
2 POINT(20.5 43.9832) POINT(-0 0)
2 POINT(-4.2 -6.98) POINT(-120.5 343.9832)
INSERT INTO gis_point SELECT * FROM p;
INSERT INTO gis_point SELECT * FROM p;
INSERT INTO gis_point SELECT * FROM p;
INSERT INTO gis_point SELECT * FROM p;
INSERT INTO gis_point SELECT * FROM p;
INSERT INTO gis_point SELECT * FROM p;
INSERT INTO gis_point SELECT * FROM p;
CHECK TABLE gis_point;
Table Op Msg_type Msg_text
test.gis_point check status OK
SELECT COUNT(*), ST_AsText(p1), ST_AsText(p2) FROM gis_point GROUP BY p1, p2;
COUNT(*) ST_AsText(p1) ST_AsText(p2)
1024 POINT(2 4) POINT(-2 -6)
1024 POINT(3 6) POINT(-3 -9)
1024 POINT(4 8) POINT(-4 -12)
1024 POINT(5 10) POINT(-5 -15)
1024 POINT(6 12) POINT(-6 -18)
1024 POINT(7 14) POINT(-7 -21)
1024 POINT(8 16) POINT(0 0)
1024 POINT(9 18) POINT(-4 2)
1024 POINT(10 21) POINT(-6 3)
1024 POINT(1 2) POINT(-1 -3)
1024 POINT(26.25 57) POINT(1 2)
14 POINT(1000 -1000) POINT(-201 203.56)
1024 POINT(20.5 41) POINT(-8 4)
14 POINT(20.5 43.9832) POINT(-0 0)
1024 POINT(32.1234 64.2468) POINT(-1 -1)
14 POINT(-4.2 -6.98) POINT(-120.5 343.9832)
SELECT COUNT(*), ST_AsText(p1) FROM gis_point WHERE ST_TOUCHES(@poly3, p1) AND MBRWithin(p2, @poly4) GROUP BY p1;
COUNT(*) ST_AsText(p1)
1024 POINT(20.5 41)
1024 POINT(32.1234 64.2468)
SELECT COUNT(*), ST_AsText(p2) FROM gis_point WHERE MBRWithin(p2, @poly2) GROUP BY p2;
COUNT(*) ST_AsText(p2)
1024 POINT(-2 -6)
1024 POINT(-3 -9)
1024 POINT(-4 -12)
1024 POINT(-1 -3)
1024 POINT(-1 -1)
DROP TABLE p;
================================
Use a trx to test IUD and verify
================================
=============================================
Delete those rows selected from another table
=============================================
SELECT COUNT(*), ST_AsText(p1), ST_AsText(p2) FROM gis_point GROUP BY p1, p2;
COUNT(*) ST_AsText(p1) ST_AsText(p2)
1024 POINT(2 4) POINT(-2 -6)
1024 POINT(3 6) POINT(-3 -9)
1024 POINT(4 8) POINT(-4 -12)
1024 POINT(5 10) POINT(-5 -15)
1024 POINT(6 12) POINT(-6 -18)
1024 POINT(7 14) POINT(-7 -21)
1024 POINT(8 16) POINT(0 0)
1024 POINT(9 18) POINT(-4 2)
1024 POINT(10 21) POINT(-6 3)
1024 POINT(1 2) POINT(-1 -3)
1024 POINT(26.25 57) POINT(1 2)
14 POINT(1000 -1000) POINT(-201 203.56)
1024 POINT(20.5 41) POINT(-8 4)
14 POINT(20.5 43.9832) POINT(-0 0)
1024 POINT(32.1234 64.2468) POINT(-1 -1)
14 POINT(-4.2 -6.98) POINT(-120.5 343.9832)
UPDATE gis_point SET p2 = ST_PointFromText('POINT(2000 2000)') WHERE ST_Contains(ST_GeomFromText('POLYGON((-100 100, -400 100, -400 400, -100 400, -100 100))'), p2) OR ST_Contains(ST_GeomFromText('POLYGON((-0.0001 -0.0002, -0.0001 0.00002, 0.00000005 0.000001, 0.0000025 -0.001, -0.0001 -0.0002))'), p2);
CHECK TABLE gis_point;
Table Op Msg_type Msg_text
test.gis_point check status OK
'To remove all the just updated rows'
DELETE FROM gis_point WHERE ST_Intersection(ST_GeomFromText('LINESTRING(1800 1900, 2200 2100)'), ST_GeomFromText('LINESTRING(0 0, 2001 2001)')) = p2;
INSERT INTO gis_point VALUES
(ST_PointFromText('POINT(8 16)'), ST_PointFromText('POINT(0 0)')),
(ST_PointFromText('POINT(8 16)'), ST_PointFromText('POINT(0 0)'));
======================================================================
Following results should be almost the same with those at the beginning
======================================================================
SELECT COUNT(*), ST_AsText(p1), ST_AsText(p2) FROM gis_point GROUP BY p1, p2;
COUNT(*) ST_AsText(p1) ST_AsText(p2)
1024 POINT(2 4) POINT(-2 -6)
1024 POINT(3 6) POINT(-3 -9)
1024 POINT(4 8) POINT(-4 -12)
1024 POINT(5 10) POINT(-5 -15)
1024 POINT(6 12) POINT(-6 -18)
1024 POINT(7 14) POINT(-7 -21)
2 POINT(8 16) POINT(0 0)
1024 POINT(9 18) POINT(-4 2)
1024 POINT(10 21) POINT(-6 3)
1024 POINT(1 2) POINT(-1 -3)
1024 POINT(26.25 57) POINT(1 2)
1024 POINT(20.5 41) POINT(-8 4)
1024 POINT(32.1234 64.2468) POINT(-1 -1)
SELECT COUNT(*), ST_AsText(p1), ST_AsText(p2)
FROM gis_point
WHERE ST_Contains(ST_GeomFromText('POLYGON((-1000 -1000, -1000 1000, 1000 1000, 1001 -1001, -1000 -1000))'), p1)
GROUP BY p1, p2;
COUNT(*) ST_AsText(p1) ST_AsText(p2)
1024 POINT(2 4) POINT(-2 -6)
1024 POINT(3 6) POINT(-3 -9)
1024 POINT(4 8) POINT(-4 -12)
1024 POINT(5 10) POINT(-5 -15)
1024 POINT(6 12) POINT(-6 -18)
1024 POINT(7 14) POINT(-7 -21)
2 POINT(8 16) POINT(0 0)
1024 POINT(9 18) POINT(-4 2)
1024 POINT(10 21) POINT(-6 3)
1024 POINT(1 2) POINT(-1 -3)
1024 POINT(26.25 57) POINT(1 2)
1024 POINT(20.5 41) POINT(-8 4)
1024 POINT(32.1234 64.2468) POINT(-1 -1)
SELECT ST_AsText(p1), ST_AsText(p2) FROM gis_point GROUP BY p1, p2;
ST_AsText(p1) ST_AsText(p2)
POINT(2 4) POINT(-2 -6)
POINT(3 6) POINT(-3 -9)
POINT(4 8) POINT(-4 -12)
POINT(5 10) POINT(-5 -15)
POINT(6 12) POINT(-6 -18)
POINT(7 14) POINT(-7 -21)
POINT(8 16) POINT(0 0)
POINT(9 18) POINT(-4 2)
POINT(10 21) POINT(-6 3)
POINT(1 2) POINT(-1 -3)
POINT(26.25 57) POINT(1 2)
POINT(20.5 41) POINT(-8 4)
POINT(32.1234 64.2468) POINT(-1 -1)
SELECT COUNT(*), ST_AsText(p1) FROM gis_point WHERE ST_Intersection(@ls1, @ls2) = p1 GROUP BY p1;
COUNT(*) ST_AsText(p1)
1024 POINT(5 10)
SELECT COUNT(*), ST_AsText(p1) FROM gis_point WHERE MBRWithin(p1, @poly1) GROUP BY p1;
COUNT(*) ST_AsText(p1)
1024 POINT(3 6)
1024 POINT(4 8)
SELECT COUNT(*), ST_AsText(p2) FROM gis_point WHERE ST_Contains(@poly2, p2) GROUP BY p2;
COUNT(*) ST_AsText(p2)
2 POINT(0 0)
1024 POINT(-2 -6)
1024 POINT(-3 -9)
1024 POINT(-4 -12)
1024 POINT(-5 -15)
1024 POINT(-1 -3)
1024 POINT(-1 -1)
SELECT COUNT(*), ST_AsText(p2) FROM gis_point WHERE ST_Equals(p2, @p1) GROUP BY p2;
COUNT(*) ST_AsText(p2)
2 POINT(0 0)
SELECT COUNT(*), ST_AsText(p1) FROM gis_point WHERE ST_TOUCHES(@poly3, p1) AND MBRWithin(p2, @poly4) GROUP BY p1;
COUNT(*) ST_AsText(p1)
1024 POINT(20.5 41)
1024 POINT(32.1234 64.2468)
SELECT COUNT(*), ST_AsText(p1), ST_AsText(p2) FROM gis_point WHERE ST_Contains(@mpoly, p1) GROUP BY p1, p2;
COUNT(*) ST_AsText(p1) ST_AsText(p2)
1024 POINT(3 6) POINT(-3 -9)
1024 POINT(4 8) POINT(-4 -12)
1024 POINT(5 10) POINT(-5 -15)
1024 POINT(6 12) POINT(-6 -18)
1024 POINT(7 14) POINT(-7 -21)
2 POINT(8 16) POINT(0 0)
1024 POINT(10 21) POINT(-6 3)
1024 POINT(20.5 41) POINT(-8 4)
SELECT COUNT(*), ST_AsText(p1), ST_AsText(p2) FROM gis_point WHERE ST_Contains(@mpoly, p1) AND NOT MBRWithin(p1, @mpoly) GROUP BY p1, p2;
COUNT(*) ST_AsText(p1) ST_AsText(p2)
1024 POINT(3 6) POINT(-3 -9)
CHECK TABLE gis_point;
Table Op Msg_type Msg_text
test.gis_point check status OK
DROP TABLE gis_point;
|