WL#13588: Deprecate support for prefix keys in partition functions
Affects: Server-8.0
—
Status: Complete
When testing MySQL support for prefix keys in partition functions, we see that
the implementation does not actually take into account the prefix key (!).
When a table includes a column having prefix key index in
the PARTITION BY KEY clause, that column has no effect on
partition calculations.
eg: CREATE TABLE `t1` (
`a` VARCHAR(10000),
`b` VARCHAR(25),
`c` VARCHAR(10),
PRIMARY KEY (a(10), b, c(2))
) PARTITION BY KEY() PARTITIONS 2;
In this example, the columns `a` and `c` are not
considered during partition calculations.
Implementing this functionality now in 8.0 will result in different partitioning
in existing tables, and hence requiring the tables to be re-partitioned, with
added challenges for cross-version replication.
(This behavior is seen for all SEs supporting partitioning. Additionally, NDB
does not support index prefixes altogether).
The functionality is therefore suggested deprecated in 8.0.
This functionality is not widely used, so we consider
deprecation and removal to affect few use-cases.
Functional requirements: ```````````````````````` FR1: On CREATE TABLE, if the table has prefix key indexes in the PARTITION BY KEY() function, a deprecation warning shall be sent to the client for each prefix key index used. FR2: On ALTER TABLE, if the table has prefix key indexes in the PARTITION BY KEY() function, a deprecation warning shall be sent to the client for each prefix key index used. Upgrade Related: ---------------- U1) On upgrade from 5.7, if an existing table has prefix key indexes in the PARTITION BY KEY() function, the deprecation warning will be printed in the error log for each prefix key index used. U2) On upgrade from lower 8.0.x version, if an existing table has prefix key indexes in the PARTITION BY KEY() function, the deprecation warning will be printed in the error log for each prefix key index used.
I. INTRODUCTION:
````````````````
This WL aims to throw deprecation warnings when a table
uses prefix key indexes in the PARTITION BY KEY() function.
The below sections provide more detail.
II. DESIGN:
```````````
1. Changes to current behaviour:
--------------------------------
On running CREATE TABLE or ALTER TABLE, if a prefix key
index is detected in the PARTITION BY KEY() function,
deprecation warnings will be sent to the client, specifying
each prefix key index used.
Note: The ALTER TABLE query being run on an affected table
need not have anything to do with partitioning, eg: even
adding a new column would trigger the warning.
2. Affected Tables:
-------------------
Tables having definition as given below will be affected.
CREATE TABLE tbl_name (
prefix_col {CHAR|VARCHAR|BINARY|VARBINARY} (length),
...
{INDEX|PRIMARY KEY} (prefix_col(index_length), ...)
) PARTITION BY
[LINEAR] KEY [ALGORITHM={1|2}] ()
PARTITIONS num;
3. Why only CHAR|VARCHAR|BINARY|VARBINARY datatypes?
----------------------------------------------------
According to documentation, prefixes CAN be specified for
CHAR, VARCHAR, BINARY, and VARBINARY columns in index
definitions.
Additionally, a prefix MUST be specified for BLOB and TEXT
columns in index definitions.
However, when partitioning by [LINEAR] KEY, it is NOT
possible to use columns of TEXT or BLOB as partitioning
keys.
This means that only CHAR, VARCHAR, BINARY, and VARBINARY
columns may be used as both prefix indexes and in the
PARTITION BY KEY() function.
4) What happens when prefix length = column length?
---------------------------------------------------
When the prefix length is the same as column length,
it is equivalent to not specifying a prefix index at all,
and would not trigger the deprecation warning.
eg: CREATE TABLE `t1` (
`a` VARCHAR(100),
`b` VARCHAR(25),
PRIMARY KEY (a(100), b)
) PARTITION BY KEY() PARTITIONS 2;
is equivalent to
CREATE TABLE `t1` (
`a` VARCHAR(100),
`b` VARCHAR(25),
PRIMARY KEY (`a`,`b`)
) PARTITION BY KEY() PARTITIONS 2;
III. UPGRADE:
`````````````
On upgrade, deprecation warnings will be sent to the error
log, specifying each prefix key index used in the PARTITION
BY KEY() function.
This applies to both upgrade from 5.7 as well as upgrade
from lower 8.0.x version.
IV. PERFORMANCE:
````````````````
There shouldn't be any performance issues caused by this
WL's changes.
V. DOCUMENTATION:
`````````````````
Update to documentation is required specifying that the use
of prefix indexes in the PARTITION BY KEY() function has no
effect on partition calculations, and is deprecated.
Copyright (c) 2000, 2025, Oracle Corporation and/or its affiliates. All rights reserved.