mirror of
https://github.com/MariaDB/server.git
synced 2025-01-28 01:34:17 +01:00
251 lines
10 KiB
Text
251 lines
10 KiB
Text
create table t1 (i int, g geometry not null, spatial index (g))engine=innodb;
|
|
insert into t1 values (1, POINT(1,1));
|
|
insert into t1 values (1, POINT(1.5,1.5));
|
|
insert into t1 values (1, POINT(3,3));
|
|
insert into t1 values (1, POINT(3.1,3.1));
|
|
insert into t1 values (1, POINT(5,5));
|
|
analyze table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status OK
|
|
set @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
|
|
explain select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 range g g 34 NULL 1 Using where
|
|
select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
|
|
ST_astext(t1.g)
|
|
set @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
|
|
delete from t1 where MBRWithin(t1.g, @g1);
|
|
check table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
select ST_astext(t1.g) from t1;
|
|
ST_astext(t1.g)
|
|
POINT(1 1)
|
|
POINT(1.5 1.5)
|
|
POINT(3 3)
|
|
POINT(3.1 3.1)
|
|
POINT(5 5)
|
|
set @g1 = ST_GeomFromText('Polygon((5 5,5 5,5 5,5 5,5 5))');
|
|
update t1 set g = POINT(2,2) where MBRWithin(t1.g, @g1);
|
|
check table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
select ST_astext(t1.g) from t1;
|
|
ST_astext(t1.g)
|
|
POINT(1 1)
|
|
POINT(1.5 1.5)
|
|
POINT(3 3)
|
|
POINT(3.1 3.1)
|
|
POINT(2 2)
|
|
show indexes from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
|
t1 1 g 1 g A # 32 NULL SPATIAL
|
|
drop table t1;
|
|
create table t1 (name VARCHAR(100), square GEOMETRY not null, spatial index (square))engine=innodb;
|
|
INSERT INTO t1 VALUES("small", ST_GeomFromText('POLYGON (( 0 0, 0 1, 1 1, 1 0, 0 0))'));
|
|
INSERT INTO t1 VALUES("big", ST_GeomFromText('POLYGON (( 0 0, 0 3, 3 3, 3 0, 0 0))'));
|
|
INSERT INTO t1 VALUES("up", ST_GeomFromText('POLYGON (( 0 1, 0 3, 2 3, 2 1, 0 1))'));
|
|
INSERT INTO t1 VALUES("up2", ST_GeomFromText('POLYGON (( 0 2, 0 4, 2 4, 2 2, 0 2))'));
|
|
INSERT INTO t1 VALUES("up3", ST_GeomFromText('POLYGON (( 0 3, 0 5, 2 5, 2 3, 0 3))'));
|
|
INSERT INTO t1 VALUES("down", ST_GeomFromText('POLYGON (( 0 -1, 0 1, 2 1, 2 -1, 0 -1))'));
|
|
INSERT INTO t1 VALUES("down2", ST_GeomFromText('POLYGON (( 0 -2, 0 0, 2 0, 2 -2, 0 -2))'));
|
|
INSERT INTO t1 VALUES("down3", ST_GeomFromText('POLYGON (( 0 -3, 0 -1, 2 -1, 2 -3, 0 -3))'));
|
|
INSERT INTO t1 VALUES("right", ST_GeomFromText('POLYGON (( 1 0, 1 2, 3 2, 3 0, 1 0))'));
|
|
INSERT INTO t1 VALUES("right2", ST_GeomFromText('POLYGON (( 2 0, 2 2, 4 2, 4 0, 2 0))'));
|
|
INSERT INTO t1 VALUES("right3", ST_GeomFromText('POLYGON (( 3 0, 3 2, 5 2, 5 0, 3 0))'));
|
|
INSERT INTO t1 VALUES("left", ST_GeomFromText('POLYGON (( -1 0, -1 2, 1 2, 1 0, -1 0))'));
|
|
INSERT INTO t1 VALUES("left2", ST_GeomFromText('POLYGON (( -2 0, -2 2, 0 2, 0 0, -2 0))'));
|
|
INSERT INTO t1 VALUES("left3", ST_GeomFromText('POLYGON (( -3 0, -3 2, -1 2, -1 0, -3 0))'));
|
|
SET @p = ST_GeomFromText('POLYGON (( 0 0, 0 2, 2 2, 2 0, 0 0))');
|
|
SELECT name, ST_AsText(square) from t1 where MBRContains(@p, square);
|
|
name ST_AsText(square)
|
|
small POLYGON((0 0,0 1,1 1,1 0,0 0))
|
|
SELECT name, ST_AsText(square) from t1 where MBRDisjoint(@p, square);
|
|
name ST_AsText(square)
|
|
up3 POLYGON((0 3,0 5,2 5,2 3,0 3))
|
|
down3 POLYGON((0 -3,0 -1,2 -1,2 -3,0 -3))
|
|
right3 POLYGON((3 0,3 2,5 2,5 0,3 0))
|
|
left3 POLYGON((-3 0,-3 2,-1 2,-1 0,-3 0))
|
|
SELECT name, ST_AsText(square) from t1 where MBREquals(@p, square);
|
|
name ST_AsText(square)
|
|
SELECT name, ST_AsText(square) from t1 where MBRIntersects(@p, square);
|
|
name ST_AsText(square)
|
|
right2 POLYGON((2 0,2 2,4 2,4 0,2 0))
|
|
right POLYGON((1 0,1 2,3 2,3 0,1 0))
|
|
up2 POLYGON((0 2,0 4,2 4,2 2,0 2))
|
|
up POLYGON((0 1,0 3,2 3,2 1,0 1))
|
|
big POLYGON((0 0,0 3,3 3,3 0,0 0))
|
|
small POLYGON((0 0,0 1,1 1,1 0,0 0))
|
|
down POLYGON((0 -1,0 1,2 1,2 -1,0 -1))
|
|
down2 POLYGON((0 -2,0 0,2 0,2 -2,0 -2))
|
|
left POLYGON((-1 0,-1 2,1 2,1 0,-1 0))
|
|
left2 POLYGON((-2 0,-2 2,0 2,0 0,-2 0))
|
|
SELECT name, ST_AsText(square) from t1 where MBROverlaps(@p, square);
|
|
name ST_AsText(square)
|
|
right POLYGON((1 0,1 2,3 2,3 0,1 0))
|
|
up POLYGON((0 1,0 3,2 3,2 1,0 1))
|
|
down POLYGON((0 -1,0 1,2 1,2 -1,0 -1))
|
|
left POLYGON((-1 0,-1 2,1 2,1 0,-1 0))
|
|
SELECT name, ST_AsText(square) from t1 where MBRTouches(@p, square);
|
|
name ST_AsText(square)
|
|
right2 POLYGON((2 0,2 2,4 2,4 0,2 0))
|
|
up2 POLYGON((0 2,0 4,2 4,2 2,0 2))
|
|
down2 POLYGON((0 -2,0 0,2 0,2 -2,0 -2))
|
|
left2 POLYGON((-2 0,-2 2,0 2,0 0,-2 0))
|
|
SELECT name, ST_AsText(square) from t1 where MBRWithin(@p, square);
|
|
name ST_AsText(square)
|
|
big POLYGON((0 0,0 3,3 3,3 0,0 0))
|
|
SET @vert1 = ST_GeomFromText('POLYGON ((0 -2, 0 2, 0 -2))');
|
|
SET @horiz1 = ST_GeomFromText('POLYGON ((-2 0, 2 0, -2 0))');
|
|
SET @horiz2 = ST_GeomFromText('POLYGON ((-1 0, 3 0, -1 0))');
|
|
SET @horiz3 = ST_GeomFromText('POLYGON ((2 0, 3 0, 2 0))');
|
|
SET @point1 = ST_GeomFromText('POLYGON ((0 0))');
|
|
SET @point2 = ST_GeomFromText('POLYGON ((-2 0))');
|
|
SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS MBRoverlaps FROM t1 a1 WHERE MBROverlaps(a1.square, @vert1) GROUP BY a1.name;
|
|
MBRoverlaps
|
|
SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS MBRoverlaps FROM t1 a1 WHERE MBROverlaps(a1.square, @horiz1) GROUP BY a1.name;
|
|
MBRoverlaps
|
|
SELECT MBROverlaps(@horiz1, @vert1) FROM DUAL;
|
|
MBROverlaps(@horiz1, @vert1)
|
|
0
|
|
SELECT MBROverlaps(@horiz1, @horiz2) FROM DUAL;
|
|
MBROverlaps(@horiz1, @horiz2)
|
|
1
|
|
SELECT MBROverlaps(@horiz1, @horiz3) FROM DUAL;
|
|
MBROverlaps(@horiz1, @horiz3)
|
|
0
|
|
SELECT MBROverlaps(@horiz1, @point1) FROM DUAL;
|
|
MBROverlaps(@horiz1, @point1)
|
|
0
|
|
SELECT MBROverlaps(@horiz1, @point2) FROM DUAL;
|
|
MBROverlaps(@horiz1, @point2)
|
|
0
|
|
DROP TABLE t1;
|
|
create table t1 (i int not null, g geometry not null)engine=innodb;
|
|
insert into t1 values (1, POINT(1,1));
|
|
insert into t1 values (2, POINT(1.5,1.5));
|
|
insert into t1 values (3, POINT(3,3));
|
|
insert into t1 values (4, POINT(3.1,3.1));
|
|
insert into t1 values (5, POINT(5,5));
|
|
alter table t1 add primary key(i);
|
|
alter table t1 drop primary key;
|
|
create spatial index idx on t1(g);
|
|
create spatial index idx2 on t1(g);
|
|
Warnings:
|
|
Note 1831 Duplicate index `idx2`. This is deprecated and will be disallowed in a future release
|
|
alter table t1 add primary key(i);
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`i` int(11) NOT NULL,
|
|
`g` geometry NOT NULL,
|
|
PRIMARY KEY (`i`),
|
|
SPATIAL KEY `idx` (`g`),
|
|
SPATIAL KEY `idx2` (`g`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
|
drop index idx on t1;
|
|
drop table t1;
|
|
create table t1 (i int, i2 char(10), g geometry not null, primary key (i, i2), spatial index (g))engine=innodb;
|
|
insert into t1 values (1, "111", POINT(1,1));
|
|
insert into t1 values (2, "222", POINT(1.5,1.5));
|
|
insert into t1 values (3, "333", POINT(3,3));
|
|
insert into t1 values (4, "444", POINT(3.1,3.1));
|
|
insert into t1 values (5, "555", POINT(5,5));
|
|
analyze table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 analyze status OK
|
|
set @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
|
|
explain select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 range g g 34 NULL 1 Using where
|
|
select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
|
|
ST_astext(t1.g)
|
|
set @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
|
|
delete from t1 where MBRWithin(t1.g, @g1);
|
|
check table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
select ST_astext(t1.g) from t1;
|
|
ST_astext(t1.g)
|
|
POINT(1 1)
|
|
POINT(1.5 1.5)
|
|
POINT(3 3)
|
|
POINT(3.1 3.1)
|
|
POINT(5 5)
|
|
set @g1 = ST_GeomFromText('Polygon((5 5,5 5,5 5,5 5,5 5))');
|
|
update t1 set g = POINT(2,2) where MBRWithin(t1.g, @g1);
|
|
check table t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
select ST_astext(t1.g) from t1;
|
|
ST_astext(t1.g)
|
|
POINT(1 1)
|
|
POINT(1.5 1.5)
|
|
POINT(3 3)
|
|
POINT(3.1 3.1)
|
|
POINT(2 2)
|
|
show indexes from t1;
|
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
|
t1 0 PRIMARY 1 i A # NULL NULL BTREE
|
|
t1 0 PRIMARY 2 i2 A # NULL NULL BTREE
|
|
t1 1 g 1 g A # 32 NULL SPATIAL
|
|
drop table t1;
|
|
CREATE TABLE `t1` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`way` geometry NOT NULL,
|
|
PRIMARY KEY (`id`),
|
|
SPATIAL KEY `way` (`way`)
|
|
) ENGINE=InnoDB;
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(1 1)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(1 2)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(1 3)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(1 4)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(1 5)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(2 1)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(2 2)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(2 3)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(2 4)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(2 5)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(3 1)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(3 2)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(3 3)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(3 4)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(3 5)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(4 1)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(4 2)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(4 3)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(4 4)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(4 5)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(5 1)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(5 2)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(5 3)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(5 4)');
|
|
INSERT INTO t1 SET way = ST_GeomFromText('POINT(5 5)');
|
|
SELECT COUNT(*)
|
|
FROM t1
|
|
WHERE ST_CONTAINS(ST_GeomFromText('POLYGON((2 2,4 2, 4 4, 2 4, 2 2))'),way);
|
|
COUNT(*)
|
|
9
|
|
OPTIMIZE TABLE t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 optimize note Table does not support optimize, doing recreate + analyze instead
|
|
test.t1 optimize status OK
|
|
SELECT COUNT(*)
|
|
FROM t1
|
|
WHERE ST_CONTAINS(ST_GeomFromText('POLYGON((2 2,4 2, 4 4, 2 4, 2 2))'),way);
|
|
COUNT(*)
|
|
9
|
|
DROP TABLE t1;
|
|
CREATE TABLE t1( i INT, g GEOMETRY NOT NULL, SPATIAL INDEX (g)) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES(1, LINESTRING(POINT(1,1), POINT(4, 4)));
|
|
INSERT INTO t1 VALUES(2, LINESTRING(POINT(2,2), POINT(5, 5)));
|
|
UPDATE t1 SET g = LINESTRING(POINT(1,1), POINT(2,2), POINT(3,3), POINT(4,4))
|
|
WHERE i = 1;
|
|
UPDATE t1 SET g = LINESTRING(POINT(1,1), POINT(2,2), POINT(3,3), POINT(8,8))
|
|
WHERE i = 2;
|
|
CHECK TABLE t1;
|
|
Table Op Msg_type Msg_text
|
|
test.t1 check status OK
|
|
DELETE FROM t1
|
|
WHERE ST_CONTAINS(ST_GeomFromText('POLYGON((0 0,4 0, 4 4, 0 4, 0 0))'),g);
|
|
DROP TABLE t1;
|