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

Wrong partitioning by KEY() after key dropped

    XMLWordPrintable

    Details

      Description

      Reproduce

      create or replace table t1 (pk int, x timestamp(6), primary key (pk, x)) engine innodb
      partition by key() partitions 2;
       
      insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
      alter table t1 drop primary key, drop column x, add primary key (pk); 
      select * from t1 partition (p0);
      

      Result

      +----+
      | pk |
      +----+
      |  1 |
      |  2 |
      +----+
      

      Both records are in p0 which is unacceptable for new partitioning expression.

      Expected

      Table is repartitioned by pk.

      +----+
      | pk |
      +----+
      |  1 |
      +----+
      

      Cause

      Empty key() clause implies that key might be changed by ALTER, but inplace algorithm must not be used since repartitioning is required for a different key.

      Fix

      Prohibit inplace when there is DROP PRIMARY KEY and table is partitioned by key.

      More details

      It seems same problem happens when we use UNIQUE instead of the PRIMARY KEY.

      MariaDB [test]> create or replace table t1 (pk int not null, x timestamp(6), unique ux(pk, x)) engine innodb partition by key() partitions 2;
      Query OK, 0 rows affected (0.69 sec)
      MariaDB [test]> insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');           Query OK, 2 rows affected (0.04 sec)
      Records: 2  Duplicates: 0  Warnings: 0
      MariaDB [test]> alter table t1 drop key ux, drop column x, add unique (pk);                               Query OK, 0 rows affected (1.28 sec)
      Records: 0  Duplicates: 0  Warnings: 0
      MariaDB [test]> select * from t1 partition (p0);                                                          +----+
      | pk |
      +----+
      |  1 |
      |  2 |
      +----+
      2 rows in set (0.00 sec)
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              midenok Aleksey Midenkov
              Reporter:
              midenok Aleksey Midenkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: