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

Add Foreign key to a table instantly without checking existing data

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      We have received a request to add foreign keys to a table instantly but validating the existing data at a later stage.
      According to the customer, this feature is supported by PostgreSQL (NOT VALID keyword).
      https://dba.stackexchange.com/a/271585

      Currently adding a foreign key locks the table and it is not supported by ALTER TABLE ... ALGORITHM=INSTANT.

      Attachments

        Issue Links

          Activity

            Note that in MariaDB 10.11 one can use ALTER TABLE ONLINE to add a foreign key without any downtime
            It not instant, but at least it will not block any user of the table.
            I personally don't like an 'instant' operation that may silent fail without the user knowing if the foreign key will be there or not.

            monty Michael Widenius added a comment - Note that in MariaDB 10.11 one can use ALTER TABLE ONLINE to add a foreign key without any downtime It not instant, but at least it will not block any user of the table. I personally don't like an 'instant' operation that may silent fail without the user knowing if the foreign key will be there or not.

            What about SET FOREIGN_KEY_CHECKS=0? AFAIK adding FK under this uses NOCOPY algorithm, not sure which one though

            nikitamalyavin Nikita Malyavin added a comment - What about SET FOREIGN_KEY_CHECKS=0? AFAIK adding FK under this uses NOCOPY algorithm, not sure which one though

            I believe that SET foreign_key_checks=0 should allow FOREIGN KEY constraints to be added ever since MySQL 5.6 or MariaDB Server 10.0.

            Currently, if checks are enabled, adding a constraint will require the table to be copied in the most inefficient way (ALGORITHM=COPY). Once MDEV-16356 is implemented, it should be possible to add a constraint without the server writing much, just reading the affected tables in order to validate the constraint.

            marko Marko Mäkelä added a comment - I believe that SET foreign_key_checks=0 should allow FOREIGN KEY constraints to be added ever since MySQL 5.6 or MariaDB Server 10.0. Currently, if checks are enabled, adding a constraint will require the table to be copied in the most inefficient way ( ALGORITHM=COPY ). Once MDEV-16356 is implemented, it should be possible to add a constraint without the server writing much, just reading the affected tables in order to validate the constraint.

            People

              Unassigned Unassigned
              susmeet.khaire Susmeet Khaire
              Votes:
              1 Vote for this issue
              Watchers:
              8 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.