mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-13847 Allow ALTER TABLE…ADD SPATIAL INDEX…ALGORITHM=INPLACE
MDEV-13851 Always check table options in ALTER TABLE…ALGORITHM=INPLACE In the merge of MySQL 5.7.9 to MariaDB 10.2.2, some code was included that prevents ADD SPATIAL INDEX from being executed with ALGORITHM=INPLACE. Also, the constant ADD_SPATIAL_INDEX was introduced as an alias to ADD_INDEX. We will remove that alias now, and properly implement the same ADD SPATIAL INDEX restrictions as MySQL 5.7 does: 1. table-rebuilding operations are not allowed if SPATIAL INDEX survive it 2. ALTER TABLE…ADD SPATIAL INDEX…LOCK=NONE is not allowed ha_innobase::prepare_inplace_alter_table(): If the ALTER TABLE requires actions within InnoDB, enforce the table options (MDEV-13851). In this way, we will keep denying ADD SPATIAL INDEX for tables that use encryption (MDEV-11974), even if ALGORITHM=INPLACE is used.
This commit is contained in:
@ -47,10 +47,20 @@ VALUES(10,ST_GeomFromText('POINT(160 160)'),ST_GeomFromText('LINESTRING(140 140,
|
||||
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);
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD SPATIAL KEY idx3(c3 DESC);
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD SPATIAL INDEX idx4(c4 ASC) COMMENT 'testing spatial index on Polygon';
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD SPATIAL KEY idx5(c5 ASC) COMMENT 'testing spatial index on Geometry';
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD INDEX idx6(c4(10)) USING BTREE;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
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);
|
||||
c1 ST_Astext(c2) ST_Astext(c4)
|
||||
@ -140,8 +150,14 @@ c1 ST_Astext(c2) ST_Astext(c4)
|
||||
1 POINT(1000 1000) POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))
|
||||
DELETE FROM tab WHERE ST_Crosses(tab.c4, @g1);
|
||||
ALTER TABLE tab CHANGE COLUMN c2 c22 POINT NOT NULL;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab CHANGE COLUMN c3 c33 LINESTRING NOT NULL;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab CHANGE COLUMN c4 c44 POLYGON NOT NULL;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
SHOW CREATE TABLE tab;
|
||||
Table Create Table
|
||||
tab CREATE TABLE `tab` (
|
||||
@ -166,8 +182,14 @@ tab 1 idx4 1 c44 A # 32 NULL SPATIAL testing spatial index on Polygon
|
||||
tab 1 idx5 1 c5 A # 32 NULL SPATIAL testing spatial index on Geometry
|
||||
tab 1 idx6 1 c44 A # 10 NULL BTREE
|
||||
ALTER TABLE tab CHANGE COLUMN c22 c2 POINT NOT NULL;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab CHANGE COLUMN c33 c3 LINESTRING NOT NULL;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab CHANGE COLUMN c44 c4 POLYGON NOT NULL;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
SHOW CREATE TABLE tab;
|
||||
Table Create Table
|
||||
tab CREATE TABLE `tab` (
|
||||
@ -210,7 +232,11 @@ DELETE FROM tab WHERE MBREquals(tab.c4, @g1);
|
||||
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBREquals(tab.c4, @g1);
|
||||
c1 ST_Astext(c2) ST_Astext(c4)
|
||||
ALTER TABLE tab DROP PRIMARY KEY;
|
||||
affected rows: 4
|
||||
info: Records: 4 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD PRIMARY KEY(c2) ;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
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);
|
||||
c1 ST_Astext(c2) ST_Astext(c4)
|
||||
@ -254,7 +280,11 @@ SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBROverlaps(tab.c4, @g1) OR
|
||||
c1 ST_Astext(c2) ST_Astext(c4)
|
||||
INSERT INTO tab SELECT * FROM tab1;
|
||||
ALTER TABLE tab DROP PRIMARY KEY;
|
||||
affected rows: 1
|
||||
info: Records: 1 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab DROP INDEX idx2;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
|
||||
CREATE TEMPORARY TABLE temp_tab AS SELECT * FROM tab where c1 = c2;
|
||||
INSERT INTO temp_tab SELECT * FROM tab;
|
||||
@ -306,8 +336,14 @@ tab 1 idx5 1 c5 A # 32 NULL SPATIAL testing spatial index on Geometry
|
||||
tab 1 idx6 1 c4 A # 10 NULL BTREE
|
||||
DELETE FROM tab;
|
||||
ALTER TABLE tab ADD PRIMARY KEY(c2);
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
CREATE SPATIAL INDEX idx2 ON tab(c2 ASC);
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD CONSTRAINT const_1 UNIQUE(c2);
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
SHOW CREATE TABLE tab;
|
||||
Table Create Table
|
||||
tab CREATE TABLE `tab` (
|
||||
@ -339,9 +375,17 @@ 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))'));
|
||||
DELETE FROM tab;
|
||||
ALTER TABLE tab DROP PRIMARY KEY ;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab DROP KEY const_1;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD PRIMARY KEY(c5(10));
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD CONSTRAINT const_1 UNIQUE(c5(10));
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
SHOW CREATE TABLE tab;
|
||||
Table Create Table
|
||||
tab CREATE TABLE `tab` (
|
||||
@ -419,13 +463,25 @@ ANALYZE TABLE tab;
|
||||
Table Op Msg_type Msg_text
|
||||
test.tab analyze status OK
|
||||
ALTER TABLE tab ADD SPATIAL INDEX idx2(c2 ASC);
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD SPATIAL KEY idx3(c3 DESC);
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD SPATIAL INDEX idx4(c4 ASC) COMMENT 'testing spatial index on Polygon';
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD SPATIAL KEY idx5(c5 ASC) COMMENT 'testing spatial index on Geometry';
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab ADD INDEX idx6(c4(10)) USING BTREE;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab MODIFY COLUMN c2 GEOMETRY NOT NULL;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab add COLUMN c8 POINT NOT NULL, ALGORITHM = INPLACE, LOCK=NONE;
|
||||
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Do not support online operation on table with GIS index. Try ALGORITHM=COPY
|
||||
ERROR 0A000: LOCK=NONE is not supported. Reason: Do not support online operation on table with GIS index. Try LOCK=SHARED
|
||||
SHOW CREATE TABLE tab;
|
||||
Table Create Table
|
||||
tab CREATE TABLE `tab` (
|
||||
@ -459,6 +515,8 @@ 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;
|
||||
c1 ST_Astext(c2) ST_Astext(c4)
|
||||
ALTER TABLE tab MODIFY COLUMN c4 GEOMETRY NOT NULL;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
SHOW CREATE TABLE tab;
|
||||
Table Create Table
|
||||
tab CREATE TABLE `tab` (
|
||||
@ -507,8 +565,14 @@ test.tab analyze status OK
|
||||
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)');
|
||||
ALTER TABLE tab MODIFY COLUMN c2 POINT NOT NULL;
|
||||
affected rows: 8
|
||||
info: Records: 8 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab MODIFY COLUMN c3 LINESTRING NOT NULL;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE tab MODIFY COLUMN c4 POLYGON NOT NULL;
|
||||
affected rows: 8
|
||||
info: Records: 8 Duplicates: 0 Warnings: 0
|
||||
SHOW CREATE TABLE tab;
|
||||
Table Create Table
|
||||
tab CREATE TABLE `tab` (
|
||||
@ -585,7 +649,11 @@ DROP TABLE tab;
|
||||
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);
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE child ADD SPATIAL INDEX idx2(parent_id ASC);
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
SHOW CREATE TABLE parent;
|
||||
Table Create Table
|
||||
parent CREATE TABLE `parent` (
|
||||
@ -613,7 +681,11 @@ DROP table child,parent;
|
||||
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) ;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
ALTER TABLE child ADD SPATIAL INDEX idx2(parent_id ASC);
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
SHOW CREATE TABLE parent;
|
||||
Table Create Table
|
||||
parent CREATE TABLE `parent` (
|
||||
@ -641,11 +713,12 @@ create table t1 (c1 int) engine=innodb;
|
||||
insert into t1 values(NULL);
|
||||
alter table t1 add b geometry, add spatial index(b), algorithm=inplace;
|
||||
ERROR 42000: All parts of a SPATIAL index must be NOT NULL
|
||||
alter table t1 add b geometry, algorithm=inplace;
|
||||
update t1 set b = st_geomfromtext('point(0 0)');
|
||||
alter table t1 add spatial index(b), algorithm=inplace;
|
||||
ERROR 42000: All parts of a SPATIAL index must be NOT NULL
|
||||
delete from t1;
|
||||
alter table t1 add b geometry not null, add spatial index(b), algorithm=inplace;
|
||||
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
|
||||
alter table t1 add b geometry not null default st_geomfromtext('POINT(0 0)'),
|
||||
add spatial index(b), algorithm=inplace;
|
||||
affected rows: 0
|
||||
info: Records: 0 Duplicates: 0 Warnings: 0
|
||||
DROP table t1;
|
||||
create table t1 (c1 int) engine=innodb;
|
||||
insert into t1 values(NULL);
|
||||
@ -653,11 +726,8 @@ alter table t1 add b geometry, add spatial index(b), algorithm=copy;
|
||||
ERROR 42000: All parts of a SPATIAL index must be NOT NULL
|
||||
alter table t1 add b geometry not null, add spatial index(b), algorithm=copy;
|
||||
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
|
||||
update t1 set b = st_geomfromtext('point(0 0)');
|
||||
ERROR 42S22: Unknown column 'b' in 'field list'
|
||||
alter table t1 add spatial index(b), algorithm=copy;
|
||||
ERROR 42000: Key column 'b' doesn't exist in table
|
||||
delete from t1;
|
||||
alter table t1 add b geometry not null default st_geomfromtext('POINT(0 0)'),
|
||||
add spatial index(b), algorithm=copy;
|
||||
DROP table t1;
|
||||
#
|
||||
# BUG#20111575 ALTER TABLE...ADD SPATIAL INDEX...LOCK NONE IS REFUSED
|
||||
|
Reference in New Issue
Block a user