Home Database Mysql Tutorial mysql multi-field partitioning

mysql multi-field partitioning

May 10, 2019 pm 01:32 PM
mysql

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.

mysql multi-field partitioning

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';
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

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.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

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 Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

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.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

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.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

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.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

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: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

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.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

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.

See all articles