Skip to content

Dropping a table referenced by a foreign key breaks some information_schema tables, dolt diff #7005

@zachmu

Description

@zachmu

Repro:

create table parent(a int primary key, b int);
create table child(c int primary key);
alter table child add foreign key (c) references parent(a);
call dolt_commit('-Am', 'new tables');
set foreign_key_checks=0;
drop table parent;
set foreign_key_checks=1;

Now selecting from the information_schema.referential_constraints table fails:

select * from information_schema.referential_constraints;
table not found: parent

Worse, dolt diff panics:

dolt diff HEAD~
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x1c24085]

goroutine 1 [running]:
github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlfmt.GenerateCreateTableForeignKeyDefinition({{0xc000f66bd8, 0x8}, {0xc000f66be0, 0x5}, {0x0, 0x0}, {0xc000f66bc8, 0x1, 0x1}, {0xc000f66be6, ...}, ...}, ...)
        /c/Users/zachmu/liquidata/go-workspace/src/github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlfmt/schema_fmt.go:77 +0x465
github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlfmt.GenerateCreateTableStatement({0xc000f67450, 0x5}, {0x30c2c28, 0xc000e81b60}, {0xc00018b800, 0x1, 0x302c830?}, 0xc0011514a0?)
        /c/Users/zachmu/liquidata/go-workspace/src/github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlfmt/schema_fmt.go:290 +0x630

In general, it's not safe to assume that a referenced foreign key table exists, they can be invalid.

Other things to test that I haven't yet:

INSERT, DELETE operations should still work on child after this setup (the defunct foreign key should be ignored).

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcorrectnessWe don't return the same result as MySQLcustomer issuegood reproEasily reproducible bugspanic

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions