Rechercher dans le manuel MySQL
23.2.5 KEY Partitioning
Partitioning by key is similar to partitioning by hash, except
that where hash partitioning employs a user-defined expression,
the hashing function for key partitioning is supplied by the
MySQL server. NDB Cluster uses
MD5()
for this purpose; for
tables using other storage engines, the server employs its own
internal hashing function which is based on the same algorithm
as PASSWORD()
.
The syntax rules for CREATE TABLE ... PARTITION BY
KEY
are similar to those for creating a table that is
partitioned by hash. The major differences are listed here:
KEY
is used rather thanHASH
.KEY
takes only a list of zero or more column names. Any columns used as the partitioning key must comprise part or all of the table's primary key, if the table has one. Where no column name is specified as the partitioning key, the table's primary key is used, if there is one. For example, the followingCREATE TABLE
statement is valid in MySQL 8.0:If there is no primary key but there is a unique key, then the unique key is used for the partitioning key:
- )
- PARTITIONS 2;
However, if the unique key column were not defined as
NOT NULL
, then the previous statement would fail.In both of these cases, the partitioning key is the
id
column, even though it is not shown in the output ofSHOW CREATE TABLE
or in thePARTITION_EXPRESSION
column of theINFORMATION_SCHEMA.PARTITIONS
table.Unlike the case with other partitioning types, columns used for partitioning by
KEY
are not restricted to integer orNULL
values. For example, the followingCREATE TABLE
statement is valid:The preceding statement would not be valid, were a different partitioning type to be specified. (In this case, simply using
PARTITION BY KEY()
would also be valid and have the same effect asPARTITION BY KEY(s1)
, sinces1
is the table's primary key.)For additional information about this issue, see Section 23.6, “Restrictions and Limitations on Partitioning”.
NoteTables using the
NDB
storage engine are implicitly partitioned byKEY
, again using the table's primary key as the partitioning key. In the event that the NDB Cluster table has no explicit primary key, the “hidden” primary key generated by theNDB
storage engine for each NDB Cluster table is used as the partitioning key.If you define an explicit partitioning scheme for an
NDB
table, the table must have an explicit primary key, and any columns used in the partitioning expression must be part of this key. However, if the table uses an “empty” partitioning expression—that is,PARTITION BY KEY()
with no column references—then no explicit primary key is required.You can observe this partitioning using the ndb_desc utility (with the
-p
option).ImportantFor a key-partitioned table, you cannot execute an
ALTER TABLE DROP PRIMARY KEY
, as doing so generates the error ERROR 1466 (HY000): Field in list of fields for partition function not found in table. This is not an issue for NDB Cluster tables which are partitioned byKEY
; in such cases, the table is reorganized using the “hidden” primary key as the table's new partitioning key. See Chapter 22, MySQL NDB Cluster 8.0.
It is also possible to partition a table by linear key. Here is a simple example:
- col3 DATE
- )
- PARTITIONS 3;
The LINEAR
keyword has the same effect on
KEY
partitioning as it does on
HASH
partitioning, with the partition number
being derived using a powers-of-two algorithm rather than modulo
arithmetic. See Section 23.2.4.1, “LINEAR HASH Partitioning”, for
a description of this algorithm and its implications.
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-partitioning-key.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.