MySQL partition table (RPM)

Source: Internet
Author: User

View partition status

    1. SELECT * from information_schema. Partitions WHERE table_name=' table_name ';

Partition_name: Name of the partition

Partition_method: Type of partition

Table_rows: Number of partitioned data bars

Range Partition:

  1. Create table T (
  2. ID int) engine=innodb
  3. Partition by range (ID) (
  4. Partition P0 values less than ,--id p0 partition
  5. Partition P1 values less than ()); --id greater than or equal to 10 less than 20 join P1 partition

Add partition

    1. Alter table R add partition (partition P2 values less than MaxValue); -- all add P2 partitions greater than or equal to 20

  1. CREATE TABLE ' W ' (
  2. ' money ' INT(Ten) UNSIGNED not NULL,
  3. ' Date ' DATETIME DEFAULT NULL
  4. ) ENGINE=innodb DEFAULT CHARSET=utf8
  5. PARTITION by RANGE (DATE)--The defined rule can also be a function
  6. (PARTITION p2010 VALUES less THAN ),
  7. PARTITION p2001 VALUES less THAN (+),
  8. PARTITION p2012 VALUES less THAN (+));

Delete Partition

    1. Alter table w drop partition p2010;

--Deleting a partition, the partition's data is also deleted

----------------------------------------------------------------------

List partition

  1. CREATE TABLE M (
  2. A INT,
  3. b INT) ENGINE=innnodb
  4. PARTITION by LIST (b)(
  5. PARTITION p0 VALUES in (1, 2, 3, 4, 5),
  6. PARTITION p1 VALUES in (6, 7, 8, 9, ten));
  7. Insert INTO m values (1, 6), (2, 7), (3, one),(4, 9)

--The inserted value (3,11) does not match, and if it is the InnoDB engine, subsequent (4,9) qualifying conditions are not inserted into the table,

If the MyISAM engine is in the back (4,9), it will be inserted into the table

----------------------------------------------------------------------

< Strong style= "font-family: Song body; font-size:10.5pt; line-height:13.5pt; " >hash Partition

    1. create table m_hash (
    2. a int
    3. b datetime) Engine=innnodb
    4. PARTITION by HASH (year) )-- "Partition by hash (expr )
    5. partitions 4

For example: Add partition algorithm mod (expr, number of partitions 4) =0 join P0

    1. PARTITION by LINEAR HASH (year(b))

--unlike hash only algorithm, return is the same value

----------------------------------------------------------------------

Columns Partition

mysql5.5 started support as an evolution of the range partition and list partition, supporting int,smallint,tinyint,bigint. date,datetime. char,varchar,binary,varbinary Type

  1. CREATE TABLE T_columns_range(
  2. A INT,
  3. b DATETIME) ENGINE=innodb
  4. PARTITION by RANGE COLUMNS (b)-can also PARTITION by less COLUMNS (b)
  5. (PARTITION p0 VALUES less THAN(' 2009-01-01 '),
  6. PARTITION p1 VALUES less THAN(' 2010-01-01 '));

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.