summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorThirunarayanan Balathandayuthapani <thiru@mariadb.com>2021-07-28 19:25:25 +0530
committerThirunarayanan Balathandayuthapani <thiru@mariadb.com>2021-08-16 15:32:07 +0530
commit89445b64fef2c3c9f2cfb9f572dd19b88f3a48df (patch)
treedce6885267b137070b52ebed867d05f64e916866 /mysql-test
parent4cd063b9e40cfb77413bcd44bc7d922c6228f810 (diff)
downloadmariadb-git-89445b64fef2c3c9f2cfb9f572dd19b88f3a48df.tar.gz
MDEV-26131 SEGV in ha_innobase::discard_or_import_tablespace
Import operation without .cfg file fails when there is mismatch of index between metadata table and .ibd file. Moreover, MDEV-19022 shows that InnoDB can end up with index tree where non-leaf page has only one child page. So it is unsafe to find the secondary index root page. This patch does the following when importing the table without .cfg file: 1) If the metadata contains more than one index then InnoDB stops the import operation and report the user to drop all secondary indexes before doing import operation. 2) When the metadata contain only clustered index then InnoDB finds the index id by reading page 0 & page 3 instead of traversing the whole tablespace.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/suite/encryption/r/innodb_import.result22
-rw-r--r--mysql-test/suite/encryption/t/innodb_import.combinations7
-rw-r--r--mysql-test/suite/encryption/t/innodb_import.test21
-rw-r--r--mysql-test/suite/innodb_gis/r/alter_spatial_index.result39
-rw-r--r--mysql-test/suite/innodb_gis/t/alter_spatial_index.test10
5 files changed, 70 insertions, 29 deletions
diff --git a/mysql-test/suite/encryption/r/innodb_import.result b/mysql-test/suite/encryption/r/innodb_import.result
new file mode 100644
index 00000000000..54b95ab26d4
--- /dev/null
+++ b/mysql-test/suite/encryption/r/innodb_import.result
@@ -0,0 +1,22 @@
+#
+# MDEV-26131 SEGV in ha_innobase::discard_or_import_tablespace
+#
+CREATE TABLE t1(f1 int,f2 text)ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1, "InnoDB");
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE t2 ADD KEY idx (f2(13));
+ALTER TABLE t2 DISCARD TABLESPACE;
+FLUSH TABLES t1 FOR EXPORT;
+UNLOCK TABLES;
+ALTER TABLE t2 IMPORT TABLESPACE;
+ERROR HY000: Internal error: Drop all secondary indexes before importing table test/t2 when .cfg file is missing.
+ALTER TABLE t2 DROP KEY idx;
+Warnings:
+Warning 1814 Tablespace has been discarded for table `t2`
+ALTER TABLE t2 IMPORT TABLESPACE;
+Warnings:
+Warning 1810 IO Read error: (2, No such file or directory) Error opening './test/t2.cfg', will attempt to import without schema verification
+SELECT * FROM t2;
+f1 f2
+1 InnoDB
+DROP TABLE t1, t2;
diff --git a/mysql-test/suite/encryption/t/innodb_import.combinations b/mysql-test/suite/encryption/t/innodb_import.combinations
new file mode 100644
index 00000000000..75458949582
--- /dev/null
+++ b/mysql-test/suite/encryption/t/innodb_import.combinations
@@ -0,0 +1,7 @@
+[page_compressed]
+innodb-compression-default=1
+[encryption]
+innodb-encrypt-tables=1
+[page_compressed_encryption]
+innodb-compression-default=1
+innodb-encrypt-tables=1
diff --git a/mysql-test/suite/encryption/t/innodb_import.test b/mysql-test/suite/encryption/t/innodb_import.test
new file mode 100644
index 00000000000..12c8d8bb017
--- /dev/null
+++ b/mysql-test/suite/encryption/t/innodb_import.test
@@ -0,0 +1,21 @@
+--source include/have_innodb.inc
+-- source include/have_example_key_management_plugin.inc
+--echo #
+--echo # MDEV-26131 SEGV in ha_innobase::discard_or_import_tablespace
+--echo #
+let $MYSQLD_DATADIR = `SELECT @@datadir`;
+CREATE TABLE t1(f1 int,f2 text)ENGINE=InnoDB;
+INSERT INTO t1 VALUES(1, "InnoDB");
+CREATE TABLE t2 LIKE t1;
+ALTER TABLE t2 ADD KEY idx (f2(13));
+ALTER TABLE t2 DISCARD TABLESPACE;
+FLUSH TABLES t1 FOR EXPORT;
+--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
+UNLOCK TABLES;
+--error ER_INTERNAL_ERROR
+ALTER TABLE t2 IMPORT TABLESPACE;
+
+ALTER TABLE t2 DROP KEY idx;
+ALTER TABLE t2 IMPORT TABLESPACE;
+SELECT * FROM t2;
+DROP TABLE t1, t2;
diff --git a/mysql-test/suite/innodb_gis/r/alter_spatial_index.result b/mysql-test/suite/innodb_gis/r/alter_spatial_index.result
index bef144e6072..f550d6168e2 100644
--- a/mysql-test/suite/innodb_gis/r/alter_spatial_index.result
+++ b/mysql-test/suite/innodb_gis/r/alter_spatial_index.result
@@ -252,6 +252,16 @@ UNLOCK TABLES;
ALTER TABLE tab DISCARD TABLESPACE;
SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab;
ERROR HY000: Tablespace has been discarded for table `tab`
+ERROR HY000: Internal error: Drop all secondary indexes before importing table test/tab when .cfg file is missing.
+Table Create Table
+tab CREATE TABLE `tab` (
+ `c1` int(11) NOT NULL,
+ `c2` point NOT NULL,
+ `c3` linestring NOT NULL,
+ `c4` polygon NOT NULL,
+ `c5` geometry NOT NULL,
+ PRIMARY KEY (`c2`(25))
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
CHECK TABLE tab;
Table Op Msg_type Msg_text
test.tab check status OK
@@ -282,9 +292,6 @@ 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;
@@ -322,18 +329,10 @@ tab CREATE TABLE `tab` (
`c2` point NOT NULL,
`c3` linestring NOT NULL,
`c4` polygon NOT NULL,
- `c5` geometry NOT NULL,
- SPATIAL KEY `idx3` (`c3`),
- SPATIAL KEY `idx4` (`c4`) COMMENT 'testing spatial index on Polygon',
- SPATIAL KEY `idx5` (`c5`) COMMENT 'testing spatial index on Geometry',
- KEY `idx6` (`c4`(10)) USING BTREE
+ `c5` geometry NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SHOW INDEX FROM tab;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
-tab 1 idx3 1 c3 A # 32 NULL SPATIAL
-tab 1 idx4 1 c4 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 c4 A # 10 NULL BTREE
DELETE FROM tab;
ALTER TABLE tab ADD PRIMARY KEY(c2);
affected rows: 0
@@ -354,20 +353,12 @@ tab CREATE TABLE `tab` (
`c5` geometry NOT NULL,
PRIMARY KEY (`c2`(25)),
UNIQUE KEY `const_1` (`c2`(25)),
- SPATIAL KEY `idx3` (`c3`),
- SPATIAL KEY `idx4` (`c4`) COMMENT 'testing spatial index on Polygon',
- SPATIAL KEY `idx5` (`c5`) COMMENT 'testing spatial index on Geometry',
- KEY `idx6` (`c4`(10)) USING BTREE,
SPATIAL KEY `idx2` (`c2`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SHOW INDEX FROM tab;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
tab 0 PRIMARY 1 c2 A # 25 NULL BTREE
tab 0 const_1 1 c2 A # 25 NULL BTREE
-tab 1 idx3 1 c3 A # 32 NULL SPATIAL
-tab 1 idx4 1 c4 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 c4 A # 10 NULL BTREE
tab 1 idx2 1 c2 A # 32 NULL SPATIAL
INSERT INTO tab(c1,c2,c3,c4,c5)
VALUES(1,ST_GeomFromText('POINT(10 10)'),ST_GeomFromText('LINESTRING(5 5,20 20,30 30)'),
@@ -396,20 +387,12 @@ tab CREATE TABLE `tab` (
`c5` geometry NOT NULL,
PRIMARY KEY (`c5`(10)),
UNIQUE KEY `const_1` (`c5`(10)),
- SPATIAL KEY `idx3` (`c3`),
- SPATIAL KEY `idx4` (`c4`) COMMENT 'testing spatial index on Polygon',
- SPATIAL KEY `idx5` (`c5`) COMMENT 'testing spatial index on Geometry',
- KEY `idx6` (`c4`(10)) USING BTREE,
SPATIAL KEY `idx2` (`c2`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SHOW INDEX FROM tab;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
tab 0 PRIMARY 1 c5 A # 10 NULL BTREE
tab 0 const_1 1 c5 A # 10 NULL BTREE
-tab 1 idx3 1 c3 A # 32 NULL SPATIAL
-tab 1 idx4 1 c4 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 c4 A # 10 NULL BTREE
tab 1 idx2 1 c2 A # 32 NULL SPATIAL
INSERT INTO tab(c1,c2,c3,c4,c5)
VALUES(1,ST_GeomFromText('POINT(10 10)'),ST_GeomFromText('LINESTRING(5 5,20 20,30 30)'),
diff --git a/mysql-test/suite/innodb_gis/t/alter_spatial_index.test b/mysql-test/suite/innodb_gis/t/alter_spatial_index.test
index c4cd100c7e3..cd148820e85 100644
--- a/mysql-test/suite/innodb_gis/t/alter_spatial_index.test
+++ b/mysql-test/suite/innodb_gis/t/alter_spatial_index.test
@@ -277,8 +277,17 @@ SELECT c1,ST_Astext(c2),ST_Astext(c4) FROM tab;
--disable_query_log
+--error ER_INTERNAL_ERROR
ALTER TABLE tab IMPORT TABLESPACE;
+ALTER TABLE tab DROP INDEX idx2;
+ALTER TABLE tab DROP INDEX idx3;
+ALTER TABLE tab DROP INDEX idx4;
+ALTER TABLE tab DROP INDEX idx5;
+ALTER TABLE tab DROP INDEX idx6;
+
+SHOW CREATE TABLE tab;
+ALTER TABLE tab IMPORT TABLESPACE;
--enable_query_log
CHECK TABLE tab;
@@ -308,7 +317,6 @@ INSERT INTO tab SELECT * FROM tab1;
--enable_info
ALTER TABLE tab DROP PRIMARY KEY;
-ALTER TABLE tab DROP INDEX idx2;
--disable_info
# Check spatial index on temp tables