Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-37825

Misleading ERROR 1020 message on snapshot isolation with FK

    XMLWordPrintable

Details

    Description

      With innodb_snapshot_isolation=ON, inserting a new record that references a not-yet-visible record via a foreign key constraint causes an error:

      ERROR 1020 (HY000): Record has changed since last read in table '(inserted table)'

      This error mentions the wrong table: The changed table is the one referenced by the foreign key constaint, not the one the current INSERT operates on. This is misleading and causes confusion when debugging.

      The error can be recreated with these statements:

      -- Tables
      create table RecordChange1 (id int primary key);
      create table RecordChange2 (id2 int primary key, fk int references RecordChange1 (id));
       
      -- Connection 1
      start transaction;
      select * from RecordChange1;
      -- continue later...
       
      -- Concurrent Connection 2
      start transaction;
      insert into RecordChange1 (id) values (1);
      commit;
       
      -- Continue in Connection 1
      insert into RecordChange2 (id2, fk) values (2, 1);
      -- ERROR 1020 (HY000): Record has changed since last read in table 'RecordChange2'
      

      Note that the error message mentions RecordChange2, but the changed record is actually in RecordChange1.

      Context: https://mariadb.zulipchat.com/#narrow/channel/118759-general/topic/Snapshot.20Isolation.20Error/with/543722639

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              gechterling Georg Echterling
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.