Skip to content

Commit be70f59

Browse files
author
Aakanksha Verma
committed
Bug #26654685 INDEX->ID == BTR_PAGE_GET_INDEX_ID(PAGE) AT
BTR_CUR_SEARCH_TO_NTH_LEVEL IN BTR/B PROBLEM During foreign key check , index id value is getting corrupted as the check for index creation being aborted is not done. FIX Add the check , backported patch from 8.0 jimmy's patch Reviewed by : Jimmy Yang<Jimmy.Yang@oracle.com> RB: 19262
1 parent c1bc6c0 commit be70f59

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
2+
INSERT INTO parent VALUES(1,2),(2,2);
3+
CREATE TABLE child (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
4+
INSERT INTO child VALUES (10, 2);
5+
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create
6+
WAIT_FOR go_ahead';
7+
CREATE UNIQUE INDEX idx ON parent(b);;
8+
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
9+
INSERT INTO parent VALUES(4, 2);
10+
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
11+
ERROR 23000: Duplicate entry '2' for key 'idx'
12+
SET DEBUG_SYNC = 'now SIGNAL conn_add_fk';
13+
SET DEBUG_SYNC = 'now WAIT_FOR conn_add_fk';
14+
ALTER TABLE child ADD CONSTRAINT cfx FOREIGN KEY (b) REFERENCES parent(b);
15+
ERROR HY000: Cannot add foreign key constraint
16+
DROP TABLE child;
17+
DROP TABLE parent;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#
2+
## Bug #26654685 INDEX->ID == BTR_PAGE_GET_INDEX_ID(PAGE)
3+
## AT BTR_CUR_SEARCH_TO_NTH_LEVEL IN BTR/B
4+
#
5+
6+
--source include/have_debug.inc
7+
--source include/have_debug_sync.inc
8+
--source include/count_sessions.inc
9+
--source include/have_innodb_16k.inc
10+
11+
CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
12+
INSERT INTO parent VALUES(1,2),(2,2);
13+
CREATE TABLE child (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
14+
INSERT INTO child VALUES (10, 2);
15+
16+
# This should rollback due to dup key
17+
SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create
18+
WAIT_FOR go_ahead';
19+
--send CREATE UNIQUE INDEX idx ON parent(b);
20+
21+
# Make table ref_count > 1
22+
connect (con1,localhost,root,,);
23+
connection con1;
24+
SET DEBUG_SYNC = 'now WAIT_FOR start_create';
25+
INSERT INTO parent VALUES(4, 2);
26+
SET DEBUG_SYNC = 'now SIGNAL go_ahead';
27+
28+
connection default;
29+
--error ER_DUP_ENTRY
30+
reap;
31+
SET DEBUG_SYNC = 'now SIGNAL conn_add_fk';
32+
33+
connection con1;
34+
SET DEBUG_SYNC = 'now WAIT_FOR conn_add_fk';
35+
--error ER_CANNOT_ADD_FOREIGN
36+
ALTER TABLE child ADD CONSTRAINT cfx FOREIGN KEY (b) REFERENCES parent(b);
37+
38+
--connection default
39+
DROP TABLE child;
40+
DROP TABLE parent;
41+
--disconnect con1

storage/innobase/dict/dict0dict.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 1996, 2018, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2012, Facebook Inc.
55
66
This program is free software; you can redistribute it and/or modify it under
@@ -3378,7 +3378,10 @@ dict_foreign_find_index(
33783378
&& dict_foreign_qualify_index(
33793379
table, col_names, columns, n_cols,
33803380
index, types_idx,
3381-
check_charsets, check_null)) {
3381+
check_charsets, check_null)
3382+
&& (!(index->online_status ==
3383+
ONLINE_INDEX_ABORTED_DROPPED
3384+
||index->online_status == ONLINE_INDEX_ABORTED))) {
33823385
return(index);
33833386
}
33843387

0 commit comments

Comments
 (0)