MDEV-23675 Assertion `pos < table->n_def' fails in dict_table_get_nth_col

- During insertion of clustered inde, InnoDB does the check for
foreign key constraints. It rebuild the tuple based on foreign
column names when there is no foreign index. While rebuilding,
InnoDB should ignore the dropped columns.
parent 6a137625
...@@ -755,4 +755,17 @@ DROP TABLE t1; ...@@ -755,4 +755,17 @@ DROP TABLE t1;
CREATE TABLE t1 (a GEOMETRY, INDEX(a(8)), CREATE TABLE t1 (a GEOMETRY, INDEX(a(8)),
FOREIGN KEY (a) REFERENCES x (xx)) ENGINE=InnoDB; FOREIGN KEY (a) REFERENCES x (xx)) ENGINE=InnoDB;
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
#
# MDEV-23675 Assertion `pos < table->n_def' in dict_table_get_nth_col
#
CREATE TABLE t1 (pk int PRIMARY KEY, a INT, b INT, c INT, KEY(c),
FOREIGN KEY fx (b) REFERENCES t1 (c))
ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,0,10,10);
ALTER TABLE t1 DROP a, ALGORITHM=INSTANT;
SET FOREIGN_KEY_CHECKS= 0;
DROP INDEX fx ON t1;
INSERT INTO t1 VALUES (2,11,11);
DROP TABLE t1;
SET FOREIGN_KEY_CHECKS=DEFAULT;
# End of 10.4 tests # End of 10.4 tests
...@@ -741,6 +741,20 @@ DROP TABLE t1; ...@@ -741,6 +741,20 @@ DROP TABLE t1;
CREATE TABLE t1 (a GEOMETRY, INDEX(a(8)), CREATE TABLE t1 (a GEOMETRY, INDEX(a(8)),
FOREIGN KEY (a) REFERENCES x (xx)) ENGINE=InnoDB; FOREIGN KEY (a) REFERENCES x (xx)) ENGINE=InnoDB;
--echo #
--echo # MDEV-23675 Assertion `pos < table->n_def' in dict_table_get_nth_col
--echo #
CREATE TABLE t1 (pk int PRIMARY KEY, a INT, b INT, c INT, KEY(c),
FOREIGN KEY fx (b) REFERENCES t1 (c))
ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,0,10,10);
ALTER TABLE t1 DROP a, ALGORITHM=INSTANT;
SET FOREIGN_KEY_CHECKS= 0;
DROP INDEX fx ON t1;
INSERT INTO t1 VALUES (2,11,11);
DROP TABLE t1;
SET FOREIGN_KEY_CHECKS=DEFAULT;
-- echo # End of 10.4 tests -- echo # End of 10.4 tests
--source include/wait_until_count_sessions.inc --source include/wait_until_count_sessions.inc
...@@ -1908,8 +1908,14 @@ bool row_ins_foreign_index_entry(dict_foreign_t *foreign, ...@@ -1908,8 +1908,14 @@ bool row_ins_foreign_index_entry(dict_foreign_t *foreign,
{ {
for (ulint j= 0; j < index->n_fields; j++) for (ulint j= 0; j < index->n_fields; j++)
{ {
const char *col_name= dict_table_get_col_name( const dict_col_t *col= dict_index_get_nth_col(index, j);
index->table, dict_index_get_nth_col_no(index, j));
/* A clustered index may contain instantly dropped columns,
which must be skipped. */
if (col->is_dropped())
continue;
const char *col_name= dict_table_get_col_name(index->table, col->ind);
if (0 == innobase_strcasecmp(col_name, foreign->foreign_col_names[i])) if (0 == innobase_strcasecmp(col_name, foreign->foreign_col_names[i]))
{ {
dfield_copy(&ref_entry->fields[i], &entry->fields[j]); dfield_copy(&ref_entry->fields[i], &entry->fields[j]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment