Enhanced MySQL 5.5 partition functions

Source: Internet
Author: User

Figure 1 you have not noticed that MySQL has a strong partition function.

  Non-integer column Partition

Anyone who uses too many partitions should have encountered many problems. Especially for non-integer column partitions, MySQL 5.1 can only process integer column partitions. If you want to partition on a date or string column, you have to use the function to convert it.

MySQL 5.5 adds two types of partitioning methods, RANG and LIST partitioning, and adds a COLUMNS keyword to the new function. Suppose we have a table like this:

Create table expenses (
Expense_date date not null,
Category VARCHAR (30 ),
Amount DECIMAL (10, 3 ));

If you want to use the partition type in MySQL 5.1, you must convert the type to an integer and use an additional table to search for it in MySQL 5.5, you do not need to convert the type, for example:

Alter table expenses partition by list columns (category )(
PARTITION p01 values in (lodging, food ),
PARTITION p02 values in (flights, ground transportation), PARTITION p03 values in (leisure, customer entertainment ),
PARTITION p04 values in (communications ),
PARTITION p05 values in (fees ));

In addition to easier reading, such partition statements clearly organize and manage data. The preceding example only partitions the category column.

Another headache for using partitions in MySQL 5.1 is the date type (that is, the date columns). You cannot use them directly. You must use YEAR or TO_DAYS to convert these columns, for example:

/* In MySQL 5.1 */
Create table t2
(
Dt DATE
)
Partition by range (TO_DAYS (dt ))
(
PARTITION p01 values less than (TO_DAYS (2007-01-01 )),
PARTITION p02 values less than (TO_DAYS (2008-01-01 )),
PARTITION p03 values less than (TO_DAYS (2009-01-01 )),
PARTITION p04 values less than (MAXVALUE ));
Show create table t2G ***************************** 1
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.