Skip to content

Commit 8e8651f

Browse files
author
Darshan M N
committed
Merge mysql-5.6 to mysql-5.7 for BUG#21514135
2 parents 1e139ad + a0bc9d8 commit 8e8651f

File tree

5 files changed

+211
-22
lines changed

5 files changed

+211
-22
lines changed

mysql-test/suite/innodb/include/import.inc

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,38 @@
33

44
let $MYSQLD_DATADIR = `SELECT @@datadir`;
55

6-
FLUSH TABLES t1 FOR EXPORT;
6+
if(!$source_db) {
7+
let $source_db = test;
8+
}
79

8-
--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/t1.cfg_back
9-
--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/t1.ibd_back
10+
if(!$dest_db) {
11+
let $dest_db = test;
12+
}
13+
14+
eval FLUSH TABLES $source_db.t1 FOR EXPORT;
15+
16+
--copy_file $MYSQLD_DATADIR/$source_db/t1.cfg $MYSQLD_DATADIR/t1.cfg_back
17+
--copy_file $MYSQLD_DATADIR/$source_db/t1.ibd $MYSQLD_DATADIR/t1.ibd_back
1018

1119
UNLOCK TABLES;
12-
ALTER TABLE t1 DISCARD TABLESPACE;
1320

14-
--move_file $MYSQLD_DATADIR/t1.cfg_back $MYSQLD_DATADIR/test/t1.cfg
15-
--move_file $MYSQLD_DATADIR/t1.ibd_back $MYSQLD_DATADIR/test/t1.ibd
21+
if($source_db != $dest_db) {
22+
eval USE $dest_db;
23+
let $create1 = query_get_value(SHOW CREATE TABLE $source_db.t1, Create Table, 1);
24+
eval $create1;
25+
}
26+
27+
eval ALTER TABLE $dest_db.t1 DISCARD TABLESPACE;
28+
29+
--move_file $MYSQLD_DATADIR/t1.cfg_back $MYSQLD_DATADIR/$dest_db/t1.cfg
30+
--move_file $MYSQLD_DATADIR/t1.ibd_back $MYSQLD_DATADIR/$dest_db/t1.ibd
31+
32+
eval ALTER TABLE $dest_db.t1 IMPORT TABLESPACE;
1633

17-
ALTER TABLE t1 IMPORT TABLESPACE;
34+
eval CHECK TABLE $dest_db.t1;
35+
eval SHOW CREATE TABLE $dest_db.t1;
36+
eval SELECT * FROM $dest_db.t1;
1837

19-
CHECK TABLE t1;
20-
SHOW CREATE TABLE t1;
21-
SELECT * FROM t1;
38+
if($source_db != $dest_db) {
39+
eval DROP TABLE $dest_db.t1;
40+
}

mysql-test/suite/innodb/r/import.result

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ ALTER TABLE t1 ADD INDEX ind2(c3, c1(10), c2);
99
ALTER TABLE t1 ADD INDEX ind3(c2, c3, c1(20));
1010
INSERT INTO t1 VALUES ('Test Data -1', 'Test Data -2', 'Test Data -3');
1111
# Test with 2ndary index having prefix
12-
FLUSH TABLES t1 FOR EXPORT;
12+
FLUSH TABLES test.t1 FOR EXPORT;
1313
UNLOCK TABLES;
14-
ALTER TABLE t1 DISCARD TABLESPACE;
15-
ALTER TABLE t1 IMPORT TABLESPACE;
16-
CHECK TABLE t1;
14+
ALTER TABLE test.t1 DISCARD TABLESPACE;
15+
ALTER TABLE test.t1 IMPORT TABLESPACE;
16+
CHECK TABLE test.t1;
1717
Table Op Msg_type Msg_text
1818
test.t1 check status OK
19-
SHOW CREATE TABLE t1;
19+
SHOW CREATE TABLE test.t1;
2020
Table Create Table
2121
t1 CREATE TABLE `t1` (
2222
`c1` varchar(32) NOT NULL,
@@ -27,19 +27,19 @@ t1 CREATE TABLE `t1` (
2727
KEY `ind2` (`c3`,`c1`(10),`c2`),
2828
KEY `ind3` (`c2`,`c3`,`c1`(20))
2929
) ENGINE=InnoDB DEFAULT CHARSET=latin1
30-
SELECT * FROM t1;
30+
SELECT * FROM test.t1;
3131
c1 c2 c3
3232
Test Data -1 Test Data -2 Test Data -3
3333
# Test with PK & 2ndary index with prefix
3434
ALTER TABLE t1 DROP PRIMARY KEY, ADD PRIMARY KEY(c1(5), c2(10), c3(20));
35-
FLUSH TABLES t1 FOR EXPORT;
35+
FLUSH TABLES test.t1 FOR EXPORT;
3636
UNLOCK TABLES;
37-
ALTER TABLE t1 DISCARD TABLESPACE;
38-
ALTER TABLE t1 IMPORT TABLESPACE;
39-
CHECK TABLE t1;
37+
ALTER TABLE test.t1 DISCARD TABLESPACE;
38+
ALTER TABLE test.t1 IMPORT TABLESPACE;
39+
CHECK TABLE test.t1;
4040
Table Op Msg_type Msg_text
4141
test.t1 check status OK
42-
SHOW CREATE TABLE t1;
42+
SHOW CREATE TABLE test.t1;
4343
Table Create Table
4444
t1 CREATE TABLE `t1` (
4545
`c1` varchar(32) NOT NULL,
@@ -50,7 +50,7 @@ t1 CREATE TABLE `t1` (
5050
KEY `ind2` (`c3`,`c1`(10),`c2`),
5151
KEY `ind3` (`c2`,`c3`,`c1`(20))
5252
) ENGINE=InnoDB DEFAULT CHARSET=latin1
53-
SELECT * FROM t1;
53+
SELECT * FROM test.t1;
5454
c1 c2 c3
5555
Test Data -1 Test Data -2 Test Data -3
5656
DROP TABLE t1;

mysql-test/suite/innodb/r/innodb-alter.result

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,3 +742,73 @@ t2 CREATE TABLE `t2` (
742742
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c2`) REFERENCES `t1` (`c5`)
743743
) ENGINE=InnoDB DEFAULT CHARSET=latin1
744744
DROP TABLE t2, t1;
745+
#
746+
#BUG#21514135 SCHEMA MISMATCH ERROR WHEN IMPORTING TABLESPACE AFTER
747+
#DROPPING AN INDEX
748+
#
749+
CREATE DATABASE source_db;
750+
CREATE DATABASE dest_db;
751+
CREATE TABLE source_db.t1 (
752+
id int(11) NOT NULL,
753+
age int(11) DEFAULT NULL,
754+
name varchar(20),
755+
PRIMARY KEY (id),
756+
KEY index1 (age)
757+
) ENGINE=InnoDB;
758+
ALTER TABLE source_db.t1 DROP INDEX index1, ADD INDEX index2(name, age), algorithm=inplace;
759+
FLUSH TABLES source_db.t1 FOR EXPORT;
760+
UNLOCK TABLES;
761+
USE dest_db;
762+
CREATE TABLE `t1` (
763+
`id` int(11) NOT NULL,
764+
`age` int(11) DEFAULT NULL,
765+
`name` varchar(20) DEFAULT NULL,
766+
PRIMARY KEY (`id`),
767+
KEY `index2` (`name`,`age`)
768+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
769+
ALTER TABLE dest_db.t1 DISCARD TABLESPACE;
770+
ALTER TABLE dest_db.t1 IMPORT TABLESPACE;
771+
CHECK TABLE dest_db.t1;
772+
Table Op Msg_type Msg_text
773+
dest_db.t1 check status OK
774+
SHOW CREATE TABLE dest_db.t1;
775+
Table Create Table
776+
t1 CREATE TABLE `t1` (
777+
`id` int(11) NOT NULL,
778+
`age` int(11) DEFAULT NULL,
779+
`name` varchar(20) DEFAULT NULL,
780+
PRIMARY KEY (`id`),
781+
KEY `index2` (`name`,`age`)
782+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
783+
SELECT * FROM dest_db.t1;
784+
id age name
785+
DROP TABLE dest_db.t1;
786+
ALTER TABLE source_db.t1 DROP INDEX index2, algorithm=inplace;
787+
FLUSH TABLES source_db.t1 FOR EXPORT;
788+
UNLOCK TABLES;
789+
USE dest_db;
790+
CREATE TABLE `t1` (
791+
`id` int(11) NOT NULL,
792+
`age` int(11) DEFAULT NULL,
793+
`name` varchar(20) DEFAULT NULL,
794+
PRIMARY KEY (`id`)
795+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
796+
ALTER TABLE dest_db.t1 DISCARD TABLESPACE;
797+
ALTER TABLE dest_db.t1 IMPORT TABLESPACE;
798+
CHECK TABLE dest_db.t1;
799+
Table Op Msg_type Msg_text
800+
dest_db.t1 check status OK
801+
SHOW CREATE TABLE dest_db.t1;
802+
Table Create Table
803+
t1 CREATE TABLE `t1` (
804+
`id` int(11) NOT NULL,
805+
`age` int(11) DEFAULT NULL,
806+
`name` varchar(20) DEFAULT NULL,
807+
PRIMARY KEY (`id`)
808+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
809+
SELECT * FROM dest_db.t1;
810+
id age name
811+
DROP TABLE dest_db.t1;
812+
DROP TABLE source_db.t1;
813+
DROP DATABASE source_db;
814+
DROP DATABASE dest_db;

mysql-test/suite/innodb/t/innodb-alter.test

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,33 @@ ALTER TABLE t1 CHANGE COLUMN C1 c5 INT;
420420
SHOW CREATE TABLE t1;
421421
SHOW CREATE TABLE t2;
422422
DROP TABLE t2, t1;
423+
424+
--echo #
425+
--echo #BUG#21514135 SCHEMA MISMATCH ERROR WHEN IMPORTING TABLESPACE AFTER
426+
--echo #DROPPING AN INDEX
427+
--echo #
428+
let $source_db = source_db;
429+
let $dest_db = dest_db;
430+
431+
eval CREATE DATABASE $source_db;
432+
eval CREATE DATABASE $dest_db;
433+
434+
eval CREATE TABLE $source_db.t1 (
435+
id int(11) NOT NULL,
436+
age int(11) DEFAULT NULL,
437+
name varchar(20),
438+
PRIMARY KEY (id),
439+
KEY index1 (age)
440+
) ENGINE=InnoDB;
441+
442+
eval ALTER TABLE $source_db.t1 DROP INDEX index1, ADD INDEX index2(name, age), algorithm=inplace;
443+
444+
--source suite/innodb/include/import.inc
445+
446+
eval ALTER TABLE $source_db.t1 DROP INDEX index2, algorithm=inplace;
447+
448+
--source suite/innodb/include/import.inc
449+
450+
eval DROP TABLE $source_db.t1;
451+
eval DROP DATABASE $source_db;
452+
eval DROP DATABASE $dest_db;

storage/innobase/handler/handler0alter.cc

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7108,6 +7108,61 @@ commit_cache_rebuild(
71087108
DBUG_VOID_RETURN;
71097109
}
71107110

7111+
/** Store the column number of the columns in a list belonging
7112+
to indexes which are not being dropped.
7113+
@param[in] ctx In-place ALTER TABLE context
7114+
@param[in, out] drop_col_list list which will be set, containing columns
7115+
which is part of index being dropped */
7116+
static
7117+
void
7118+
get_col_list_to_be_dropped(
7119+
ha_innobase_inplace_ctx* ctx,
7120+
std::set<ulint>& drop_col_list)
7121+
{
7122+
for (ulint index_count = 0; index_count < ctx->num_to_drop_index;
7123+
index_count++) {
7124+
dict_index_t* index = ctx->drop_index[index_count];
7125+
7126+
for (ulint col = 0; col < index->n_user_defined_cols; col++) {
7127+
ulint col_no = dict_index_get_nth_col_no(index, col);
7128+
drop_col_list.insert(col_no);
7129+
}
7130+
}
7131+
}
7132+
7133+
/** For each column, which is part of an index which is not going to be
7134+
dropped, it checks if the column number of the column is same as col_no
7135+
argument passed.
7136+
@param[in] table table object
7137+
@param[in] col_no column number of the column which is to be checked
7138+
@retval true column exists
7139+
@retval false column does not exist. */
7140+
static
7141+
bool
7142+
check_col_exists_in_indexes(
7143+
const dict_table_t* table,
7144+
ulint col_no)
7145+
{
7146+
for (dict_index_t* index = dict_table_get_first_index(table); index;
7147+
index = dict_table_get_next_index(index)) {
7148+
7149+
if (index->to_be_dropped) {
7150+
continue;
7151+
}
7152+
7153+
for (ulint col = 0; col < index->n_user_defined_cols; col++) {
7154+
7155+
ulint index_col_no = dict_index_get_nth_col_no(
7156+
index, col);
7157+
if (col_no == index_col_no) {
7158+
return(true);
7159+
}
7160+
}
7161+
}
7162+
7163+
return(false);
7164+
}
7165+
71117166
/** Commit the changes made during prepare_inplace_alter_table()
71127167
and inplace_alter_table() inside the data dictionary tables,
71137168
when not rebuilding the table.
@@ -7141,6 +7196,21 @@ commit_try_norebuild(
71417196
|| ctx->num_to_drop_vcol
71427197
== ha_alter_info->alter_info->drop_list.elements);
71437198

7199+
7200+
std::set<ulint> drop_list;
7201+
std::set<ulint>::iterator col_no;
7202+
7203+
/* Check if the column, part of an index to be dropped is part of any
7204+
other index which is not being dropped. If it so, then set the ord_part
7205+
of the column to 0. */
7206+
get_col_list_to_be_dropped(ctx, drop_list);
7207+
7208+
for(col_no = drop_list.begin(); col_no != drop_list.end(); ++col_no) {
7209+
if (!check_col_exists_in_indexes(ctx->new_table, *col_no)) {
7210+
ctx->new_table->cols[*col_no].ord_part = 0;
7211+
}
7212+
}
7213+
71447214
for (ulint i = 0; i < ctx->num_to_add_index; i++) {
71457215
dict_index_t* index = ctx->add_index[i];
71467216
DBUG_ASSERT(dict_index_get_online_status(index)

0 commit comments

Comments
 (0)