[MDEV-19751] Wrong partitioning by KEY() after key dropped Created: 2019-06-13  Updated: 2020-05-28  Resolved: 2020-05-26

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Partitioning
Affects Version/s: 10.2, 10.3, 10.4
Fix Version/s: 10.5.4, 10.2.33, 10.3.24, 10.4.14

Type: Bug Priority: Major
Reporter: Aleksey Midenkov Assignee: Aleksey Midenkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Problem/Incident
causes MDEV-18794 Assertion `!m_innodb' failed in ha_pa... Closed

 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)


Generated at Thu Feb 08 08:54:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.