dolthub / dolthub/dolt

Foreign key corruption: `foreign key has entered an invalid state`

Open
#8,954 1 comment 1 reaction 0 assignees View on GitHub
bug no repro sql
Dominant language
Go
Stars
24.4k
Forks
873
Avg merge
1d 8h
Merged PRs (30d)
120

Description

It's possible for foreign keys in Dolt to become corrupted through certain schema changes, exact mechanism unclear at this point. The symptom is that a call to `dolt_commit()` fails with a message like this:

```sql
Failed to commit changes.
cause: foreign key `paperinfo02_ibfk_1` has entered an invalid state, table `paperinfo02` is missing the index `pinc2`
```

The workaround is to drop and recreate the foreign key with the same definition.

```sql
alter table paperinfo02 drop constraint `paperinfo02_ibfk_1`;
alter table paperinfo02 add constraint `paperinfo02_ibfk_1` FOREIGN KEY (`id_coderinfo`) REFERENCES `coderinfo02` (`id_coderinfo`);
```

If you encounter this bug and can reproduce it, please comment to let us know.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by finding a reproducible schema-change sequence that leaves a foreign key invalid, then follow the dolt_commit() path that reports the missing index. Use the provided paperinfo02/coderinfo02 example and verify that the corruption no longer occurs, with a regression test covering the failing commit.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.