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

Partial support of foreign keys in partitioned tables

    XMLWordPrintable

Details

    Description

      Implementation of foreign keys in partitioned tables with limitations is relatively simple and is covered by this task. Full support of foreign keys in partitioning is covered by MDEV-12483.

      This task is basically divided into 3 parts:

      1. Remove prohibiting code, this allows FKs to be created for partitions and DML to work;
      2. Allow partitioned FKs at SQL layer for such functions as SHOW CREATE;
      3. Implement correct handling of FKs when partitioning configuration changes.

      Limitations

      1. Foreign keys cannot refer partitioned table

      Foreign keys cannot refer to partitioned table even SYSTEM_TIME-partitioned still. create_foreign_keys() at InnoDB layer receives Foreign_key about referenced table T, but no such table exists at InnoDB layer, only partition tables T#P#p0, T#P#p1, ..., T#P#pn. Finding out it is SYSTEM_TIME partitioning and current partition at that point is impossible without modification of SYS_TABLES or opening TABLE object of referenced table. Both should be avoided as this is superseded by MDEV-12483.

      2. CASCADE and SET NULL actions cannot work

      In partitioned foreign table CASCADE and SET NULL actions cannot work as these actions update row data which is the subject of row placement into another partition and that cannot be done at InnoDB layer. DELETE CASCADE for SYSTEM_TIME partitioning requires the row to be moved from current to history partition. CASCADE and SET NULL actions disabled completely in CREATE TABLE for partitioned foreign tables in this task.

      Allow partitioned FKs at SQL layer for such functions as SHOW CREATE

      Through standard handler interface get_foreign_key_list() foreign keys are returned to SQL layer. For SYSTEM_TIME partitioning from current partition, for any other partitioning from first read-marked partition.

      Implement correct handling of FKs when partitioning configuration changes

      ALTER operations such as ADD PARTITION, DROP PARTITION, REMOVE PARTITIONING , etc. must be reflected into correct configuration of foreign keys in InnoDB. Handling of foreign key ID for temporary tables in ALTER may be done similar to MDEV-28933.

      Attachments

        1. y.test
          1 kB
        2. y.result
          3 kB

        Issue Links

          Activity

            People

              sanja Oleksandr Byelkin
              midenok Aleksey Midenkov
              Votes:
              7 Vote for this issue
              Watchers:
              14 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.