mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-11041 Innodb_gis/ tests taken from MySQL fail.
Some fixes made in innodb and item_create.cc. Adapted Innodb-GIS tests moved to MariaDB.
This commit is contained in:
42
mysql-test/suite/innodb_gis/t/0.test
Normal file
42
mysql-test/suite/innodb_gis/t/0.test
Normal file
@ -0,0 +1,42 @@
|
||||
--source include/have_innodb.inc
|
||||
SET default_storage_engine=innodb;
|
||||
--source include/gis_generic.inc
|
||||
--source include/gis_keys.inc
|
||||
|
||||
#
|
||||
# Bug #15680 (SPATIAL key in innodb)
|
||||
#
|
||||
#--error ER_TABLE_CANT_HANDLE_SPKEYS
|
||||
create table t1 (g geometry not null, spatial gk(g)) engine=innodb;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
# Test read uncommitted
|
||||
create table t1 (c1 int, c2 geometry not null, spatial index (c2))engine=innodb;
|
||||
|
||||
connect (a,localhost,root,,);
|
||||
connection a;
|
||||
|
||||
start transaction;
|
||||
insert into t1 values(1, Point(1,1));
|
||||
|
||||
|
||||
connect (con1,localhost,root,,);
|
||||
connection con1;
|
||||
set @g1 = ST_GeomFromText('Polygon((0 0,0 100,100 100,100 0,0 0))');
|
||||
set transaction isolation level read uncommitted;
|
||||
select count(*) from t1 where ST_Within(t1.c2, @g1);
|
||||
disconnect con1;
|
||||
|
||||
--source include/wait_until_disconnected.inc
|
||||
|
||||
connection a;
|
||||
commit;
|
||||
disconnect a;
|
||||
--source include/wait_until_disconnected.inc
|
||||
|
||||
connection default;
|
||||
drop table t1;
|
||||
|
||||
|
||||
|
1451
mysql-test/suite/innodb_gis/t/1.test
Normal file
1451
mysql-test/suite/innodb_gis/t/1.test
Normal file
File diff suppressed because it is too large
Load Diff
753
mysql-test/suite/innodb_gis/t/alter_spatial_index.test
Normal file
753
mysql-test/suite/innodb_gis/t/alter_spatial_index.test
Normal file
@ -0,0 +1,753 @@
|
||||
# ******************************************************************
|
||||
# Test Alter table add spatial idex asc/desc comments
|
||||
# Test error Alter table modify column with No not null option
|
||||
# Test error Alter table modify column with null option
|
||||
# Test table column having both indexes spatial and Btree
|
||||
# Test error Alter table spatial index using hash/Btree
|
||||
# Test modify column from point to multipoint,line to multiline
|
||||
# Test modify column from mutipoint to point,multiline to line
|
||||
# Test discard & import tablepsace
|
||||
# spatial index on temp tables
|
||||
# Unique constraint on spatial index column Geometry
|
||||
# Unique constraint on spatial index column POINT
|
||||
# Modify Engine Innodb to Myisam to InnoDB
|
||||
# Check Foreign Key constraint on Point column
|
||||
# Check Foreign Key constraint on Geometry column
|
||||
# ******************************************************************
|
||||
|
||||
CALL mtr.add_suppression("but MySQL is asking statistics for 2 columns. Have you mixed");
|
||||
|
||||
--source include/have_innodb.inc
|
||||
--source include/have_geometry.inc
|
||||
|
||||
let MYSQLD_DATADIR= `select @@datadir`;
|
||||
|
||||
CREATE TABLE tab(c1 int NOT NULL PRIMARY KEY,c2 POINT NOT NULL,
|
||||
c3 LINESTRING NOT NULL,c4 POLYGON NOT NULL,c5 GEOMETRY NOT NULL)
|
||||
ENGINE=InnoDB;
|
||||
|
||||
CREATE TABLE tab1(c1 int NOT NULL PRIMARY KEY,c2 MULTIPOINT NOT NULL,
|
||||
c3 MULTILINESTRING NOT NULL,c4 MULTIPOLYGON NOT NULL,c5 GEOMETRY NOT NULL)
|
||||
ENGINE=InnoDB;
|
||||
|
||||
INSERT INTO tab1 SELECT * FROM tab;
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(1,ST_GeomFromText('POINT(10 10)'),ST_GeomFromText('LINESTRING(5 5,20 20,30 30)'),
|
||||
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'),
|
||||
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'));
|
||||
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(2,ST_GeomFromText('POINT(20 20)'),ST_GeomFromText('LINESTRING(20 20,30 30,40 40)'),
|
||||
ST_GeomFromText('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))'),
|
||||
ST_GeomFromText('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(3,ST_GeomFromText('POINT(4 4)'),ST_GeomFromText('LINESTRING(130 130,140 140,150 150)'),
|
||||
ST_GeomFromText('POLYGON((7 1,6 2,6 3,10 3,10 1,7 1))'),
|
||||
ST_GeomFromText('POLYGON((4 -2,5 -4,6 -5,7 -4,7 2,4 -2))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(4,ST_GeomFromText('POINT(50 50)'),ST_GeomFromText('LINESTRING(200 200,300 300,400 400)'),
|
||||
ST_GeomFromText('POLYGON((300 300,400 400,500 500,300 500,300 400,300 300))'),
|
||||
ST_GeomFromText('POLYGON((300 300,400 400,500 500,300 500,300 400,300 300))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(5,ST_GeomFromText('POINT(3 3)'),ST_GeomFromText('LINESTRING(400 400,500 500,600 700)'),
|
||||
ST_GeomFromText('POLYGON((1010 1010,1020 1020,1030 1030,1040 1030,1020 1010,1010 1010))'),
|
||||
ST_GeomFromText('POLYGON((1010 1010,1020 1020,1030 1030,1040 1030,1020 1010,1010 1010))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(6,ST_GeomFromText('POINT(3 3)'),ST_GeomFromText('LINESTRING(40 40,50 50,60 70)'),
|
||||
ST_GeomFromText('POLYGON((2010 2010,2020 2020,2030 2030,2040 2030,2020 2010,2010 2010))'),
|
||||
ST_GeomFromText('POLYGON((2010 2010,2020 2020,2030 2030,2040 2030,2020 2010,2010 2010))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(7,ST_GeomFromText('POINT(60 70)'),ST_GeomFromText('LINESTRING(40 40,50 50,60 70)'),
|
||||
ST_GeomFromText('POLYGON((3010 3010,3020 3020,3030 3030,3040 3030,3020 3010,3010 3010))'),
|
||||
ST_GeomFromText('POLYGON((3010 3010,3020 3020,3030 3030,3040 3030,3020 3010,3010 3010))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(8,ST_GeomFromText('POINT(0 0)'),ST_GeomFromText('LINESTRING(40 40,50 50,60 70)'),
|
||||
ST_GeomFromText('POLYGON((3010 3010,3020 3020,3030 3030,3040 3030,3020 3010,3010 3010))'),
|
||||
ST_GeomFromText('POLYGON((3010 3010,3020 3020,3030 3030,3040 3030,3020 3010,3010 3010))'));
|
||||
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(9,ST_GeomFromText('POINT(120 120)'),ST_GeomFromText('LINESTRING(100 100,110 110,120 120)'),
|
||||
ST_GeomFromText('POLYGON((4010 4010,4020 4020,4030 4030,4040 4030,4020 4010,4010 4010))'),
|
||||
ST_GeomFromText('POLYGON((4010 4010,4020 4020,4030 4030,4040 4030,4020 4010,4010 4010))'));
|
||||
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(10,ST_GeomFromText('POINT(160 160)'),ST_GeomFromText('LINESTRING(140 140,150 150,160 160)'),
|
||||
ST_GeomFromText('POLYGON((5010 5010,5020 5020,5030 5030,5040 5030,5020 5010,5010 5010))'),
|
||||
ST_GeomFromText('POLYGON((5010 5010,5020 5020,5030 5030,5040 5030,5020 5010,5010 5010))'));
|
||||
|
||||
|
||||
ALTER TABLE tab ADD SPATIAL INDEX idx2(c2 ASC);
|
||||
|
||||
ALTER TABLE tab ADD SPATIAL KEY idx3(c3 DESC);
|
||||
|
||||
ALTER TABLE tab ADD SPATIAL INDEX idx4(c4 ASC) COMMENT 'testing spatial index on Polygon';
|
||||
|
||||
ALTER TABLE tab ADD SPATIAL KEY idx5(c5 ASC) COMMENT 'testing spatial index on Geometry';
|
||||
|
||||
ALTER TABLE tab ADD INDEX idx6(c4(10)) USING BTREE;
|
||||
|
||||
|
||||
# Test the MBRContains
|
||||
SET @g1 = ST_GeomFromText( 'POLYGON((7 1,6 2,6 3,10 3,10 1,7 1))');
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBRContains(tab.c4, @g1);
|
||||
|
||||
UPDATE tab SET C2 = ST_GeomFromText('POINT(0 0)')
|
||||
WHERE MBRContains(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBRContains(tab.c4, @g1);
|
||||
|
||||
DELETE FROM tab WHERE MBRContains(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBRContains(tab.c4, @g1);
|
||||
|
||||
|
||||
SET @g1 = ST_GeomFromText('LINESTRING( 300 300,400 400)');
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBRContains(tab.c4, @g1);
|
||||
|
||||
UPDATE tab SET C2 = ST_GeomFromText('POINT(100 100)')
|
||||
WHERE MBRContains(tab.c4, @g1);
|
||||
|
||||
DELETE FROM tab WHERE MBRContains(tab.c4, @g1);
|
||||
|
||||
# Test the MBRWithin
|
||||
SET @g1 = ST_GeomFromText( 'POLYGON((1010 1010,1020 1020,1030 1030,1040 1030,1020 1010,1010 1010))');
|
||||
|
||||
SELECT c1,ST_AsText(c2),ST_Astext(c4) FROM tab WHERE MBRWithin(tab.c4, @g1);
|
||||
|
||||
UPDATE tab SET C2 = ST_GeomFromText('POINT(200 200)')
|
||||
WHERE MBRWithin(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_AsText(c2),ST_AsText(c4) FROM tab WHERE MBRWithin(tab.c4, @g1);
|
||||
|
||||
DELETE FROM tab WHERE MBRWithin(tab.c4, @g1);
|
||||
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
ALTER TABLE tab MODIFY COLUMN c2 MULTIPOINT;
|
||||
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
ALTER TABLE tab MODIFY COLUMN c3 MULTILINESTRING;
|
||||
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
ALTER TABLE tab MODIFY COLUMN c4 MULTIPOLYGON;
|
||||
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
ALTER TABLE tab MODIFY COLUMN c3 MULTILINESTRING NULL;
|
||||
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
ALTER TABLE tab MODIFY COLUMN c4 MULTIPOLYGON NULL;
|
||||
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
ALTER TABLE tab MODIFY COLUMN c4 Geometry NULL;
|
||||
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
ALTER TABLE tab CHANGE COLUMN c2 c22 POINT;
|
||||
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
ALTER TABLE tab CHANGE COLUMN c3 c33 LINESTRING;
|
||||
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
ALTER TABLE tab CHANGE COLUMN c4 c44 POLYGON;
|
||||
|
||||
# --error ER_SPATIAL_MUST_HAVE_GEOM_COL
|
||||
--error ER_WRONG_ARGUMENTS
|
||||
ALTER TABLE tab add SPATIAL INDEX idx1(c1);
|
||||
|
||||
--error ER_PARSE_ERROR
|
||||
ALTER TABLE tab ADD SPATIAL INDEX idx6(c2 ASC) USING BTREE;
|
||||
|
||||
--error ER_PARSE_ERROR
|
||||
ALTER TABLE tab ADD SPATIAL INDEX idx6(c2 ASC) USING HASH;
|
||||
|
||||
# --error ER_INVALID_USE_OF_NULL
|
||||
# ALTER TABLE tab CHANGE c2 c2 MULTIPOINT NOT NULL FIRST, ALGORITHM=COPY;
|
||||
|
||||
# --error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
# ALTER TABLE tab MODIFY COLUMN c3 MULTILINESTRING NOT NULL,ALGORITHM=COPY;
|
||||
|
||||
# --error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
# ALTER TABLE tab MODIFY COLUMN c4 MULTIPOLYGON NOT NULL;
|
||||
|
||||
SHOW CREATE TABLE tab;
|
||||
|
||||
--replace_column 7 #
|
||||
SHOW INDEX FROM tab;
|
||||
|
||||
SET @g1 = ST_GeomFromText('POLYGON((20 20,30 30,40 40,50 50,40 50,30 40,30 30,20 20))');
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE ST_Crosses(tab.c4, @g1);
|
||||
|
||||
UPDATE tab SET C2 = ST_GeomFromText('POINT(1000 1000)')
|
||||
WHERE ST_Crosses(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE ST_Crosses(tab.c4, @g1);
|
||||
|
||||
DELETE FROM tab WHERE ST_Crosses(tab.c4, @g1);
|
||||
|
||||
ALTER TABLE tab CHANGE COLUMN c2 c22 POINT NOT NULL;
|
||||
|
||||
ALTER TABLE tab CHANGE COLUMN c3 c33 LINESTRING NOT NULL;
|
||||
|
||||
ALTER TABLE tab CHANGE COLUMN c4 c44 POLYGON NOT NULL;
|
||||
|
||||
SHOW CREATE TABLE tab;
|
||||
|
||||
--replace_column 7 #
|
||||
SHOW INDEX FROM tab;
|
||||
|
||||
ALTER TABLE tab CHANGE COLUMN c22 c2 POINT NOT NULL;
|
||||
|
||||
ALTER TABLE tab CHANGE COLUMN c33 c3 LINESTRING NOT NULL;
|
||||
|
||||
ALTER TABLE tab CHANGE COLUMN c44 c4 POLYGON NOT NULL;
|
||||
|
||||
SHOW CREATE TABLE tab;
|
||||
|
||||
--replace_column 7 #
|
||||
SHOW INDEX FROM tab;
|
||||
|
||||
ALTER TABLE tab DISABLE KEYS;
|
||||
|
||||
SHOW WARNINGS;
|
||||
|
||||
SET @g1 = ST_GeomFromText('POLYGON((5010 5010,5020 5020,5030 5030,5040 5030,5020 5010,5010 5010))');
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBREquals(tab.c4, @g1);
|
||||
|
||||
UPDATE tab SET C2 = ST_GeomFromText('POINT(2000 2000)')
|
||||
WHERE MBREquals(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBREquals(tab.c4, @g1);
|
||||
|
||||
DELETE FROM tab WHERE MBREquals(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBREquals(tab.c4, @g1);
|
||||
|
||||
ALTER TABLE tab DROP PRIMARY KEY;
|
||||
|
||||
ALTER TABLE tab ADD PRIMARY KEY(c2) ;
|
||||
|
||||
SET @g1 = ST_GeomFromText( 'POLYGON((0 0,0 30,30 40,40 50,50 30,0 0))');
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE ST_Touches(tab.c4, @g1);
|
||||
|
||||
UPDATE tab SET C2 = ST_GeomFromText('POINT(3000 3000)')
|
||||
WHERE ST_Touches(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE ST_Touches(tab.c4, @g1);
|
||||
|
||||
DELETE FROM tab WHERE ST_Touches(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE ST_Touches(tab.c4, @g1);
|
||||
|
||||
FLUSH TABLE tab FOR EXPORT;
|
||||
|
||||
--copy_file $MYSQLD_DATADIR/test/tab.ibd $MYSQLD_DATADIR/test/tab.ibd.bk
|
||||
|
||||
UNLOCK TABLES;
|
||||
|
||||
ALTER TABLE tab DISCARD TABLESPACE;
|
||||
|
||||
--disable_warnings
|
||||
|
||||
--error ER_TABLESPACE_DISCARDED
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab;
|
||||
|
||||
--copy_file $MYSQLD_DATADIR/test/tab.ibd.bk $MYSQLD_DATADIR/test/tab.ibd
|
||||
|
||||
--remove_file $MYSQLD_DATADIR/test/tab.ibd.bk
|
||||
|
||||
--disable_query_log
|
||||
|
||||
ALTER TABLE tab IMPORT TABLESPACE;
|
||||
|
||||
--enable_query_log
|
||||
|
||||
CHECK TABLE tab;
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab ORDER BY c1;
|
||||
|
||||
SET @g1 = ST_GeomFromText('LINESTRING( 3010 3010,4010 4010,5010 5010)');
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBRIntersects(tab.c4, @g1) order by c1;
|
||||
|
||||
--error ER_DUP_ENTRY
|
||||
UPDATE tab SET c2 = ST_GeomFromText('POINT(4000 4000)')
|
||||
WHERE MBRIntersects(tab.c4, @g1);
|
||||
|
||||
# --error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
# UPDATE tab SET c4 = ST_GeomFromText('POINT(4000 4000)')
|
||||
# WHERE MBRIntersects(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBRIntersects(tab.c4, @g1) ORDER BY c1;
|
||||
|
||||
DELETE FROM tab WHERE MBRIntersects(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBROverlaps(tab.c4, @g1) ORDER BY c1;
|
||||
|
||||
INSERT INTO tab SELECT * FROM tab1;
|
||||
|
||||
ALTER TABLE tab DROP PRIMARY KEY;
|
||||
|
||||
ALTER TABLE tab DROP INDEX idx2;
|
||||
|
||||
# Check spatial index on temp tables
|
||||
|
||||
CREATE TEMPORARY TABLE temp_tab AS SELECT * FROM tab where c1 = c2;
|
||||
|
||||
INSERT INTO temp_tab SELECT * FROM tab;
|
||||
|
||||
CREATE SPATIAL INDEX idx2 ON temp_tab(c2);
|
||||
|
||||
CREATE SPATIAL INDEX idx3 ON temp_tab(c3);
|
||||
|
||||
CREATE SPATIAL INDEX idx4 ON temp_tab(c4);
|
||||
|
||||
CREATE SPATIAL INDEX idx5 ON temp_tab(c5);
|
||||
|
||||
SHOW CREATE TABLE temp_tab;
|
||||
|
||||
SET @g1 = ST_GeomFromText( 'POLYGON((7 1,6 2,6 3,10 3,10 1,7 1))');
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM temp_tab WHERE MBRContains(temp_tab.c4, @g1) ORDER BY c1;
|
||||
|
||||
# The following comments will be removed once the patch is available
|
||||
UPDATE temp_tab SET C2 = ST_GeomFromText('POINT(1000 1000)')
|
||||
WHERE MBRContains(temp_tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM temp_tab WHERE MBRContains(temp_tab.c4, @g1);
|
||||
|
||||
# Sever crashes Here so commented, will be removed later
|
||||
DELETE FROM temp_tab WHERE MBRContains(temp_tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM temp_tab WHERE MBRContains(temp_tab.c4, @g1) ORDER BY c1;
|
||||
|
||||
# Check Unique constraint on spatial index column POINT
|
||||
|
||||
SHOW CREATE TABLE tab;
|
||||
|
||||
--replace_column 7 #
|
||||
SHOW INDEX FROM tab;
|
||||
|
||||
DELETE FROM tab;
|
||||
|
||||
ALTER TABLE tab ADD PRIMARY KEY(c2);
|
||||
|
||||
CREATE SPATIAL INDEX idx2 ON tab(c2 ASC);
|
||||
|
||||
ALTER TABLE tab ADD CONSTRAINT const_1 UNIQUE(c2);
|
||||
|
||||
SHOW CREATE TABLE tab;
|
||||
|
||||
--replace_column 7 #
|
||||
SHOW INDEX FROM tab;
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(1,ST_GeomFromText('POINT(10 10)'),ST_GeomFromText('LINESTRING(5 5,20 20,30 30)'),
|
||||
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'),
|
||||
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'));
|
||||
|
||||
# Check Unique constraint on spatial index column Geometry
|
||||
|
||||
DELETE FROM tab;
|
||||
|
||||
ALTER TABLE tab DROP PRIMARY KEY ;
|
||||
|
||||
ALTER TABLE tab DROP KEY const_1;
|
||||
|
||||
ALTER TABLE tab ADD PRIMARY KEY(c5(10));
|
||||
|
||||
ALTER TABLE tab ADD CONSTRAINT const_1 UNIQUE(c5(10));
|
||||
|
||||
SHOW CREATE TABLE tab;
|
||||
|
||||
--replace_column 7 #
|
||||
SHOW INDEX FROM tab;
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(1,ST_GeomFromText('POINT(10 10)'),ST_GeomFromText('LINESTRING(5 5,20 20,30 30)'),
|
||||
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'),
|
||||
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'));
|
||||
|
||||
#cleanup
|
||||
DROP TABLE tab,tab1,temp_tab;
|
||||
|
||||
--enable_warnings
|
||||
|
||||
# Check Modify POINT to GEOMETRY and GEOMETRY to POINT
|
||||
CREATE TABLE tab(c1 int NOT NULL PRIMARY KEY,c2 POINT NOT NULL,
|
||||
c3 LINESTRING NOT NULL,c4 POLYGON NOT NULL,c5 GEOMETRY NOT NULL)
|
||||
ENGINE=InnoDB;
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(1,ST_GeomFromText('POINT(10 10)'),ST_GeomFromText('LINESTRING(5 5,20 20,30 30)'),
|
||||
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'),
|
||||
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'));
|
||||
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(2,ST_GeomFromText('POINT(20 20)'),ST_GeomFromText('LINESTRING(20 20,30 30,40 40)'),
|
||||
ST_GeomFromText('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))'),
|
||||
ST_GeomFromText('POLYGON((40 50,40 70,50 100,70 100,80 80,70 50,40 50))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(3,ST_GeomFromText('POINT(4 4)'),ST_GeomFromText('LINESTRING(130 130,140 140,150 150)'),
|
||||
ST_GeomFromText('POLYGON((7 1,6 2,6 3,10 3,10 1,7 1))'),
|
||||
ST_GeomFromText('POLYGON((4 -2,5 -4,6 -5,7 -4,7 2,4 -2))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(4,ST_GeomFromText('POINT(50 50)'),ST_GeomFromText('LINESTRING(200 200,300 300,400 400)'),
|
||||
ST_GeomFromText('POLYGON((300 300,400 400,500 500,300 500,300 400,300 300))'),
|
||||
ST_GeomFromText('POLYGON((300 300,400 400,500 500,300 500,300 400,300 300))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(5,ST_GeomFromText('POINT(3 3)'),ST_GeomFromText('LINESTRING(400 400,500 500,600 700)'),
|
||||
ST_GeomFromText('POLYGON((1010 1010,1020 1020,1030 1030,1040 1030,1020 1010,1010 1010))'),
|
||||
ST_GeomFromText('POLYGON((1010 1010,1020 1020,1030 1030,1040 1030,1020 1010,1010 1010))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(6,ST_GeomFromText('POINT(3 3)'),ST_GeomFromText('LINESTRING(40 40,50 50,60 70)'),
|
||||
ST_GeomFromText('POLYGON((2010 2010,2020 2020,2030 2030,2040 2030,2020 2010,2010 2010))'),
|
||||
ST_GeomFromText('POLYGON((2010 2010,2020 2020,2030 2030,2040 2030,2020 2010,2010 2010))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(7,ST_GeomFromText('POINT(60 70)'),ST_GeomFromText('LINESTRING(40 40,50 50,60 70)'),
|
||||
ST_GeomFromText('POLYGON((3010 3010,3020 3020,3030 3030,3040 3030,3020 3010,3010 3010))'),
|
||||
ST_GeomFromText('POLYGON((3010 3010,3020 3020,3030 3030,3040 3030,3020 3010,3010 3010))'));
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(8,ST_GeomFromText('POINT(0 0)'),ST_GeomFromText('LINESTRING(40 40,50 50,60 70)'),
|
||||
ST_GeomFromText('POLYGON((3010 3010,3020 3020,3030 3030,3040 3030,3020 3010,3010 3010))'),
|
||||
ST_GeomFromText('POLYGON((3010 3010,3020 3020,3030 3030,3040 3030,3020 3010,3010 3010))'));
|
||||
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(9,ST_GeomFromText('POINT(120 120)'),ST_GeomFromText('LINESTRING(100 100,110 110,120 120)'),
|
||||
ST_GeomFromText('POLYGON((4010 4010,4020 4020,4030 4030,4040 4030,4020 4010,4010 4010))'),
|
||||
ST_GeomFromText('POLYGON((4010 4010,4020 4020,4030 4030,4040 4030,4020 4010,4010 4010))'));
|
||||
|
||||
|
||||
INSERT INTO tab(c1,c2,c3,c4,c5)
|
||||
VALUES(10,ST_GeomFromText('POINT(160 160)'),ST_GeomFromText('LINESTRING(140 140,150 150,160 160)'),
|
||||
ST_GeomFromText('POLYGON((5010 5010,5020 5020,5030 5030,5040 5030,5020 5010,5010 5010))'),
|
||||
ST_GeomFromText('POLYGON((5010 5010,5020 5020,5030 5030,5040 5030,5020 5010,5010 5010))'));
|
||||
|
||||
ANALYZE TABLE tab;
|
||||
|
||||
ALTER TABLE tab ADD SPATIAL INDEX idx2(c2 ASC);
|
||||
|
||||
ALTER TABLE tab ADD SPATIAL KEY idx3(c3 DESC);
|
||||
|
||||
ALTER TABLE tab ADD SPATIAL INDEX idx4(c4 ASC) COMMENT 'testing spatial index on Polygon';
|
||||
|
||||
ALTER TABLE tab ADD SPATIAL KEY idx5(c5 ASC) COMMENT 'testing spatial index on Geometry';
|
||||
|
||||
ALTER TABLE tab ADD INDEX idx6(c4(10)) USING BTREE;
|
||||
|
||||
|
||||
ALTER TABLE tab MODIFY COLUMN c2 GEOMETRY NOT NULL;
|
||||
|
||||
# --error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
# ALTER TABLE tab MODIFY COLUMN c3 POLYGON NOT NULL;
|
||||
|
||||
# --error ER_INVALID_USE_OF_NULL
|
||||
# ALTER TABLE tab add COLUMN c7 POINT NOT NULL;
|
||||
|
||||
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
|
||||
ALTER TABLE tab add COLUMN c8 POINT NOT NULL, ALGORITHM = INPLACE, LOCK=NONE;
|
||||
|
||||
SHOW CREATE TABLE tab;
|
||||
|
||||
--replace_column 7 #
|
||||
SHOW INDEX FROM tab;
|
||||
|
||||
SET @g1 = ST_GeomFromText( 'POLYGON((7 1,6 2,6 3,10 3,10 1,7 1))');
|
||||
|
||||
UPDATE tab SET C2 = ST_GeomFromText('POINT(1000 1000)')
|
||||
WHERE MBRContains(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBRContains(tab.c4, @g1) ORDER BY c1;
|
||||
|
||||
DELETE FROM tab WHERE MBRContains(tab.c4, @g1);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBRContains(tab.c4, @g1) ORDER BY c1;
|
||||
|
||||
# --error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
# ALTER TABLE tab MODIFY COLUMN c2 POLYGON NOT NULL;
|
||||
|
||||
ALTER TABLE tab MODIFY COLUMN c4 GEOMETRY NOT NULL;
|
||||
|
||||
SHOW CREATE TABLE tab;
|
||||
|
||||
--replace_column 7 #
|
||||
SHOW INDEX FROM tab;
|
||||
|
||||
ANALYZE TABLE tab;
|
||||
|
||||
SET @g1 = ST_GeomFromText('POLYGON((5010 5010,5020 5020,5030 5030,5040 5030,5020 5010,5010 5010))');
|
||||
|
||||
SET @g2 = ST_GeomFromText('LINESTRING(140 140,150 150,160 160)');
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE MBREquals(tab.c4, @g1)
|
||||
AND MBREquals(tab.c3,@g2) ORDER BY c1;
|
||||
|
||||
UPDATE tab SET C2 = ST_GeomFromText('POINT(2000 2000)')
|
||||
WHERE MBREquals(tab.c4, @g1) AND MBREquals(tab.c3,@g2);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE MBREquals(tab.c4, @g1)
|
||||
AND MBREquals(tab.c3,@g2) ORDER BY c1;
|
||||
|
||||
DELETE FROM tab WHERE MBREquals(tab.c4, @g1) AND MBREquals(tab.c3,@g2);
|
||||
|
||||
SELECT c1,ST_Astext(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE MBREquals(tab.c4, @g1)
|
||||
AND MBREquals(tab.c3,@g2) ORDER BY c1;
|
||||
|
||||
ANALYZE TABLE tab;
|
||||
|
||||
SET @g1 = ST_GeomFromText('POLYGON((4010 4010,4020 4020,4030 4030,4040 4030,4020 4010,4010 4010))');
|
||||
|
||||
SET @g2 = ST_GeomFromText('LINESTRING(1 1,2 2,3 3)');
|
||||
|
||||
# When Point type data exist in the column allow DDL operation
|
||||
ALTER TABLE tab MODIFY COLUMN c2 POINT NOT NULL;
|
||||
|
||||
ALTER TABLE tab MODIFY COLUMN c3 LINESTRING NOT NULL;
|
||||
|
||||
ALTER TABLE tab MODIFY COLUMN c4 POLYGON NOT NULL;
|
||||
|
||||
SHOW CREATE TABLE tab;
|
||||
|
||||
--replace_column 7 #
|
||||
SHOW INDEX FROM tab;
|
||||
|
||||
ANALYZE TABLE tab;
|
||||
|
||||
SET @g1 = ST_GeomFromText( 'POLYGON((0 0,0 30,30 40,40 50,50 30,0 0))');
|
||||
|
||||
SET @g2 = ST_GeomFromText('LINESTRING(1 1,2 2,3 3)');
|
||||
|
||||
# Should be 0 rows affected
|
||||
SELECT c1,ST_Astext(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE ST_Touches(tab.c4, @g1)
|
||||
AND ST_Touches(tab.c3,@g2);
|
||||
|
||||
# Should be 0 rows affected
|
||||
UPDATE tab SET C2 = ST_GeomFromText('POINT(2000 2000)')
|
||||
WHERE ST_Touches(tab.c4, @g1) AND ST_Touches(tab.c3,@g2);
|
||||
|
||||
# Should be 0 rows affected
|
||||
DELETE FROM tab WHERE ST_Touches(tab.c4, @g1) AND ST_Touches(tab.c3,@g2);
|
||||
|
||||
# Should be 0 rows affected
|
||||
SELECT c1,ST_Astext(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE ST_Touches(tab.c4, @g1)
|
||||
AND ST_Touches(tab.c3,@g2);
|
||||
|
||||
# should be 1 row affected
|
||||
SELECT c1,ST_Astext(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE ST_Touches(tab.c4, @g1)
|
||||
OR ST_Touches(tab.c3,@g2);
|
||||
|
||||
# should be 1 row affected
|
||||
UPDATE tab SET C2 = ST_GeomFromText('POINT(2000 2000)')
|
||||
WHERE ST_Touches(tab.c4, @g1) OR ST_Touches(tab.c3,@g2);
|
||||
|
||||
# should be 1 row affected
|
||||
SELECT c1,ST_Astext(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE ST_Touches(tab.c4, @g1)
|
||||
OR ST_Touches(tab.c3,@g2);
|
||||
|
||||
# should be 1 row affected
|
||||
DELETE FROM tab WHERE ST_Touches(tab.c4, @g1) OR ST_Touches(tab.c3,@g2);
|
||||
|
||||
# Should be Empty set
|
||||
SELECT c1,ST_Astext(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE ST_Touches(tab.c4, @g1)
|
||||
OR ST_Touches(tab.c3,@g2);
|
||||
|
||||
# --error ER_SPATIAL_MUST_HAVE_GEOM_COL
|
||||
--error ER_WRONG_ARGUMENTS
|
||||
ALTER TABLE tab MODIFY COLUMN c4 INT NOT NULL;
|
||||
|
||||
# --error ER_SPATIAL_MUST_HAVE_GEOM_COL
|
||||
--error ER_WRONG_ARGUMENTS
|
||||
ALTER TABLE tab MODIFY COLUMN c4 BLOB NOT NULL;
|
||||
|
||||
# Test InnoDB to Myisam to InnoDB
|
||||
ALTER TABLE tab ENGINE Myisam;
|
||||
|
||||
ALTER TABLE tab ENGINE InnoDB;
|
||||
|
||||
ANALYZE TABLE tab;
|
||||
|
||||
SET @g1 = ST_GeomFromText('POLYGON((1010 1010,1020 1020,1030 1030,1040 1030,1020 1010,1010 1010))');
|
||||
|
||||
SET @g2 = ST_GeomFromText('LINESTRING(400 400,500 500,600 700)');
|
||||
|
||||
SELECT c1,ST_AsText(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE MBRWithin(tab.c4, @g1) AND MBRWithin(tab.c3, @g2);
|
||||
|
||||
# --error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
# UPDATE tab SET c2 = ST_GeomFromText('POINT(2000 2000)'),
|
||||
# c3=ST_GeomFromText('POINT(2000 2000)')
|
||||
# WHERE MBRWithin(tab.c4, @g1) AND MBRWithin(tab.c3, @g2);
|
||||
|
||||
SET @g1 = ST_GeomFromText('POINT(2000 2000)');
|
||||
|
||||
SET @g2 = ST_GeomFromText('POINT(2000 2000)');
|
||||
|
||||
SELECT c1,ST_AsText(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE MBRWithin(tab.c2, @g1) AND MBRWithin(tab.c3, @g2);
|
||||
|
||||
DELETE FROM tab WHERE MBRWithin(tab.c2, @g1) AND MBRWithin(tab.c3, @g2);
|
||||
|
||||
SELECT c1,ST_AsText(c2),ST_AsText(c3),ST_Astext(c4) FROM tab WHERE MBRWithin(tab.c2, @g1) AND MBRWithin(tab.c3, @g2);
|
||||
|
||||
#cleanup
|
||||
DROP TABLE tab;
|
||||
|
||||
# Check Foreign Key constraint on Point column
|
||||
CREATE TABLE parent (id POINT, PRIMARY KEY(id)) ENGINE=InnoDB;
|
||||
|
||||
CREATE TABLE child (id GEOMETRY NOT NULL, parent_id POINT NOT NULL) ENGINE=InnoDB;
|
||||
|
||||
ALTER TABLE parent ADD SPATIAL INDEX idx1(id ASC);
|
||||
|
||||
ALTER TABLE child ADD SPATIAL INDEX idx2(parent_id ASC);
|
||||
|
||||
SHOW CREATE TABLE parent;
|
||||
|
||||
SHOW CREATE TABLE child;
|
||||
|
||||
SHOW INDEX FROM parent;
|
||||
|
||||
--replace_column 7 #
|
||||
SHOW INDEX FROM child;
|
||||
|
||||
# --error ER_CANNOT_ADD_FOREIGN
|
||||
--disable_result_log
|
||||
--error ER_CANT_CREATE_TABLE
|
||||
ALTER TABLE child ADD FOREIGN KEY(parent_id) REFERENCES parent(id) ;
|
||||
|
||||
# --error ER_CANNOT_ADD_FOREIGN
|
||||
--error ER_CANT_CREATE_TABLE
|
||||
ALTER TABLE child ADD FOREIGN KEY(parent_id) REFERENCES parent(id) ON DELETE CASCADE ;
|
||||
--enable_result_log
|
||||
|
||||
#cleanup
|
||||
DROP table child,parent;
|
||||
|
||||
# Check Foreign Key constraint on Geometry column
|
||||
CREATE TABLE parent (id GEOMETRY, PRIMARY KEY(id(10))) ENGINE=InnoDB;
|
||||
|
||||
CREATE TABLE child (id GEOMETRY NOT NULL, parent_id GEOMETRY NOT NULL) ENGINE=InnoDB;
|
||||
|
||||
ALTER TABLE parent ADD SPATIAL INDEX idx1(id ASC) ;
|
||||
|
||||
ALTER TABLE child ADD SPATIAL INDEX idx2(parent_id ASC);
|
||||
|
||||
SHOW CREATE TABLE parent;
|
||||
|
||||
SHOW CREATE TABLE child;
|
||||
|
||||
SHOW INDEX FROM parent;
|
||||
|
||||
SHOW INDEX FROM child;
|
||||
|
||||
--disable_result_log
|
||||
# --error ER_BLOB_KEY_WITHOUT_LENGTH
|
||||
--error ER_CANT_CREATE_TABLE
|
||||
ALTER TABLE child ADD FOREIGN KEY(parent_id) REFERENCES parent(id) ;
|
||||
--enable_result_log
|
||||
|
||||
#cleanup
|
||||
DROP table child,parent;
|
||||
|
||||
# Check add spatial index when table already has rows (inplace).
|
||||
create table t1 (c1 int) engine=innodb;
|
||||
insert into t1 values(NULL);
|
||||
|
||||
# Add spatial index fail, since geometry column can't be null.
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
alter table t1 add b geometry, add spatial index(b), algorithm=inplace;
|
||||
|
||||
# Add spatial index fail, since there's invalid geo data.
|
||||
# The case has to be commented because it no longer fails and following cases
|
||||
# don't expect the effect of such a statement.
|
||||
#--error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
# alter table t1 add b geometry not null, add spatial index(b), algorithm=inplace;
|
||||
|
||||
# Add a geometry column.
|
||||
alter table t1 add b geometry, algorithm=inplace;
|
||||
|
||||
# Add spatial index fail, since there's a NULL or invalid geo data.
|
||||
# The case has to be commented because it no longer fails and following cases
|
||||
# don't expect the effect of such a statement.
|
||||
#--error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
#alter table t1 add spatial index(b), algorithm=inplace;
|
||||
|
||||
# Update invalide geo data to point(0 0).
|
||||
update t1 set b = st_geomfromtext('point(0 0)');
|
||||
|
||||
# Add spatial index success.
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
alter table t1 add spatial index(b), algorithm=inplace;
|
||||
|
||||
# Delete rows.
|
||||
delete from t1;
|
||||
|
||||
#cleanup
|
||||
DROP table t1;
|
||||
|
||||
# Check add spatial index when table already has rows (copy).
|
||||
create table t1 (c1 int) engine=innodb;
|
||||
insert into t1 values(NULL);
|
||||
|
||||
# Add spatial index fail, since geometry column can't be null.
|
||||
--error ER_SPATIAL_CANT_HAVE_NULL
|
||||
alter table t1 add b geometry, add spatial index(b), algorithm=copy;
|
||||
|
||||
# Add spatial index fail, since there's a NULL or invalid geo data.
|
||||
# --error ER_INVALID_USE_OF_NULL
|
||||
--error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
alter table t1 add b geometry not null, add spatial index(b), algorithm=copy;
|
||||
|
||||
# Add a geometry column.
|
||||
# --error ER_INVALID_USE_OF_NULL
|
||||
# alter table t1 add b geometry not null, algorithm=copy;
|
||||
|
||||
# Add spatial index.
|
||||
# The case has to be commented because it no longer fails and following cases
|
||||
# don't expect the effect of such a statement.
|
||||
#--error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
#alter table t1 add spatial index(b), algorithm=copy;
|
||||
|
||||
# Update invalide geo data to point(0 0).
|
||||
--error ER_BAD_FIELD_ERROR
|
||||
update t1 set b = st_geomfromtext('point(0 0)');
|
||||
|
||||
# Add spatial index success.
|
||||
--error ER_KEY_COLUMN_DOES_NOT_EXITS
|
||||
alter table t1 add spatial index(b), algorithm=copy;
|
||||
|
||||
# Delete rows.
|
||||
delete from t1;
|
||||
|
||||
#cleanup
|
||||
DROP table t1;
|
||||
|
||||
--echo #
|
||||
--echo # BUG#20111575 ALTER TABLE...ADD SPATIAL INDEX...LOCK NONE IS REFUSED
|
||||
--echo # WITHOUT STATING A REASON
|
||||
--echo #
|
||||
CREATE TABLE t1(p point NOT NULL) ENGINE=innodb;
|
||||
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
|
||||
ALTER TABLE t1 ADD SPATIAL INDEX(p), LOCK=NONE;
|
||||
ALTER TABLE t1 ADD SPATIAL INDEX(p);
|
||||
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
|
||||
ALTER TABLE t1 FORCE, LOCK=NONE;
|
||||
DROP TABLE t1;
|
27
mysql-test/suite/innodb_gis/t/check_rtree.test
Normal file
27
mysql-test/suite/innodb_gis/t/check_rtree.test
Normal file
@ -0,0 +1,27 @@
|
||||
# This test case will test checking R-tree features.
|
||||
|
||||
# Not supported in embedded
|
||||
--source include/not_embedded.inc
|
||||
--source include/have_debug.inc
|
||||
--source include/have_innodb.inc
|
||||
|
||||
# Create table with R-tree index.
|
||||
create table t1 (i int, g geometry not null, spatial index (g))engine=innodb;
|
||||
|
||||
# Turn on the geometry data print.
|
||||
SET SESSION debug="+d,rtree_test_check_count";
|
||||
|
||||
# Insert values.
|
||||
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));
|
||||
|
||||
CALL mtr.add_suppression("InnoDB: Flagged corruption of `g` in table `test`.`t1` in CHECK TABLE; Wrong count");
|
||||
|
||||
# Select by R-tree index.
|
||||
check table t1;
|
||||
|
||||
# Cleanup.
|
||||
drop table t1;
|
1175
mysql-test/suite/innodb_gis/t/create_spatial_index.test
Normal file
1175
mysql-test/suite/innodb_gis/t/create_spatial_index.test
Normal file
File diff suppressed because it is too large
Load Diff
1444
mysql-test/suite/innodb_gis/t/gis.test
Normal file
1444
mysql-test/suite/innodb_gis/t/gis.test
Normal file
File diff suppressed because it is too large
Load Diff
144
mysql-test/suite/innodb_gis/t/precise.test
Normal file
144
mysql-test/suite/innodb_gis/t/precise.test
Normal file
@ -0,0 +1,144 @@
|
||||
-- source include/have_innodb.inc
|
||||
-- source include/have_geometry.inc
|
||||
|
||||
|
||||
#
|
||||
# Spatial objects
|
||||
#
|
||||
|
||||
--disable_warnings
|
||||
DROP TABLE IF EXISTS t1;
|
||||
--enable_warnings
|
||||
|
||||
select 1, ST_Intersects(ST_GeomFromText('POLYGON((0 0,20 0,20 20,0 20,0 0))'), ST_GeomFromText('POLYGON((10 10,30 10,30 30,10 30,10 10))'));
|
||||
select 0, ST_Intersects(ST_GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), ST_GeomFromText('POLYGON((10 40, 40 50, 20 70, 10 40))'));
|
||||
select 1, ST_Intersects(ST_GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), ST_GeomFromText('POINT(10 10)'));
|
||||
select 1, ST_Intersects(ST_GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), ST_GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
|
||||
select 0, ST_Within(ST_GeomFromText('POLYGON((0 0,20 10,10 30, 0 0))'), ST_GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
|
||||
select 1, ST_Within(ST_GeomFromText('POLYGON((1 1,20 10,10 30, 1 1))'), ST_GeomFromText('POLYGON((0 0,30 5,10 40, 0 0))'));
|
||||
|
||||
|
||||
create table t1 (g point)engine=innodb;
|
||||
insert into t1 values
|
||||
(ST_GeomFromText('POINT(2 2)')), (ST_GeomFromText('POINT(2 4)')), (ST_GeomFromText('POINT(2 6)')), (ST_GeomFromText('POINT(2 8)')),
|
||||
(ST_GeomFromText('POINT(4 2)')), (ST_GeomFromText('POINT(4 4)')), (ST_GeomFromText('POINT(4 6)')), (ST_GeomFromText('POINT(4 8)')),
|
||||
(ST_GeomFromText('POINT(6 2)')), (ST_GeomFromText('POINT(6 4)')), (ST_GeomFromText('POINT(6 6)')), (ST_GeomFromText('POINT(6 8)')),
|
||||
(ST_GeomFromText('POINT(8 2)')), (ST_GeomFromText('POINT(8 4)')), (ST_GeomFromText('POINT(8 6)')), (ST_GeomFromText('POINT(8 8)'));
|
||||
|
||||
select ST_astext(g) from t1 where ST_Within(g, ST_GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'));
|
||||
select 'Contains';
|
||||
select ST_astext(g) from t1 where ST_Contains(ST_GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'), g);
|
||||
select 'Intersects';
|
||||
select ST_astext(g) from t1 where ST_Intersects(ST_GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'), g);
|
||||
select 'Contains';
|
||||
select ST_astext(g) from t1 where ST_Contains(ST_GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1))'), g);
|
||||
select 'Contains2';
|
||||
select ST_astext(g) from t1 where ST_Contains(ST_GeomFromText('POLYGON((5 1, 7 1, 7 7, 5 7, 3 3, 5 3, 5 1), (5.01 3.01, 6 5, 9 5, 8 3, 5.01 3.01))'), g);
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
select 0, ST_Within(ST_GeomFromText('LINESTRING(15 15, 50 50, 60 60)'), ST_GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
|
||||
select 1, ST_Within(ST_GeomFromText('LINESTRING(15 15, 16 16)'), ST_GeomFromText('POLYGON((10 10,30 20,20 40, 10 10))'));
|
||||
|
||||
|
||||
select 1, ST_Intersects(ST_GeomFromText('LINESTRING(15 15, 50 50)'), ST_GeomFromText('LINESTRING(50 15, 15 50)'));
|
||||
select 1, ST_Intersects(ST_GeomFromText('LINESTRING(15 15, 50 50)'), ST_GeomFromText('LINESTRING(16 16, 51 51)'));
|
||||
|
||||
select 1, ST_Intersects(ST_GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), ST_GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))'));
|
||||
|
||||
select ST_astext(ST_Union(ST_geometryfromtext('point(1 1)'), ST_geometryfromtext('polygon((0 0, 2 0, 1 2, 0 0))')));
|
||||
select ST_astext(ST_Intersection(ST_geometryfromtext('point(1 1)'), ST_geometryfromtext('polygon((0 0, 2 0, 1 2, 0 0))')));
|
||||
|
||||
select ST_Intersects(ST_GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), ST_GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))'));
|
||||
select ST_contains(ST_GeomFromText('MULTIPOLYGON(((0 0, 0 5, 5 5, 5 0, 0 0)), ((6 6, 6 11, 11 11, 11 6, 6 6)))'), ST_GeomFromText('POINT(5 10)'));
|
||||
select ST_Disjoint(ST_GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), ST_GeomFromText('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))'));
|
||||
select ST_Disjoint(ST_GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), ST_GeomFromText('POLYGON((10 10, 10 4, 4 4, 4 10, 10 10))'));
|
||||
select ST_Overlaps(ST_GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), ST_GeomFromText('POLYGON((10 10, 10 4, 4 4, 4 10, 10 10))'));
|
||||
select ST_Overlaps(ST_GeomFromText('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'), ST_GeomFromText('POLYGON((1 1, 1 4, 4 4, 4 1, 1 1))'));
|
||||
|
||||
# Distance tests
|
||||
select ST_DISTANCE(ST_geomfromtext('polygon((0 0, 1 2, 2 1, 0 0))'), ST_geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'));
|
||||
select ST_DISTANCE(ST_geomfromtext('polygon((0 0, 1 2, 2 1, 0 0))'), ST_geomfromtext('linestring(0 1, 1 0)'));
|
||||
select ST_DISTANCE(ST_geomfromtext('polygon((0 0, 3 6, 6 3, 0 0))'), ST_geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'));
|
||||
select ST_DISTANCE(ST_geomfromtext('polygon((0 0, 3 6, 6 3, 0 0),(2 2, 3 4, 4 3, 2 2))'), ST_geomfromtext('point(3 3)'));
|
||||
select ST_DISTANCE(ST_geomfromtext('linestring(0 0, 3 6, 6 3, 0 0)'), ST_geomfromtext('polygon((2 2, 3 4, 4 3, 2 2))'));
|
||||
|
||||
|
||||
# Operations tests
|
||||
--replace_result 23.85542168674699 23.855421686746986
|
||||
select ST_astext(ST_Intersection(ST_GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), ST_GeomFromText('POLYGON((50 5, 55 10, 0 45, 50 5))')));
|
||||
--replace_result 23.85542168674699 23.855421686746986
|
||||
select ST_astext(ST_Intersection(ST_GeomFromText('LINESTRING(0 0, 50 45, 40 50, 0 0)'), ST_GeomFromText('LINESTRING(50 5, 55 10, 0 45, 50 5)')));
|
||||
select ST_astext(ST_Intersection(ST_GeomFromText('LINESTRING(0 0, 50 45, 40 50)'), ST_GeomFromText('LINESTRING(50 5, 55 10, 0 45)')));
|
||||
select ST_astext(ST_Intersection(ST_GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), ST_GeomFromText('POINT(20 20)')));
|
||||
select ST_astext(ST_Intersection(ST_GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), ST_GeomFromText('LINESTRING(-10 -10, 200 200)')));
|
||||
select ST_astext(ST_Intersection(ST_GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), ST_GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')));
|
||||
select ST_astext(ST_UNION(ST_GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), ST_GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')));
|
||||
|
||||
select ST_astext(ST_intersection(ST_geomfromtext('polygon((0 0, 1 0, 0 1, 0 0))'), ST_geomfromtext('polygon((0 0, 1 1, 0 2, 0 0))')));
|
||||
|
||||
select ST_astext(ST_symdifference(ST_geomfromtext('polygon((0 0, 1 0, 0 1, 0 0))'), ST_geomfromtext('polygon((0 0, 1 1, 0 2, 0 0))')));
|
||||
select ST_astext(ST_UNION(ST_GeomFromText('POLYGON((0 0, 50 45, 40 50, 0 0))'), ST_GeomFromText('LINESTRING(-10 -10, 200 200, 199 201, -11 -9)')));
|
||||
|
||||
# Buffer() tests
|
||||
--replace_regex /([0-9]+\.[0-9]{4})[0-9]*/\1/
|
||||
select ST_astext(ST_buffer(ST_geometryfromtext('point(1 1)'), 1));
|
||||
create table t1(geom geometrycollection)engine=innodb;
|
||||
# --error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
# insert into t1 values (ST_geomfromtext('POLYGON((0 0, 10 10, 0 8, 0 0))'));
|
||||
# --error ER_CANT_CREATE_GEOMETRY_OBJECT
|
||||
# insert into t1 values (ST_geomfromtext('POLYGON((1 1, 10 10, 0 8, 1 1))'));
|
||||
--replace_regex /([0-9]+\.[0-9]{4})[0-9]*/\1/
|
||||
select ST_astext(geom), ST_area(geom),ST_area(ST_buffer(geom,2)) from t1;
|
||||
select ST_NUMPOINTS(ST_EXTERIORRING(ST_buffer(geom,2))) from t1;
|
||||
|
||||
set @geom=ST_geomfromtext('LINESTRING(2 1, 4 2, 2 3, 2 5)');
|
||||
set @buff=ST_buffer(@geom,1);
|
||||
select ST_NUMPOINTS(ST_EXTERIORRING(@buff)) from t1;
|
||||
|
||||
# cleanup
|
||||
DROP TABLE t1;
|
||||
|
||||
#ST_Touches tests
|
||||
select st_touches(ST_geomfromtext('point(0 0)'), ST_geomfromtext('point(1 1)'));
|
||||
select st_touches(ST_geomfromtext('point(1 1)'), ST_geomfromtext('point(1 1)'));
|
||||
select st_touches(ST_geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), ST_geomfromtext('point(1 1)'));
|
||||
select st_touches(ST_geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), ST_geomfromtext('point(1 0)'));
|
||||
select st_touches(ST_geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), ST_geomfromtext('point(1 2)'));
|
||||
select st_touches(ST_geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), ST_geomfromtext('polygon((1 1.2, 1 0, 2 0, 1 1.2))'));
|
||||
select st_touches(ST_geomfromtext('polygon((0 0, 2 2, 0 4, 0 0))'), ST_geomfromtext('polygon((1 1, 1 0, 2 0, 1 1))'));
|
||||
|
||||
#Equals test
|
||||
SELECT ST_Equals(ST_PolyFromText('POLYGON((67 13, 67 18, 67 18, 59 18, 59 13, 67 13) )'),ST_PolyFromText('POLYGON((67 13, 67 18, 59 19, 59 13, 59 13, 67 13) )')) as result;
|
||||
SELECT ST_Equals(ST_PolyFromText('POLYGON((67 13, 67 18, 67 18, 59 18, 59 13, 67 13) )'),ST_PolyFromText('POLYGON((67 13, 67 18, 59 18, 59 13, 59 13, 67 13) )')) as result;
|
||||
SELECT ST_Equals(ST_PointFromText('POINT (12 13)'),ST_PointFromText('POINT (12 13)')) as result;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # BUG#11755628/47429: INTERSECTION FUNCTION CRASHED MYSQLD
|
||||
--echo # BUG#11759650/51979: UNION/INTERSECTION OF POLYGONS CRASHES MYSQL
|
||||
--echo #
|
||||
|
||||
# --error ER_GIS_INVALID_DATA
|
||||
SELECT ST_ASTEXT(ST_UNION(ST_GEOMFROMTEXT('POLYGON((525000 183300,525400
|
||||
183300,525400 18370, 525000 183700,525000 183300))'),
|
||||
ST_geomfromtext('POLYGON((525298.67 183511.53,525296.57
|
||||
183510.39,525296.42 183510.31,525289.11 183506.62,525283.17
|
||||
183503.47,525280.98 183502.26,525278.63 183500.97,525278.39
|
||||
183500.84,525276.79 183500,525260.7 183491.55,525263.95
|
||||
183484.75,525265.58 183481.95,525278.97 183488.73,525276.5
|
||||
183493.45,525275.5 183495.7,525280.35 183498.2,525282.3
|
||||
183499.1,525282.2 183499.3,525283.55 183500,525301.75
|
||||
183509.35,525304.45 183504.25,525307.85 183504.95,525304.5
|
||||
183510.83,525302.81 183513.8,525298.67 183511.53),(525275.06
|
||||
183489.89,525272.06 183488.37,525268.94 183494.51,525271.94
|
||||
183496.03,525275.06 183489.89),(525263.26 183491.55,525266.15
|
||||
183493.04,525269.88 183485.82,525266.99 183484.33,525263.26
|
||||
183491.55))'))) st_u;
|
||||
|
||||
SET @a=0x0000000001030000000200000005000000000000000000000000000000000000000000000000002440000000000000000000000000000024400000000000002440000000000000000000000000000024400000000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000F03F00000000000000400000000000000040000000000000F03F0000000000000040000000000000F03F000000000000F03F;
|
||||
# --error ER_GIS_INVALID_DATA
|
||||
SELECT ST_ASTEXT(ST_TOUCHES(@a, ST_GEOMFROMTEXT('point(0 0)'))) t;
|
||||
|
||||
|
||||
--source include/gis_debug.inc
|
74
mysql-test/suite/innodb_gis/t/rt_precise.test
Normal file
74
mysql-test/suite/innodb_gis/t/rt_precise.test
Normal file
@ -0,0 +1,74 @@
|
||||
#*****************************************************************
|
||||
# This was a Myisam testcase, converted to InnoDB
|
||||
# Since Innodb does not support the spatial key, hence converted
|
||||
# Orginal name of the testcase : gis_rt_precise.test
|
||||
#*****************************************************************
|
||||
--source include/have_innodb.inc
|
||||
-- source include/have_geometry.inc
|
||||
SET default_storage_engine=InnoDB;
|
||||
|
||||
#
|
||||
# test of rtree (using with spatial data)
|
||||
#
|
||||
--disable_warnings
|
||||
DROP TABLE IF EXISTS t1;
|
||||
--enable_warnings
|
||||
|
||||
CREATE TABLE t1 (
|
||||
fid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
g GEOMETRY NOT NULL,
|
||||
KEY gis_key(g(5))
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
SHOW CREATE TABLE t1;
|
||||
|
||||
--disable_query_log
|
||||
let $1=150;
|
||||
let $2=150;
|
||||
while ($1)
|
||||
{
|
||||
eval INSERT INTO t1 (g) VALUES (ST_GeomFromText('LineString($1 $1, $2 $2)'));
|
||||
dec $1;
|
||||
inc $2;
|
||||
}
|
||||
--enable_query_log
|
||||
|
||||
SELECT count(*) FROM t1;
|
||||
|
||||
ANALYZE TABLE t1;
|
||||
|
||||
--replace_column 10 #
|
||||
EXPLAIN SELECT fid, ST_AsText(g) FROM t1 WHERE ST_Within(g, ST_GeomFromText('Polygon((140 140,160 140,160 160,140 140))'));
|
||||
SELECT fid, ST_AsText(g) FROM t1 WHERE ST_Within(g, ST_GeomFromText('Polygon((140 140,160 140,160 160,140 160,140 140))')) ORDER BY fid;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
CREATE TABLE t1 (
|
||||
fid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
g GEOMETRY NOT NULL
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
--disable_query_log
|
||||
let $1=10;
|
||||
while ($1)
|
||||
{
|
||||
let $2=10;
|
||||
while ($2)
|
||||
{
|
||||
eval INSERT INTO t1 (g) VALUES (LineString(Point($1 * 10 - 9, $2 * 10 - 9), Point($1 * 10, $2 * 10)));
|
||||
dec $2;
|
||||
}
|
||||
dec $1;
|
||||
}
|
||||
--enable_query_log
|
||||
|
||||
#--error 1464
|
||||
ALTER TABLE t1 ADD SPATIAL KEY(g);
|
||||
SHOW CREATE TABLE t1;
|
||||
SELECT count(*) FROM t1;
|
||||
SELECT fid, ST_AsText(g) FROM t1 WHERE ST_Within(g,
|
||||
ST_GeomFromText('Polygon((40 40,60 40,60 60,40 40))')) ORDER BY fid;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo End of 5.5 tests.
|
236
mysql-test/suite/innodb_gis/t/rtree.test
Normal file
236
mysql-test/suite/innodb_gis/t/rtree.test
Normal file
@ -0,0 +1,236 @@
|
||||
# WL#6745 InnoDB R-tree support
|
||||
# This test case will test basic R-tree support features.
|
||||
|
||||
# Not supported in embedded
|
||||
--source include/not_embedded.inc
|
||||
|
||||
--source include/have_innodb.inc
|
||||
|
||||
# Create table with R-tree index.
|
||||
create table t1 (i int, g geometry not null, spatial index (g))engine=innodb;
|
||||
|
||||
# Insert values.
|
||||
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;
|
||||
|
||||
# Select by R-tree index.
|
||||
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);
|
||||
select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
|
||||
|
||||
# Delete values.
|
||||
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;
|
||||
|
||||
select ST_astext(t1.g) from t1;
|
||||
|
||||
# Update values.
|
||||
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;
|
||||
|
||||
select ST_astext(t1.g) from t1;
|
||||
|
||||
# Show index.
|
||||
--replace_column 7 #
|
||||
show indexes from t1;
|
||||
|
||||
# Cleanup.
|
||||
drop table t1;
|
||||
|
||||
# Test functions.
|
||||
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);
|
||||
SELECT name, ST_AsText(square) from t1 where MBRDisjoint(@p, square);
|
||||
SELECT name, ST_AsText(square) from t1 where MBREquals(@p, square);
|
||||
SELECT name, ST_AsText(square) from t1 where MBRIntersects(@p, square);
|
||||
SELECT name, ST_AsText(square) from t1 where MBROverlaps(@p, square);
|
||||
SELECT name, ST_AsText(square) from t1 where MBRTouches(@p, square);
|
||||
SELECT name, ST_AsText(square) from t1 where MBRWithin(@p, square);
|
||||
|
||||
# MBROverlaps needs a few more tests, with point and line dimensions
|
||||
|
||||
# --error ER_GIS_INVALID_DATA
|
||||
SET @vert1 = ST_GeomFromText('POLYGON ((0 -2, 0 2, 0 -2))');
|
||||
# --error ER_GIS_INVALID_DATA
|
||||
SET @horiz1 = ST_GeomFromText('POLYGON ((-2 0, 2 0, -2 0))');
|
||||
# --error ER_GIS_INVALID_DATA
|
||||
SET @horiz2 = ST_GeomFromText('POLYGON ((-1 0, 3 0, -1 0))');
|
||||
# --error ER_GIS_INVALID_DATA
|
||||
SET @horiz3 = ST_GeomFromText('POLYGON ((2 0, 3 0, 2 0))');
|
||||
# --error ER_GIS_INVALID_DATA
|
||||
SET @point1 = ST_GeomFromText('POLYGON ((0 0))');
|
||||
# --error ER_GIS_INVALID_DATA
|
||||
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;
|
||||
SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS MBRoverlaps FROM t1 a1 WHERE MBROverlaps(a1.square, @horiz1) GROUP BY a1.name;
|
||||
SELECT MBROverlaps(@horiz1, @vert1) FROM DUAL;
|
||||
SELECT MBROverlaps(@horiz1, @horiz2) FROM DUAL;
|
||||
SELECT MBROverlaps(@horiz1, @horiz3) FROM DUAL;
|
||||
SELECT MBROverlaps(@horiz1, @point1) FROM DUAL;
|
||||
SELECT MBROverlaps(@horiz1, @point2) FROM DUAL;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
# Inplace create spatial index is not supported
|
||||
create table t1 (i int not null, g geometry not null)engine=innodb;
|
||||
|
||||
# Insert values.
|
||||
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), algorithm=inplace;
|
||||
alter table t1 add primary key(i);
|
||||
alter table t1 drop primary key;
|
||||
|
||||
# create spatial index idx on t1(g) algorithm=inplace;
|
||||
create spatial index idx on t1(g);
|
||||
|
||||
create spatial index idx2 on t1(g);
|
||||
|
||||
# alter table t1 add primary key(i), algorithm=inplace;
|
||||
alter table t1 add primary key(i);
|
||||
|
||||
show create table t1;
|
||||
|
||||
drop index idx on t1;
|
||||
|
||||
drop table t1;
|
||||
|
||||
#Test multi pk table.
|
||||
create table t1 (i int, i2 char(10), g geometry not null, primary key (i, i2), spatial index (g))engine=innodb;
|
||||
|
||||
# Insert values.
|
||||
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;
|
||||
|
||||
# Select by R-tree index.
|
||||
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);
|
||||
select ST_astext(t1.g) from t1 where MBRWithin(t1.g, @g1);
|
||||
|
||||
# Delete values.
|
||||
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;
|
||||
|
||||
select ST_astext(t1.g) from t1;
|
||||
|
||||
# Update values.
|
||||
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;
|
||||
|
||||
select ST_astext(t1.g) from t1;
|
||||
|
||||
# Show index.
|
||||
--replace_column 7 #
|
||||
show indexes from t1;
|
||||
|
||||
# Cleanup.
|
||||
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);
|
||||
|
||||
OPTIMIZE TABLE t1;
|
||||
|
||||
SELECT COUNT(*)
|
||||
FROM t1
|
||||
WHERE ST_CONTAINS(ST_GeomFromText('POLYGON((2 2,4 2, 4 4, 2 4, 2 2))'),way);
|
||||
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
# Check the update with unchanged MBR optimization.
|
||||
# Create table with R-tree index.
|
||||
CREATE TABLE t1( i INT, g GEOMETRY NOT NULL, SPATIAL INDEX (g)) ENGINE=InnoDB;
|
||||
|
||||
# Insert values.
|
||||
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 value.
|
||||
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;
|
||||
|
||||
DELETE FROM t1
|
||||
WHERE ST_CONTAINS(ST_GeomFromText('POLYGON((0 0,4 0, 4 4, 0 4, 0 0))'),g);
|
||||
|
||||
DROP TABLE t1;
|
Reference in New Issue
Block a user