Rechercher dans le manuel MySQL

23.6 Restrictions and Limitations on Partitioning

This section discusses current restrictions and limitations on MySQL partitioning support.

Prohibited constructs.  The following constructs are not permitted in partitioning expressions:

  • Stored procedures, stored functions, UDFs, or plugins.

  • Declared variables or user variables.

For a list of SQL functions which are permitted in partitioning expressions, see Section 23.6.3, “Partitioning Limitations Relating to Functions”.

Arithmetic and logical operators.  Use of the arithmetic operators +, -, and * is permitted in partitioning expressions. However, the result must be an integer value or NULL (except in the case of [LINEAR] KEY partitioning, as discussed elsewhere in this chapter; see Section 23.2, “Partitioning Types”, for more information).

The DIV operator is also supported; the / operator is not permitted.

The bit operators |, &, ^, <<, >>, and ~ are not permitted in partitioning expressions.

Server SQL mode.  Tables employing user-defined partitioning do not preserve the SQL mode in effect at the time that they were created. As discussed elsewhere in this Manual (see Section 5.1.11, “Server SQL Modes”), the results of many MySQL functions and operators may change according to the server SQL mode. Therefore, a change in the SQL mode at any time after the creation of partitioned tables may lead to major changes in the behavior of such tables, and could easily lead to corruption or loss of data. For these reasons, it is strongly recommended that you never change the server SQL mode after creating partitioned tables.

Examples.  The following examples illustrate some changes in behavior of partitioned tables due to a change in the server SQL mode:

  1. Error handling.  As discussed elsewhere, handling of special values such as zero and NULL can differ between different server SQL modes (see Section 5.1.11, “Server SQL Modes”). For example, ERROR_FOR_DIVISION_BY_ZERO can affect whether or not 0 can be inserted as a value into a table whose paritioning expression uses column DIV value or column MOD value.

  2. Table accessibility.  Sometimes a change in the server SQL mode can make partitioned tables unusable. The following CREATE TABLE statement can be executed successfully only if the NO_UNSIGNED_SUBTRACTION mode is in effect:

    1. mysql> SELECT @@sql_mode;
    2. +------------+
    3. | @@sql_mode |
    4. +------------+
    5. |            |
    6. +------------+
    7. 1 row in set (0.00 sec)
    8.  
    9. mysql> CREATE TABLE tu (c1 BIGINT UNSIGNED)
    10.     ->   PARTITION BY RANGE(c1 - 10) (
    11.     ->     PARTITION p0 VALUES LESS THAN (-5),
    12.     ->     PARTITION p1 VALUES LESS THAN (0),
    13.     ->     PARTITION p2 VALUES LESS THAN (5),
    14.     ->     PARTITION p3 VALUES LESS THAN (10),
    15.     ->     PARTITION p4 VALUES LESS THAN (MAXVALUE)
    16.     -> );
    17. ERROR 1563 (HY000): Partition constant is out of partition function domain
    18.  
    19. mysql> SET sql_mode='NO_UNSIGNED_SUBTRACTION';
    20. Query OK, 0 rows affected (0.00 sec)
    21.  
    22. mysql> SELECT @@sql_mode;
    23. +-------------------------+
    24. | @@sql_mode              |
    25. +-------------------------+
    26. | NO_UNSIGNED_SUBTRACTION |
    27. +-------------------------+
    28. 1 row in set (0.00 sec)
    29.  
    30. mysql> CREATE TABLE tu (c1 BIGINT UNSIGNED)
    31.     ->   PARTITION BY RANGE(c1 - 10) (
    32.     ->     PARTITION p0 VALUES LESS THAN (-5),
    33.     ->     PARTITION p1 VALUES LESS THAN (0),
    34.     ->     PARTITION p2 VALUES LESS THAN (5),
    35.     ->     PARTITION p3 VALUES LESS THAN (10),
    36.     ->     PARTITION p4 VALUES LESS THAN (MAXVALUE)
    37.     -> );
    38. Query OK, 0 rows affected (0.05 sec)

    If you remove the NO_UNSIGNED_SUBTRACTION server SQL mode after creating tu, you may no longer be able to access this table:

    1. mysql> SET sql_mode='';
    2. Query OK, 0 rows affected (0.00 sec)
    3.  
    4. mysql> SELECT * FROM tu;
    5. ERROR 1563 (HY000): Partition constant is out of partition function domain
    6. mysql> INSERT INTO tu VALUES (20);
    7. ERROR 1563 (HY000): Partition constant is out of partition function domain

    See also Section 5.1.11, “Server SQL Modes”.

Server SQL modes also impact replication of partitioned tables. Disparate SQL modes on master and slave can lead to partitioning expressions being evaluated differently; this can cause the distribution of data among partitions to be different in the master's and slave's copies of a given table, and may even cause inserts into partitioned tables that succeed on the master to fail on the slave. For best results, you should always use the same server SQL mode on the master and on the slave.

Performance considerations.  Some effects of partitioning operations on performance are given in the following list:

  • File system operations.  Partitioning and repartitioning operations (such as ALTER TABLE with PARTITION BY ..., REORGANIZE PARTITION, or REMOVE PARTITIONING) depend on file system operations for their implementation. This means that the speed of these operations is affected by such factors as file system type and characteristics, disk speed, swap space, file handling efficiency of the operating system, and MySQL server options and variables that relate to file handling. In particular, you should make sure that large_files_support is enabled and that open_files_limit is set properly. Partitioning and repartitioning operations involving InnoDB tables may be made more efficient by enabling innodb_file_per_table.

    See also Maximum number of partitions.

  • Table locks.  Generally, the process executing a partitioning operation on a table takes a write lock on the table. Reads from such tables are relatively unaffected; pending INSERT and UPDATE operations are performed as soon as the partitioning operation has completed. For InnoDB-specific exceptions to this limitation, see Partitioning Operations.

  • Indexes; partition pruning.  As with nonpartitioned tables, proper use of indexes can speed up queries on partitioned tables significantly. In addition, designing partitioned tables and queries on these tables to take advantage of partition pruning can improve performance dramatically. See Section 23.4, “Partition Pruning”, for more information.

    Index condition pushdown is supported for partitioned tables. See Section 8.2.1.5, “Index Condition Pushdown Optimization”.

  • Performance with LOAD DATA.  In MySQL 8.0, LOAD DATA uses buffering to improve performance. You should be aware that the buffer uses 130 KB memory per partition to achieve this.

Maximum number of partitions.  The maximum possible number of partitions for a given table not using the NDB storage engine is 8192. This number includes subpartitions.

The maximum possible number of user-defined partitions for a table using the NDB storage engine is determined according to the version of the NDB Cluster software being used, the number of data nodes, and other factors. See NDB and user-defined partitioning, for more information.

If, when creating tables with a large number of partitions (but less than the maximum), you encounter an error message such as Got error ... from storage engine: Out of resources when opening file, you may be able to address the issue by increasing the value of the open_files_limit system variable. However, this is dependent on the operating system, and may not be possible or advisable on all platforms; see Section B.4.2.17, “File Not Found and Similar Errors”, for more information. In some cases, using large numbers (hundreds) of partitions may also not be advisable due to other concerns, so using more partitions does not automatically lead to better results.

See also File system operations.

Foreign keys not supported for partitioned InnoDB tables.  Partitioned tables using the InnoDB storage engine do not support foreign keys. More specifically, this means that the following two statements are true:

  1. No definition of an InnoDB table employing user-defined partitioning may contain foreign key references; no InnoDB table whose definition contains foreign key references may be partitioned.

  2. No InnoDB table definition may contain a foreign key reference to a user-partitioned table; no InnoDB table with user-defined partitioning may contain columns referenced by foreign keys.

The scope of the restrictions just listed includes all tables that use the InnoDB storage engine. CREATE TABLE and ALTER TABLE statements that would result in tables violating these restrictions are not allowed.

ALTER TABLE ... ORDER BY.  An ALTER TABLE ... ORDER BY column statement run against a partitioned table causes ordering of rows only within each partition.

Effects on REPLACE statements by modification of primary keys.  It can be desirable in some cases (see Section 23.6.1, “Partitioning Keys, Primary Keys, and Unique Keys”) to modify a table's primary key. Be aware that, if your application uses REPLACE statements and you do this, the results of these statements can be drastically altered. See Section 13.2.9, “REPLACE Syntax”, for more information and an example.

FULLTEXT indexes.  Partitioned tables do not support FULLTEXT indexes or searches.

Spatial columns.  Columns with spatial data types such as POINT or GEOMETRY cannot be used in partitioned tables.

Temporary tables.  Temporary tables cannot be partitioned.

Log tables.  It is not possible to partition the log tables; an ALTER TABLE ... PARTITION BY ... statement on such a table fails with an error.

Data type of partitioning key.  A partitioning key must be either an integer column or an expression that resolves to an integer. Expressions employing ENUM columns cannot be used. The column or expression value may also be NULL; see Section 23.2.7, “How MySQL Partitioning Handles NULL”.

There are two exceptions to this restriction:

  1. When partitioning by [LINEAR] KEY, it is possible to use columns of any valid MySQL data type other than TEXT or BLOB as partitioning keys, because the internal key-hashing functions produce the correct data type from these types. For example, the following two CREATE TABLE statements are valid:

    1. CREATE TABLE tkc (c1 CHAR)
    2. PARTITION BY KEY(c1)
    3. PARTITIONS 4;
    4.  
    5.     ( c1 ENUM('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet') )
    6. PARTITION BY LINEAR KEY(c1)
    7. PARTITIONS 6;
  2. When partitioning by RANGE COLUMNS or LIST COLUMNS, it is possible to use string, DATE, and DATETIME columns. For example, each of the following CREATE TABLE statements is valid:

    1. CREATE TABLE rc (c1 INT, c2 DATE)
    2. PARTITION BY RANGE COLUMNS(c2) (
    3.     PARTITION p0 VALUES LESS THAN('1990-01-01'),
    4.     PARTITION p1 VALUES LESS THAN('1995-01-01'),
    5.     PARTITION p2 VALUES LESS THAN('2000-01-01'),
    6.     PARTITION p3 VALUES LESS THAN('2005-01-01'),
    7.     PARTITION p4 VALUES LESS THAN(MAXVALUE)
    8. );
    9.  
    10. CREATE TABLE lc (c1 INT, c2 CHAR(1))
    11. PARTITION BY LIST COLUMNS(c2) (
    12.     PARTITION p0 VALUES IN('a', 'd', 'g', 'j', 'm', 'p', 's', 'v', 'y'),
    13.     PARTITION p1 VALUES IN('b', 'e', 'h', 'k', 'n', 'q', 't', 'w', 'z'),
    14.     PARTITION p2 VALUES IN('c', 'f', 'i', 'l', 'o', 'r', 'u', 'x', NULL)
    15. );

Neither of the preceding exceptions applies to BLOB or TEXT column types.

Subqueries.  A partitioning key may not be a subquery, even if that subquery resolves to an integer value or NULL.

Issues with subpartitions.  Subpartitions must use HASH or KEY partitioning. Only RANGE and LIST partitions may be subpartitioned; HASH and KEY partitions cannot be subpartitioned.

SUBPARTITION BY KEY requires that the subpartitioning column or columns be specified explicitly, unlike the case with PARTITION BY KEY, where it can be omitted (in which case the table's primary key column is used by default). Consider the table created by this statement:

  1.     name VARCHAR(30)
  2. );

You can create a table having the same columns, partitioned by KEY, using a statement such as this one:

  1.     name VARCHAR(30)
  2. )
  3. PARTITIONS 4;

The previous statement is treated as though it had been written like this, with the table's primary key column used as the partitioning column:

  1.     name VARCHAR(30)
  2. )
  3. PARTITION BY KEY(id)
  4. PARTITIONS 4;

However, the following statement that attempts to create a subpartitioned table using the default column as the subpartitioning column fails, and the column must be specified for the statement to succeed, as shown here:

  1. mysql> CREATE TABLE ts (
  2.     ->     name VARCHAR(30)
  3.     -> )
  4.     -> PARTITION BY RANGE(id)
  5.     -> SUBPARTITION BY KEY()
  6.     -> SUBPARTITIONS 4
  7.     -> (
  8.     ->     PARTITION p0 VALUES LESS THAN (100),
  9.     ->     PARTITION p1 VALUES LESS THAN (MAXVALUE)
  10.     -> );
  11. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
  12. corresponds to your MySQL server version for the right syntax to use near ')
  13.  
  14. mysql> CREATE TABLE ts (
  15.    ->     id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  16.    ->     name VARCHAR(30)
  17.    -> )
  18.    -> PARTITION BY RANGE(id)
  19.    -> SUBPARTITION BY KEY(id)
  20.    -> SUBPARTITIONS 4
  21.    -> (
  22.    ->     PARTITION p0 VALUES LESS THAN (100),
  23.    ->     PARTITION p1 VALUES LESS THAN (MAXVALUE)
  24.    -> );
  25. Query OK, 0 rows affected (0.07 sec)

This is a known issue (see Bug #51470).

DATA DIRECTORY and INDEX DIRECTORY options.  Table-level DATA DIRECTORY and INDEX DIRECTORY options are ignored (see Bug #32091). You can employ these options for individual partitions or subpartitions of InnoDB tables.

Repairing and rebuilding partitioned tables.  The statements CHECK TABLE, OPTIMIZE TABLE, ANALYZE TABLE, and REPAIR TABLE are supported for partitioned tables.

In addition, you can use ALTER TABLE ... REBUILD PARTITION to rebuild one or more partitions of a partitioned table; ALTER TABLE ... REORGANIZE PARTITION also causes partitions to be rebuilt. See Section 13.1.9, “ALTER TABLE Syntax”, for more information about these two statements.

ANALYZE, CHECK, OPTIMIZE, REPAIR, and TRUNCATE operations are supported with subpartitions. See Section 13.1.9.1, “ALTER TABLE Partition Operations”.

File name delimiters for partitions and subpartitions.  Table partition and subpartition file names include generated delimiters such as #P# and #SP#. The letter case of such delimiters can vary and should not be depended upon.


Zoek in de MySQL-handleiding

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-limitations.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

  1. Bekijk - html-document Taal van het document:en Manuel MySQL : https://dev.mysql.com/

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.

Inhoudsopgave Haut