mysql multi-field partitioning
Partitioning is based on certain rules. The database decomposes a table into multiple smaller, more manageable parts. As far as accessing database applications is concerned, logically there is only one table or one index, but in fact this table may be composed of N physical partition objects. Each partition is an independent object and can be processed independently and can be used as part of the table. for processing. Partitioning is completely transparent to the application and does not affect the application's business logic.
Recommended courses: MySQL Tutorial.
Partitioning is conducive to managing very large tables. It adopts the logic of divide and conquer. Partitioning introduces the concept of partition key. The partition key is used to calculate the partition value according to a certain interval value (or range). value), a specific value list or a hash function value to perform data aggregation, allowing the data to be distributed in different partitions according to rules, making one large object some small objects.
MySQL partitioning can partition data or indexes.
Note: No matter what kind of partitioning, either there is no primary key/unique key on your partitioned table, or the primary key/unique key of the partitioned table must contain the partition key, which means that you cannot use fields other than the primary key/unique key. other field partitions.
The limitations of MySQL partitions mainly include the following four aspects:
Compared with a single disk or file system partition, more data can be stored
Optimize queries. When the partition condition is included in the where clause, you can only scan the necessary one or more partitions to improve query efficiency; at the same time, when queries involving aggregate functions such as sum() and count(), you can easily scan each partition Parallel processing, and finally only need to summarize the results obtained from all partitions
For data that has expired or does not need to be saved, the data can be quickly deleted by deleting the partitions related to these data
Across multiple Disks are used to disperse data queries to obtain greater query throughput
Partitioning is similar to horizontal table partitioning. It divides the data of a large table into multiple small tables, because the query does not require a full table scan. , only certain partitions need to be scanned, so partitioning can improve query speed.
Horizontal sharding requires users to manually and explicitly create multiple sharding tables (such as tbl_user0, tbl_user1, tbl_user2) in advance, and physically create multiple tables through the client agent (Sharding-JDBC etc.) or middleware agent (Mycat, etc.) to implement table splitting logic.
Partition is a plug-in function of MySQL, which divides the data of a large table into multiple partition files at the bottom of the database (such as tbl_user#P#p0.ibd, tbl_user#P#p1.ibd, tbl_user#P #p2.ibd), unlike horizontal partitioning, partitioning does not require explicit creation of "partitioning tables". The database will automatically create partition files. What the user sees is just an ordinary table, which actually corresponds to multiple A partition is shielded and transparent to users. Its use is exactly the same as using a table. It does not require any functions to implement it. Partition is a logical horizontal table, but it is still a table at the physical level.
Before mysql5.5, range partitioning and list partitioning only supported integer partitioning, and an integer could be obtained through additional function operations or additional conversions. The columns partition is divided into range columns and list columns, and supports three major data types: integer (tinyint to bigint, decimal and float are not supported), date (date, datetime), and string (char, varchar, binary, varbinary).
Columns partitioning supports one or more fields as partitioning keys, but does not support expressions as partitioning keys. This is different from range and list partitioning. It should be noted that the comparison of range columns partition keys is based on tuple comparison, that is, based on field group comparison, which is different from range partitioning.
create talbe rc3 ( a int, b int ) partition by range columns(a, b) ( partition p01 values less than (0, 10), partition p02 values less than (10, 10), partition p03 values less than (10, 20), partition p04 values less than (10, 35), partition p05 values less than (10, maxvalue), partition p06 values less than (maxvalue, maxvalue), ); insert into rc3(a, b) values(1, 10); select (1, 10) < (10, 10) from dual; -- 根据结果存放到p02分区上了 select partition_name, partition_expression, partition_description, table_rows from information_schema.partitions where table_schema = schema() and table_name = 'rc3';
The comparison of range columns partition keys (comparison of tuples) is actually multi-column sorting, first sorting according to the a field and then sorting according to the b field, partitioning the data according to the sorting result, and range single field partitioning The rules for sorting are actually the same.
The above is the detailed content of mysql multi-field partitioning. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.
