Debian Codegraph @

mysql-test/suite/innodb_gis/t/rtree_multi_pk.test

raw
1 # WL#6745 InnoDB R-tree support
2 # This test case will test basic R-tree support features.
3
4 --source include/have_innodb.inc
5
6 # Create table with R-tree index.
7 create table t1 (i int, i2 char(10), g geometry not null, primary key (i, i2), spatial index (g))engine=innodb;
8
9 # Insert values.
10 insert into t1 values (1, "111", POINT(1,1));
11 insert into t1 values (2, "222", POINT(1.5,1.5));
12 insert into t1 values (3, "333", POINT(3,3));
13 insert into t1 values (4, "444", POINT(3.1,3.1));
14 insert into t1 values (5, "555", POINT(5,5));
15
16 analyze table t1;
17
18 # Select by R-tree index.
19 set @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
20 explain select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
21 select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
22
23 # Delete values.
24 set @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
25 delete from t1 where MBRWithin(t1.g, @g1);
26 check table t1;
27
28 select ST_astext(t1.g) from t1;
29
30 # Update values.
31 set @g1 = ST_GeomFromText('Polygon((5 5,5 5,5 5,5 5,5 5))');
32 update t1 set g = POINT(2,2) where MBRWithin(t1.g, @g1);
33 check table t1;
34
35 select ST_astext(t1.g) from t1;
36
37 # Show index.
38 --replace_column 7 #
39 show indexes from t1;
40
41 # Cleanup.
42 drop table t1;
43
44 # Test functions.
45 create table t1 (name VARCHAR(100), square GEOMETRY not null, spatial index (square))engine=innodb;
46
47
48 INSERT INTO t1 VALUES("small", ST_GeomFromText('POLYGON (( 0 0, 0 1, 1 1, 1 0, 0 0))'));
49 INSERT INTO t1 VALUES("big", ST_GeomFromText('POLYGON (( 0 0, 0 3, 3 3, 3 0, 0 0))'));
50
51 INSERT INTO t1 VALUES("up", ST_GeomFromText('POLYGON (( 0 1, 0 3, 2 3, 2 1, 0 1))'));
52 INSERT INTO t1 VALUES("up2", ST_GeomFromText('POLYGON (( 0 2, 0 4, 2 4, 2 2, 0 2))'));
53 INSERT INTO t1 VALUES("up3", ST_GeomFromText('POLYGON (( 0 3, 0 5, 2 5, 2 3, 0 3))'));
54
55 INSERT INTO t1 VALUES("down", ST_GeomFromText('POLYGON (( 0 -1, 0 1, 2 1, 2 -1, 0 -1))'));
56 INSERT INTO t1 VALUES("down2", ST_GeomFromText('POLYGON (( 0 -2, 0 0, 2 0, 2 -2, 0 -2))'));
57 INSERT INTO t1 VALUES("down3", ST_GeomFromText('POLYGON (( 0 -3, 0 -1, 2 -1, 2 -3, 0 -3))'));
58
59 INSERT INTO t1 VALUES("right", ST_GeomFromText('POLYGON (( 1 0, 1 2, 3 2, 3 0, 1 0))'));
60 INSERT INTO t1 VALUES("right2", ST_GeomFromText('POLYGON (( 2 0, 2 2, 4 2, 4 0, 2 0))'));
61 INSERT INTO t1 VALUES("right3", ST_GeomFromText('POLYGON (( 3 0, 3 2, 5 2, 5 0, 3 0))'));
62
63 INSERT INTO t1 VALUES("left", ST_GeomFromText('POLYGON (( -1 0, -1 2, 1 2, 1 0, -1 0))'));
64 INSERT INTO t1 VALUES("left2", ST_GeomFromText('POLYGON (( -2 0, -2 2, 0 2, 0 0, -2 0))'));
65 INSERT INTO t1 VALUES("left3", ST_GeomFromText('POLYGON (( -3 0, -3 2, -1 2, -1 0, -3 0))'));
66
67 SET @p = ST_GeomFromText('POLYGON (( 0 0, 0 2, 2 2, 2 0, 0 0))');
68 SELECT name, ST_AsText(square) from t1 where MBRContains(@p, square);
69 --sorted_result
70 SELECT name, ST_AsText(square) from t1 where MBRDisjoint(@p, square);
71 SELECT name, ST_AsText(square) from t1 where MBREquals(@p, square);
72 SELECT name, ST_AsText(square) from t1 where MBRIntersects(@p, square);
73 SELECT name, ST_AsText(square) from t1 where MBROverlaps(@p, square);
74 SELECT name, ST_AsText(square) from t1 where MBRTouches(@p, square);
75 SELECT name, ST_AsText(square) from t1 where MBRWithin(@p, square);
76
77 # MBROverlaps needs a few more tests, with point and line dimensions
78
79 SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS MBRoverlaps FROM t1 a1 WHERE MBROverlaps(a1.square, @vert1) GROUP BY a1.name;
80 SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS MBRoverlaps FROM t1 a1 WHERE MBROverlaps(a1.square, @horiz1) GROUP BY a1.name;
81 SELECT MBROverlaps(@horiz1, @vert1) FROM DUAL;
82 SELECT MBROverlaps(@horiz1, @horiz2) FROM DUAL;
83 SELECT MBROverlaps(@horiz1, @horiz3) FROM DUAL;
84 SELECT MBROverlaps(@horiz1, @point1) FROM DUAL;
85 SELECT MBROverlaps(@horiz1, @point2) FROM DUAL;
86
87 DROP TABLE t1;
88
89 # Inplace create spatial index is not supported
90 create table t1 (i int not null, g geometry not null)engine=innodb;
91
92 # Insert values.
93 insert into t1 values (1, POINT(1,1));
94 insert into t1 values (2, POINT(1.5,1.5));
95 insert into t1 values (3, POINT(3,3));
96 insert into t1 values (4, POINT(3.1,3.1));
97 insert into t1 values (5, POINT(5,5));
98
99 alter table t1 add primary key(i), algorithm=inplace;
100 alter table t1 drop primary key;
101
102 create spatial index idx on t1(g) algorithm=inplace;
103
104 create spatial index idx2 on t1(g);
105
106 alter table t1 add primary key(i), algorithm=inplace;
107
108 show create table t1;
109
110 drop index idx on t1;
111
112 drop table t1;
113