Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
10.6.15, 10.9.8, 11.1.2, 10.4(EOL), 10.5
-
Docker on Linux Mint 20.3
Description
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2
|
mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql
|
migrate.sql:
CREATE TABLE items (
|
id VARCHAR(20) NOT NULL,
|
PRIMARY KEY (id)
|
);
|
CREATE TABLE sgs_data (
|
id INT(11) NOT NULL AUTO_INCREMENT,
|
Number varchar(15) NOT NULL DEFAULT '',
|
PRIMARY KEY (id)
|
);
|
SET foreign_key_checks=0;
|
ALTER TABLE sgs_data
|
CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL,
|
ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id);
|
This causes the MariaDB server to crash (see attached log output).
- Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash
- Removing `SET foreign_key_checks=0` avoids the crash
- Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash.
Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker).
Attachments
Issue Links
- is caused by
-
MDEV-31086 MODIFY COLUMN can break FK constraints, and lead to unrestorable dumps
-
- Closed
-
Activity
Field | Original Value | New Value |
---|---|---|
Description |
{{
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2 mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql }} {{ -- migrate.sql CREATE TABLE items ( id VARCHAR(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE sgs_data ( id INT(11) NOT NULL AUTO_INCREMENT, Number varchar(15) NOT NULL DEFAULT '', PRIMARY KEY (id) ); SET foreign_key_checks=0; ALTER TABLE sgs_data CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL, ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id); }} This causes the MariaDB server to crash. * Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash * Removing `SET foreign_key_checks=0` avoids the crash * Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash. Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker). |
```
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2 mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql ``` ``` -- migrate.sql CREATE TABLE items ( id VARCHAR(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE sgs_data ( id INT(11) NOT NULL AUTO_INCREMENT, Number varchar(15) NOT NULL DEFAULT '', PRIMARY KEY (id) ); SET foreign_key_checks=0; ALTER TABLE sgs_data CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL, ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id); ``` This causes the MariaDB server to crash. * Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash * Removing `SET foreign_key_checks=0` avoids the crash * Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash. Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker). |
Description |
```
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2 mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql ``` ``` -- migrate.sql CREATE TABLE items ( id VARCHAR(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE sgs_data ( id INT(11) NOT NULL AUTO_INCREMENT, Number varchar(15) NOT NULL DEFAULT '', PRIMARY KEY (id) ); SET foreign_key_checks=0; ALTER TABLE sgs_data CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL, ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id); ``` This causes the MariaDB server to crash. * Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash * Removing `SET foreign_key_checks=0` avoids the crash * Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash. Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker). |
{code}
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2 mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql {/code} ``` -- migrate.sql CREATE TABLE items ( id VARCHAR(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE sgs_data ( id INT(11) NOT NULL AUTO_INCREMENT, Number varchar(15) NOT NULL DEFAULT '', PRIMARY KEY (id) ); SET foreign_key_checks=0; ALTER TABLE sgs_data CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL, ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id); ``` This causes the MariaDB server to crash. * Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash * Removing `SET foreign_key_checks=0` avoids the crash * Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash. Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker). |
Description |
{code}
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2 mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql {/code} ``` -- migrate.sql CREATE TABLE items ( id VARCHAR(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE sgs_data ( id INT(11) NOT NULL AUTO_INCREMENT, Number varchar(15) NOT NULL DEFAULT '', PRIMARY KEY (id) ); SET foreign_key_checks=0; ALTER TABLE sgs_data CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL, ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id); ``` This causes the MariaDB server to crash. * Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash * Removing `SET foreign_key_checks=0` avoids the crash * Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash. Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker). |
{code:SQL}
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2 mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql {code} ``` -- migrate.sql CREATE TABLE items ( id VARCHAR(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE sgs_data ( id INT(11) NOT NULL AUTO_INCREMENT, Number varchar(15) NOT NULL DEFAULT '', PRIMARY KEY (id) ); SET foreign_key_checks=0; ALTER TABLE sgs_data CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL, ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id); ``` This causes the MariaDB server to crash. * Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash * Removing `SET foreign_key_checks=0` avoids the crash * Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash. Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker). |
Description |
{code:SQL}
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2 mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql {code} ``` -- migrate.sql CREATE TABLE items ( id VARCHAR(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE sgs_data ( id INT(11) NOT NULL AUTO_INCREMENT, Number varchar(15) NOT NULL DEFAULT '', PRIMARY KEY (id) ); SET foreign_key_checks=0; ALTER TABLE sgs_data CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL, ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id); ``` This causes the MariaDB server to crash. * Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash * Removing `SET foreign_key_checks=0` avoids the crash * Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash. Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker). |
{code:SQL}
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2 mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql {code} migrate.sql: {code:SQL} CREATE TABLE items ( id VARCHAR(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE sgs_data ( id INT(11) NOT NULL AUTO_INCREMENT, Number varchar(15) NOT NULL DEFAULT '', PRIMARY KEY (id) ); SET foreign_key_checks=0; ALTER TABLE sgs_data CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL, ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id); {code} This causes the MariaDB server to crash. * Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash * Removing `SET foreign_key_checks=0` avoids the crash * Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash. Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker). |
Description |
{code:SQL}
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2 mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql {code} migrate.sql: {code:SQL} CREATE TABLE items ( id VARCHAR(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE sgs_data ( id INT(11) NOT NULL AUTO_INCREMENT, Number varchar(15) NOT NULL DEFAULT '', PRIMARY KEY (id) ); SET foreign_key_checks=0; ALTER TABLE sgs_data CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL, ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id); {code} This causes the MariaDB server to crash. * Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash * Removing `SET foreign_key_checks=0` avoids the crash * Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash. Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker). |
{code:SQL}
docker run --rm -p 20433:3306 -e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=root mariadb:11.1.2 mysql -h 127.0.0.1 --port=20433 -u root -proot test < migrate.sql {code} migrate.sql: {code:SQL} CREATE TABLE items ( id VARCHAR(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE sgs_data ( id INT(11) NOT NULL AUTO_INCREMENT, Number varchar(15) NOT NULL DEFAULT '', PRIMARY KEY (id) ); SET foreign_key_checks=0; ALTER TABLE sgs_data CHANGE COLUMN `Number` itemId VARCHAR(20) NOT NULL, ADD CONSTRAINT fk_sgs_data_itemId FOREIGN KEY (itemId) REFERENCES items (id); {code} This causes the MariaDB server to crash (see attached log output). * Moving the CHANGE COLUMN to a separate ALTER statement avoids the crash * Removing `SET foreign_key_checks=0` avoids the crash * Removing `CREATE TABLE items` still results in a crash even though the foreign key is invalid. If you additionally remove the `SET foreign_key_checks=0` it will instead report that the foreign key is malformed and not crash. Verified on 10.6.15, 10.9.8 and 11.1.2 (all with docker). |
Link |
This issue is caused by |
Component/s | Storage Engine - InnoDB [ 10129 ] | |
Fix Version/s | 10.4 [ 22408 ] | |
Fix Version/s | 10.5 [ 23123 ] | |
Fix Version/s | 10.6 [ 24028 ] | |
Fix Version/s | 10.11 [ 27614 ] | |
Fix Version/s | 11.0 [ 28320 ] | |
Fix Version/s | 11.1 [ 28549 ] | |
Fix Version/s | 11.2 [ 28603 ] | |
Fix Version/s | 11.3 [ 28565 ] | |
Affects Version/s | 10.4 [ 22408 ] | |
Affects Version/s | 10.5 [ 23123 ] | |
Assignee | Thirunarayanan Balathandayuthapani [ thiru ] | |
Labels | crash | crash foreign-keys regression |
Status | Open [ 1 ] | Confirmed [ 10101 ] |
Priority | Major [ 3 ] | Critical [ 2 ] |
Status | Confirmed [ 10101 ] | In Progress [ 3 ] |
Assignee | Thirunarayanan Balathandayuthapani [ thiru ] | Marko Mäkelä [ marko ] |
Status | In Progress [ 3 ] | In Review [ 10002 ] |
Assignee | Marko Mäkelä [ marko ] | Thirunarayanan Balathandayuthapani [ thiru ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Fix Version/s | 10.4.32 [ 29300 ] | |
Fix Version/s | 10.4 [ 22408 ] | |
Fix Version/s | 10.5 [ 23123 ] | |
Fix Version/s | 10.6 [ 24028 ] | |
Fix Version/s | 10.11 [ 27614 ] | |
Fix Version/s | 11.0 [ 28320 ] | |
Fix Version/s | 11.1 [ 28549 ] | |
Fix Version/s | 11.3 [ 28565 ] | |
Fix Version/s | 11.2 [ 28603 ] | |
Resolution | Fixed [ 1 ] | |
Status | Stalled [ 10000 ] | Closed [ 6 ] |
Fix Version/s | 10.5.23 [ 29012 ] | |
Fix Version/s | 10.6.16 [ 29014 ] | |
Fix Version/s | 10.10.7 [ 29018 ] | |
Fix Version/s | 10.11.6 [ 29020 ] | |
Fix Version/s | 11.0.4 [ 29021 ] | |
Fix Version/s | 11.1.3 [ 29023 ] | |
Fix Version/s | 11.2.2 [ 29035 ] |
Fix Version/s | 10.4.33 [ 29516 ] | |
Fix Version/s | 10.5.24 [ 29517 ] | |
Fix Version/s | 10.6.17 [ 29518 ] | |
Fix Version/s | 10.11.7 [ 29519 ] | |
Fix Version/s | 11.0.5 [ 29520 ] | |
Fix Version/s | 11.1.4 [ 29024 ] | |
Fix Version/s | 11.2.3 [ 29521 ] | |
Fix Version/s | 11.3.2 [ 29522 ] | |
Fix Version/s | 10.5.23 [ 29012 ] | |
Fix Version/s | 10.6.16 [ 29014 ] | |
Fix Version/s | 10.10.7 [ 29018 ] | |
Fix Version/s | 10.11.6 [ 29020 ] | |
Fix Version/s | 11.0.4 [ 29021 ] | |
Fix Version/s | 11.1.3 [ 29023 ] | |
Fix Version/s | 11.2.2 [ 29035 ] | |
Fix Version/s | 10.4.32 [ 29300 ] |
This is something that was missed in
MDEV-32527,MDEV-32337,MDEV-32060,MDEV-31869and caused by the fix ofMDEV-31086.We fail to check for a null pointer:
diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index 092aa54737d..6da95e42c11 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -7759,12 +7759,15 @@ bool check_col_is_in_fk_indexes(
for (const auto &a : add_fk)
{
- for (ulint i= 0; i < a->n_fields; i++)
+ if (const dict_index_t* foreign_index= a->foreign_index)
{
- if (a->foreign_index->fields[i].col == col)
+ for (ulint i= 0; i < a->n_fields; i++)
{
- fk_id= a->id;
- goto err_exit;
+ if (foreign_index->fields[i].col == col)
+ {
+ fk_id= a->id;
+ goto err_exit;
+ }
}
}