MySQL partitioning is implemented by wrapping the data table, which means that the index is actually defined based on each partition rather than the entire table. This feature is different from Oracle, where indexes and tables can be partitioned in a more flexible and complex way. MySQL partitioning determines the partition to which a data row belongs by defining the conditions of the PATITION BY clause. When executing a query, the query optimizer distinguishes between partitions, which means that the query will not check all partitions, but only those partitions that contain the requested data. The main purpose of partitioning is to roughly index and cluster the data table. This can reduce the need to access a large range of data tables and store related data rows close together. The benefits of partitioning are significant, especially for the following scenarios:
The implementation details of MySQL partitioning are very complex and difficult to understand. We only need to focus on its performance. If you want to learn more, you can read the section about partitioning in the MySQL manual. Partitioning also brings other problems and limitations:
Partitioning mechanismAs mentioned earlier, the partition table actually has multiple hidden physical storage tables, which are presented through handle objects. We cannot access the partitions directly. Typically, each partition is managed by a storage engine (therefore requiring the same storage engine for all partitions), and the index in the data table is actually an index of the hidden physical storage table. From the storage engine's perspective, partitions are also data tables. The storage engine does not actually know whether the data table is independent or a partition of a larger data table. The operations on the partition table are implemented through the following logical operations: SELECT queryWhen querying a partitioned table, the partitioning layer opens and locks all hidden partitions, the query optimizer determines which hidden partitions can be ignored, and then the partitioning layer calls the storage engine that manages the partitions through the handle API to obtain the query results. INSERT OperationWhen a row of data is inserted, the partition layer opens and locks all partitions, then determines which partition stores the current data row, and stores the data row in the corresponding partition. DELETE OperationWhen deleting a row of data, the partitioning layer opens and locks all partitions, checks which partition contains the row of data, and then sends the delete request to that partition. UPDATE Operation When modifying a row of data, the partitioning layer opens and locks all partitions, checks which partition contains the row of data, obtains the row of data for modification, and then determines which partition should contain the new data row, sends the insert request to the partition, and sends the delete request to the old partition. Although the partition layer opens and locks all partitions, it does not mean that the partitions will remain locked. Storage engines like InnoDB support row-level locking and will only unlock partitions at the partition level. The locking and unlocking process is similar to the locking process of ordinary InnoDB data tables. Types of PartitionsMySQL supports several types of partitioning. The most commonly used type is range partitioning, which is partitioning by different ranges of values or expressions of certain columns. For example, the following statement divides sales data into different partitions based on year: CREATE TABLE sales ( order_date DATETIME NOT NULL --Other column definitions) ENGINE=InnoDB PARTITION BY RANGE(YEAR(order_date)) ( PARTITION p_2018 VALUES LESS THAN (2018), PARTITION p_2019 VALUES LESS THAN (2019), PARTITION p_2020 VALUES LESS THAN (2020), PARTITION p_other VALUES LESS THAN MAXVALUE); A variety of functions can be used in the partition clause. The main requirement is that it must return a non-constant, deterministic integer. In the above example the YEAR function is used, but other functions can also be used, such as TO_DAYS(). Using time intervals for partitioning is a common approach for date-based data. MySQL also supports key, hash, and list partitioning methods, and some also support subpartitioning (which is rarely used in practice). In MySQL 5.5 and later, you can use the RANGE COLUMNS partition type to partition directly by date-based columns without using functions to convert dates to integers. Other common partitioning techniques include:
The above is the detailed content of the concept and mechanism of MySQL advanced feature - data table partition. For more information about MySQL advanced feature data table partition, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Summary of flex layout compatibility issues
>>: Implementation of Nginx configuration Https security authentication
See: https://www.jb51.net/article/112612.htm Chec...
Table of contents 1.1. Network access between con...
Preface When we were writing the web page style a...
Docker basic instructions: Update Packages yum -y...
** Detailed graphic instructions for installing y...
This article mainly records a tomcat process, and...
filter is generally used to filter certain values...
Table of contents 1. Preparation Pull the redis i...
When inserting data, I found that I had never con...
You know that without it, the browser will use qui...
1 Introduction Thread technology was proposed as ...
Setting the font for the entire site has always b...
Table of contents Preface Can typeof correctly de...
This article shares the MySQL Workbench installat...
Table of contents Introduction Example: Event del...