Experience with MySQL (11) Table partitioning by date

Source: Internet
Author: User

Create

CREATE table user (id int (one) not NULL auto_increment,

Name varchar (255),

Birthday Date Default NULL,

PRIMARY KEY (Id,birthday))

Partition by range (birthday)

(partition P0 values less than (' 1985-12-26 '),

Partition P1 VALUES less THAN (' 2013-12-01 '));

Error

ERROR 1697 (HY000): VALUES value for partition ' P0 ' must type INT

Normal creation

CREATE table user (id int (one) not NULL auto_increment,

Name varchar (255),

Birthday Date Default NULL,

PRIMARY KEY (id,birthday)) Engine=innodb

Partition by Range (To_days (birthday))

(PARTITION p0 VALUES less THAN (to_days (' 1985-01-01 ')),

PARTITION p1 VALUES Less THAN (to_days (' 2004-01-01 ')),

PARTITION P2 VALUES Less THAN (to_days (' 2005-01-01 ')),

PARTITION P3 VALUES Less THAN (to_days (' 2006-01-01 ')),

PARTITION P4 VALUES Less THAN (to_days (' 2007-01-01 ')),

PARTITION P5 VALUES Less THAN (to_days (' 2010-01-01 ')),

PARTITION P6 VALUES less THAN MAXVALUE);

Perform an interpretation scan

Explain partitions select birthday from user where birthday> ' 2006-06-01 ' and birthday< ' 2006-12-12 '

Output

1. Row ***************************

Id:1

Select_type:simple

Table:user

Partitions:p0,p4

Type:index

Possible_keys:null

Key:primary

Key_len:7

Ref:null

Rows:2

Extra:using where; Using Index

1 row in Set (0.00 sec)

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/MySQL/

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.