Which method should used to add a new g201305 partition to the table?

Consider the following table:
CREATE TABLE ‘game’ (
‘id’ int (10) unsigned NOT NULL AUTO_INCREMENT,
‘keyword’ varchar (45) DEFAULT NULL,
‘date’ datetime NOT NULL,
PRIMARY KEY (‘id’ , ‘date’),
UNIQUE KEY ‘keyword_idx’ (‘keyword’ , ‘date’)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
PARTITION BY RANGE (TO_DAYS (date) ) (
PARTITION g201301 VALUES LESS THAN (TO_DAYS (‘2013-01-01 00:00:00’) ),
PARTITION g201302 VALUES LESS THAN (TO_DAYS (‘2013-02-01 00:00:00’) ),
PARTITION g201303 VALUES LESS THAN (TO_DAYS (‘2013-03-01 00:00:00’) ),
PARTITION g201304 VALUES LESS THAN (TO_DAYS (‘2013-04-01 00:00:00’) ),
PARTITION gMORES VALUES LESS THAN (MAXVALUE) );
Which method should used to add a new g201305 partition to the table?

Consider the following table:
CREATE TABLE ‘game’ (
‘id’ int (10) unsigned NOT NULL AUTO_INCREMENT,
‘keyword’ varchar (45) DEFAULT NULL,
‘date’ datetime NOT NULL,
PRIMARY KEY (‘id’ , ‘date’),
UNIQUE KEY ‘keyword_idx’ (‘keyword’ , ‘date’)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
PARTITION BY RANGE (TO_DAYS (date) ) (
PARTITION g201301 VALUES LESS THAN (TO_DAYS (‘2013-01-01 00:00:00’) ),
PARTITION g201302 VALUES LESS THAN (TO_DAYS (‘2013-02-01 00:00:00’) ),
PARTITION g201303 VALUES LESS THAN (TO_DAYS (‘2013-03-01 00:00:00’) ),
PARTITION g201304 VALUES LESS THAN (TO_DAYS (‘2013-04-01 00:00:00’) ),
PARTITION gMORES VALUES LESS THAN (MAXVALUE) );
Which method should used to add a new g201305 partition to the table?

A.
ALTER TABLE games
REORGANIZE PARTITION (gMORES)
INTO
g01305 VALUES LESS THAN (TO_DAYS (‘2013-05-01 00:00:00’) ),
gMORES VALUES LESS THAN (MAXVALUE) );

B.
ALTER TABLE games
ADD PARTITION g201350 VALUES LESS THAN (TO_DAYS (‘2013-05-01 00:00:00’) );

C.
ALTER TABLE games
COALESCE PARTITION (gMORES)
INTO
g01305 VALUES LESS THAN (TO_DAYS (‘2013-05-01 00:00:00’) ),
gMORES VALUES LESS THAN (MAXVALUE) );

D.
ALTER TABLE games
SPLIT PARTITION (gMORES)
INTO
g201305 VALUES LESS THAN (TO_DAYS (‘2013-05-01 00:00:00’) ),
gMORES VALUES LESS THAN (MAXVALUE) );

E.
ALTHER TABLE games
DROP PATITION gMORES,
ADD PARTITION
g201305 VALUES LESS THAN (TO_DAYS (‘2013-05-01 00:00:00’) ),
gMORES VALUES LESS THAN (MAXVALUE) );

Explanation:



Leave a Reply 10

Your email address will not be published. Required fields are marked *


Steve

Steve

I would think B.
The last partition is already allocated to anything more than the g201304 partition.
Reorganizing the last partition like B does seems logical.

E

E

Wrong. You cannot add partition in the middle of range partitions even if the last partition is MAXVALUE.
You must REORGANIZE.
Correct is A.

kyo

kyo

A
correct statement is:
alter table game reorganize partition gMORES into (partition g201305 values less than(to_days(‘2013-05-01 00:00:00’)),partition gMORES values less than (maxvalue));

jeanrock

jeanrock

correct answer is A, similar testing from my side.
CREATE TABLE tr (id INT, name VARCHAR(50), purchased DATE)
PARTITION BY RANGE( YEAR(purchased) ) (
PARTITION p0 VALUES LESS THAN (1990),
PARTITION p1 VALUES LESS THAN (1995),
PARTITION p2 VALUES LESS THAN (2000),
PARTITION p3 VALUES LESS THAN (2005),
PARTITION p4 VALUES LESS THAN(MAXVALUE)
);

ALTER TABLE tr
REORGANIZE PARTITION p4 INTO (
PARTITION p4 VALUES LESS THAN (2008),
PARTITION pmax VALUES LESS THAN (maxvalue)
);
mysql> show create table tr \G
*************************** 1. row ***************************
Table: tr
Create Table: CREATE TABLE `tr` (
`id` int(11) DEFAULT NULL,
`name` varchar(50) DEFAULT NULL,
`purchased` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE ( YEAR(purchased))
(PARTITION p0 VALUES LESS THAN (1990) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (1995) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p3 VALUES LESS THAN (2005) ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN (2008) ENGINE = InnoDB,
PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
1 row in set (0.00 sec)

sky

sky

Suppose further that the minimum age for members is 16. As the calendar approaches the end of 2005, you realize that you will soon be admitting members who were born in 1990 (and later in years to come). You can modify the members table to accommodate new members born in the years 1990 to 1999 as shown here:

ALTER TABLE members ADD PARTITION (PARTITION p3 VALUES LESS THAN (2000));
With tables that are partitioned by range, you can use ADD PARTITION to add new partitions to the high end of the partitions list only. Trying to add a new partition in this manner between or before existing partitions results in an error as shown here:

mysql> ALTER TABLE members
> ADD PARTITION (
> PARTITION n VALUES LESS THAN (1960));
ERROR 1463 (HY000): VALUES LESS THAN value must be strictly »
increasing for each partition
You can work around this problem by reorganizing the first partition into two new ones that split the range between them, like this:

ALTER TABLE members
REORGANIZE PARTITION p0 INTO (
PARTITION n0 VALUES LESS THAN (1960),
PARTITION n1 VALUES LESS THAN (1970)
);

sakthi sri

sakthi sri

A is perfect one…*