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

ONLINE Add Foreign Key

    XMLWordPrintable

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Cannot Reproduce
    • N/A
    • Server
    • None

    Description

      MariaDB 10.8.7

      I'm trying to add a new foreign key without any FK checks or tables locked.

      I tried this (with and without "GLOBAL"):

      SET GLOBAL FOREIGN_KEY_CHECKS=OFF;
      ALTER ONLINE TABLE `table` ADD FOREIGN KEY (`initiator`) REFERENCES `main_table`(`uid`) ON DELETE RESTRICT ON UPDATE RESTRICT;
      SET GLOBAL FOREIGN_KEY_CHECKS=ON;
      

      However, I get this error:

      #1846 - LOCK=NONE is not supported. Reason: Adding foreign keys needs foreign_key_checks=OFF. Try LOCK=SHARED

      Then I tried without "ONLINE":

      SET GLOBAL FOREIGN_KEY_CHECKS=OFF;
      ALTER TABLE `table` ADD FOREIGN KEY (`initiator`) REFERENCES `main_table`(`uid`) ON DELETE RESTRICT ON UPDATE RESTRICT;
      SET GLOBAL FOREIGN_KEY_CHECKS=ON;
      

      However, the "main_table" gets immediately locked for many queries, with "Waiting for table metadata lock".

      If I'm disabling FOREIGN_KEY_CHECKS, isn't the ALTER TABLE supposed to be performed ONLINE, without locking any tables and without checking for integrity?

      Attachments

        Issue Links

          Activity

            People

              marko Marko Mäkelä
              nunop Nuno
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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