Skip to content

Commit 96f06f9

Browse files
committed
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.
1 parent e53e58d commit 96f06f9

File tree

9 files changed

+158
-115
lines changed

9 files changed

+158
-115
lines changed

mysql-test/suite/encryption/r/innodb-spatial-index.result

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 140 "Wrong creat
99
DROP TABLE t1;
1010
CREATE TABLE t1 (pk INT PRIMARY KEY AUTO_INCREMENT,
1111
c VARCHAR(256), coordinate POINT NOT NULL) ENCRYPTED=YES ENGINE=INNODB;
12-
CREATE SPATIAL INDEX b on t1(coordinate);
13-
ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 140 "Wrong create options")
14-
ALTER TABLE t1 ADD SPATIAL INDEX b(coordinate);
12+
ALTER TABLE t1 ADD SPATIAL INDEX b(coordinate), ALGORITHM=COPY;
1513
ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 140 "Wrong create options")
14+
ALTER TABLE t1 ADD SPATIAL INDEX b(coordinate), FORCE, ALGORITHM=INPLACE;
15+
ERROR HY000: Table storage engine 'InnoDB' does not support the create option 'ENCRYPTED'
16+
ALTER TABLE t1 ADD SPATIAL INDEX(coordinate);
17+
ERROR HY000: Table storage engine 'InnoDB' does not support the create option 'ENCRYPTED'
18+
CREATE SPATIAL INDEX b on t1(coordinate);
19+
ERROR HY000: Table storage engine 'InnoDB' does not support the create option 'ENCRYPTED'
1620
DROP TABLE t1;
1721
CREATE TABLE t1 (pk INT PRIMARY KEY AUTO_INCREMENT,
1822
c VARCHAR(256), coordinate POINT NOT NULL) ENCRYPTED=DEFAULT ENGINE=INNODB;

mysql-test/suite/encryption/t/innodb-spatial-index.test

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ DROP TABLE t1;
3131
#
3232
CREATE TABLE t1 (pk INT PRIMARY KEY AUTO_INCREMENT,
3333
c VARCHAR(256), coordinate POINT NOT NULL) ENCRYPTED=YES ENGINE=INNODB;
34+
# FIXME: MDEV-13851 Encrypted table refuses some form of ALGORITHM=COPY,
35+
# but allows rebuild by FORCE
3436
--replace_regex /#sql-[0-9a-f_]*`/#sql-temporary`/
3537
--error ER_CANT_CREATE_TABLE
38+
ALTER TABLE t1 ADD SPATIAL INDEX b(coordinate), ALGORITHM=COPY;
39+
--error ER_ILLEGAL_HA_CREATE_OPTION
40+
ALTER TABLE t1 ADD SPATIAL INDEX b(coordinate), FORCE, ALGORITHM=INPLACE;
41+
--error ER_ILLEGAL_HA_CREATE_OPTION
42+
ALTER TABLE t1 ADD SPATIAL INDEX(coordinate);
43+
--error ER_ILLEGAL_HA_CREATE_OPTION
3644
CREATE SPATIAL INDEX b on t1(coordinate);
37-
--replace_regex /#sql-[0-9a-f_]*`/#sql-temporary`/
38-
--error ER_CANT_CREATE_TABLE
39-
ALTER TABLE t1 ADD SPATIAL INDEX b(coordinate);
4045
DROP TABLE t1;
4146

4247
CREATE TABLE t1 (pk INT PRIMARY KEY AUTO_INCREMENT,
@@ -69,4 +74,4 @@ INSERT INTO t2 values(1, 'secret', ST_GeomFromText('POINT(903994614 180726515)')
6974
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION > 0;
7075
SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0;
7176

72-
DROP TABLE t1, t2;
77+
DROP TABLE t1, t2;

mysql-test/suite/innodb_gis/r/alter_spatial_index.result

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,20 @@ VALUES(10,ST_GeomFromText('POINT(160 160)'),ST_GeomFromText('LINESTRING(140 140,
4747
ST_GeomFromText('POLYGON((5010 5010,5020 5020,5030 5030,5040 5030,5020 5010,5010 5010))'),
4848
ST_GeomFromText('POLYGON((5010 5010,5020 5020,5030 5030,5040 5030,5020 5010,5010 5010))'));
4949
ALTER TABLE tab ADD SPATIAL INDEX idx2(c2 ASC);
50+
affected rows: 0
51+
info: Records: 0 Duplicates: 0 Warnings: 0
5052
ALTER TABLE tab ADD SPATIAL KEY idx3(c3 DESC);
53+
affected rows: 0
54+
info: Records: 0 Duplicates: 0 Warnings: 0
5155
ALTER TABLE tab ADD SPATIAL INDEX idx4(c4 ASC) COMMENT 'testing spatial index on Polygon';
56+
affected rows: 0
57+
info: Records: 0 Duplicates: 0 Warnings: 0
5258
ALTER TABLE tab ADD SPATIAL KEY idx5(c5 ASC) COMMENT 'testing spatial index on Geometry';
59+
affected rows: 0
60+
info: Records: 0 Duplicates: 0 Warnings: 0
5361
ALTER TABLE tab ADD INDEX idx6(c4(10)) USING BTREE;
62+
affected rows: 0
63+
info: Records: 0 Duplicates: 0 Warnings: 0
5464
SET @g1 = ST_GeomFromText( 'POLYGON((7 1,6 2,6 3,10 3,10 1,7 1))');
5565
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBRContains(tab.c4, @g1);
5666
c1 ST_Astext(c2) ST_Astext(c4)
@@ -140,8 +150,14 @@ c1 ST_Astext(c2) ST_Astext(c4)
140150
1 POINT(1000 1000) POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))
141151
DELETE FROM tab WHERE ST_Crosses(tab.c4, @g1);
142152
ALTER TABLE tab CHANGE COLUMN c2 c22 POINT NOT NULL;
153+
affected rows: 0
154+
info: Records: 0 Duplicates: 0 Warnings: 0
143155
ALTER TABLE tab CHANGE COLUMN c3 c33 LINESTRING NOT NULL;
156+
affected rows: 0
157+
info: Records: 0 Duplicates: 0 Warnings: 0
144158
ALTER TABLE tab CHANGE COLUMN c4 c44 POLYGON NOT NULL;
159+
affected rows: 0
160+
info: Records: 0 Duplicates: 0 Warnings: 0
145161
SHOW CREATE TABLE tab;
146162
Table Create Table
147163
tab CREATE TABLE `tab` (
@@ -166,8 +182,14 @@ tab 1 idx4 1 c44 A # 32 NULL SPATIAL testing spatial index on Polygon
166182
tab 1 idx5 1 c5 A # 32 NULL SPATIAL testing spatial index on Geometry
167183
tab 1 idx6 1 c44 A # 10 NULL BTREE
168184
ALTER TABLE tab CHANGE COLUMN c22 c2 POINT NOT NULL;
185+
affected rows: 0
186+
info: Records: 0 Duplicates: 0 Warnings: 0
169187
ALTER TABLE tab CHANGE COLUMN c33 c3 LINESTRING NOT NULL;
188+
affected rows: 0
189+
info: Records: 0 Duplicates: 0 Warnings: 0
170190
ALTER TABLE tab CHANGE COLUMN c44 c4 POLYGON NOT NULL;
191+
affected rows: 0
192+
info: Records: 0 Duplicates: 0 Warnings: 0
171193
SHOW CREATE TABLE tab;
172194
Table Create Table
173195
tab CREATE TABLE `tab` (
@@ -210,7 +232,11 @@ DELETE FROM tab WHERE MBREquals(tab.c4, @g1);
210232
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBREquals(tab.c4, @g1);
211233
c1 ST_Astext(c2) ST_Astext(c4)
212234
ALTER TABLE tab DROP PRIMARY KEY;
235+
affected rows: 4
236+
info: Records: 4 Duplicates: 0 Warnings: 0
213237
ALTER TABLE tab ADD PRIMARY KEY(c2) ;
238+
affected rows: 0
239+
info: Records: 0 Duplicates: 0 Warnings: 0
214240
SET @g1 = ST_GeomFromText( 'POLYGON((0 0,0 30,30 40,40 50,50 30,0 0))');
215241
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE ST_Touches(tab.c4, @g1);
216242
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
254280
c1 ST_Astext(c2) ST_Astext(c4)
255281
INSERT INTO tab SELECT * FROM tab1;
256282
ALTER TABLE tab DROP PRIMARY KEY;
283+
affected rows: 1
284+
info: Records: 1 Duplicates: 0 Warnings: 0
257285
ALTER TABLE tab DROP INDEX idx2;
286+
affected rows: 0
287+
info: Records: 0 Duplicates: 0 Warnings: 0
258288
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
259289
CREATE TEMPORARY TABLE temp_tab AS SELECT * FROM tab where c1 = c2;
260290
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
306336
tab 1 idx6 1 c4 A # 10 NULL BTREE
307337
DELETE FROM tab;
308338
ALTER TABLE tab ADD PRIMARY KEY(c2);
339+
affected rows: 0
340+
info: Records: 0 Duplicates: 0 Warnings: 0
309341
CREATE SPATIAL INDEX idx2 ON tab(c2 ASC);
342+
affected rows: 0
343+
info: Records: 0 Duplicates: 0 Warnings: 0
310344
ALTER TABLE tab ADD CONSTRAINT const_1 UNIQUE(c2);
345+
affected rows: 0
346+
info: Records: 0 Duplicates: 0 Warnings: 0
311347
SHOW CREATE TABLE tab;
312348
Table Create Table
313349
tab CREATE TABLE `tab` (
@@ -339,9 +375,17 @@ ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'),
339375
ST_GeomFromText('POLYGON((30 30,40 40,50 50,30 50,30 40,30 30))'));
340376
DELETE FROM tab;
341377
ALTER TABLE tab DROP PRIMARY KEY ;
378+
affected rows: 0
379+
info: Records: 0 Duplicates: 0 Warnings: 0
342380
ALTER TABLE tab DROP KEY const_1;
381+
affected rows: 0
382+
info: Records: 0 Duplicates: 0 Warnings: 0
343383
ALTER TABLE tab ADD PRIMARY KEY(c5(10));
384+
affected rows: 0
385+
info: Records: 0 Duplicates: 0 Warnings: 0
344386
ALTER TABLE tab ADD CONSTRAINT const_1 UNIQUE(c5(10));
387+
affected rows: 0
388+
info: Records: 0 Duplicates: 0 Warnings: 0
345389
SHOW CREATE TABLE tab;
346390
Table Create Table
347391
tab CREATE TABLE `tab` (
@@ -419,13 +463,25 @@ ANALYZE TABLE tab;
419463
Table Op Msg_type Msg_text
420464
test.tab analyze status OK
421465
ALTER TABLE tab ADD SPATIAL INDEX idx2(c2 ASC);
466+
affected rows: 0
467+
info: Records: 0 Duplicates: 0 Warnings: 0
422468
ALTER TABLE tab ADD SPATIAL KEY idx3(c3 DESC);
469+
affected rows: 0
470+
info: Records: 0 Duplicates: 0 Warnings: 0
423471
ALTER TABLE tab ADD SPATIAL INDEX idx4(c4 ASC) COMMENT 'testing spatial index on Polygon';
472+
affected rows: 0
473+
info: Records: 0 Duplicates: 0 Warnings: 0
424474
ALTER TABLE tab ADD SPATIAL KEY idx5(c5 ASC) COMMENT 'testing spatial index on Geometry';
475+
affected rows: 0
476+
info: Records: 0 Duplicates: 0 Warnings: 0
425477
ALTER TABLE tab ADD INDEX idx6(c4(10)) USING BTREE;
478+
affected rows: 0
479+
info: Records: 0 Duplicates: 0 Warnings: 0
426480
ALTER TABLE tab MODIFY COLUMN c2 GEOMETRY NOT NULL;
481+
affected rows: 0
482+
info: Records: 0 Duplicates: 0 Warnings: 0
427483
ALTER TABLE tab add COLUMN c8 POINT NOT NULL, ALGORITHM = INPLACE, LOCK=NONE;
428-
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Do not support online operation on table with GIS index. Try ALGORITHM=COPY
484+
ERROR 0A000: LOCK=NONE is not supported. Reason: Do not support online operation on table with GIS index. Try LOCK=SHARED
429485
SHOW CREATE TABLE tab;
430486
Table Create Table
431487
tab CREATE TABLE `tab` (
@@ -459,6 +515,8 @@ DELETE FROM tab WHERE MBRContains(tab.c4, @g1);
459515
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab WHERE MBRContains(tab.c4, @g1) ORDER BY c1;
460516
c1 ST_Astext(c2) ST_Astext(c4)
461517
ALTER TABLE tab MODIFY COLUMN c4 GEOMETRY NOT NULL;
518+
affected rows: 0
519+
info: Records: 0 Duplicates: 0 Warnings: 0
462520
SHOW CREATE TABLE tab;
463521
Table Create Table
464522
tab CREATE TABLE `tab` (
@@ -507,8 +565,14 @@ test.tab analyze status OK
507565
SET @g1 = ST_GeomFromText('POLYGON((4010 4010,4020 4020,4030 4030,4040 4030,4020 4010,4010 4010))');
508566
SET @g2 = ST_GeomFromText('LINESTRING(1 1,2 2,3 3)');
509567
ALTER TABLE tab MODIFY COLUMN c2 POINT NOT NULL;
568+
affected rows: 8
569+
info: Records: 8 Duplicates: 0 Warnings: 0
510570
ALTER TABLE tab MODIFY COLUMN c3 LINESTRING NOT NULL;
571+
affected rows: 0
572+
info: Records: 0 Duplicates: 0 Warnings: 0
511573
ALTER TABLE tab MODIFY COLUMN c4 POLYGON NOT NULL;
574+
affected rows: 8
575+
info: Records: 8 Duplicates: 0 Warnings: 0
512576
SHOW CREATE TABLE tab;
513577
Table Create Table
514578
tab CREATE TABLE `tab` (
@@ -585,7 +649,11 @@ DROP TABLE tab;
585649
CREATE TABLE parent (id POINT, PRIMARY KEY(id)) ENGINE=InnoDB;
586650
CREATE TABLE child (id GEOMETRY NOT NULL, parent_id POINT NOT NULL) ENGINE=InnoDB;
587651
ALTER TABLE parent ADD SPATIAL INDEX idx1(id ASC);
652+
affected rows: 0
653+
info: Records: 0 Duplicates: 0 Warnings: 0
588654
ALTER TABLE child ADD SPATIAL INDEX idx2(parent_id ASC);
655+
affected rows: 0
656+
info: Records: 0 Duplicates: 0 Warnings: 0
589657
SHOW CREATE TABLE parent;
590658
Table Create Table
591659
parent CREATE TABLE `parent` (
@@ -613,7 +681,11 @@ DROP table child,parent;
613681
CREATE TABLE parent (id GEOMETRY, PRIMARY KEY(id(10))) ENGINE=InnoDB;
614682
CREATE TABLE child (id GEOMETRY NOT NULL, parent_id GEOMETRY NOT NULL) ENGINE=InnoDB;
615683
ALTER TABLE parent ADD SPATIAL INDEX idx1(id ASC) ;
684+
affected rows: 0
685+
info: Records: 0 Duplicates: 0 Warnings: 0
616686
ALTER TABLE child ADD SPATIAL INDEX idx2(parent_id ASC);
687+
affected rows: 0
688+
info: Records: 0 Duplicates: 0 Warnings: 0
617689
SHOW CREATE TABLE parent;
618690
Table Create Table
619691
parent CREATE TABLE `parent` (
@@ -641,23 +713,21 @@ create table t1 (c1 int) engine=innodb;
641713
insert into t1 values(NULL);
642714
alter table t1 add b geometry, add spatial index(b), algorithm=inplace;
643715
ERROR 42000: All parts of a SPATIAL index must be NOT NULL
644-
alter table t1 add b geometry, algorithm=inplace;
645-
update t1 set b = st_geomfromtext('point(0 0)');
646-
alter table t1 add spatial index(b), algorithm=inplace;
647-
ERROR 42000: All parts of a SPATIAL index must be NOT NULL
648-
delete from t1;
716+
alter table t1 add b geometry not null, add spatial index(b), algorithm=inplace;
717+
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
718+
alter table t1 add b geometry not null default st_geomfromtext('POINT(0 0)'),
719+
add spatial index(b), algorithm=inplace;
720+
affected rows: 0
721+
info: Records: 0 Duplicates: 0 Warnings: 0
649722
DROP table t1;
650723
create table t1 (c1 int) engine=innodb;
651724
insert into t1 values(NULL);
652725
alter table t1 add b geometry, add spatial index(b), algorithm=copy;
653726
ERROR 42000: All parts of a SPATIAL index must be NOT NULL
654727
alter table t1 add b geometry not null, add spatial index(b), algorithm=copy;
655728
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
656-
update t1 set b = st_geomfromtext('point(0 0)');
657-
ERROR 42S22: Unknown column 'b' in 'field list'
658-
alter table t1 add spatial index(b), algorithm=copy;
659-
ERROR 42000: Key column 'b' doesn't exist in table
660-
delete from t1;
729+
alter table t1 add b geometry not null default st_geomfromtext('POINT(0 0)'),
730+
add spatial index(b), algorithm=copy;
661731
DROP table t1;
662732
#
663733
# BUG#20111575 ALTER TABLE...ADD SPATIAL INDEX...LOCK NONE IS REFUSED

0 commit comments

Comments
 (0)