Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make partitioning in existing mysql table?

Tags:

database

mysql

I have a table called tbl_rtdata. I was dropped the all partitions in that table and create the new partition in the below manner.

ALTER TABLE tbl_rtdata  PARTITION BY RANGE (Month(fld_date))

SUBPARTITION BY HASH (Day(fld_date)) SUBPARTITIONS 12(   
PARTITION Apr_0 VALUES LESS THAN (2012-05-01),
PARTITION May_1 VALUES LESS THAN (2012-06-01),    
PARTITION Jun_2 VALUES LESS THAN (2012-07-01),  
PARTITION Jul_3 VALUES LESS THAN (2012-08-01),
PARTITION Aug_4 VALUES LESS THAN (2012-09-01),
PARTITION Sep_5 VALUES LESS THAN (2012-10-01),
PARTITION Oct_6 VALUES LESS THAN (2012-11-01),  
PARTITION Nov_7 VALUES LESS THAN (2012-12-01),
PARTITION Dec_8 VALUES LESS THAN MAXVALUE );

But I got an Error : VALUES LESS THAN value must be strictly increasing for each partition.

If I remove the subpartition in query it shows the error VALUES value for partition 'Apr_0' must have type INT

What I should do to recover from this ?

like image 746
Dhileepan Avatar asked Nov 18 '25 20:11

Dhileepan


2 Answers

I found the answer which is very simple, use to_days function

ALTER TABLE tbl_rtdata  PARTITION BY RANGE (Month(fld_date))
(   
PARTITION p_Apr VALUES LESS THAN (TO_DAYS('2012-05-01')),
PARTITION p_May VALUES LESS THAN (TO_DAYS('2012-06-01')), 
PARTITION p_Jun VALUES LESS THAN (TO_DAYS('2012-07-01')),  
PARTITION p_Jul VALUES LESS THAN (TO_DAYS('2012-08-01')),
PARTITION p_Aug VALUES LESS THAN (TO_DAYS('2012-09-01')),
PARTITION p_Sep VALUES LESS THAN (TO_DAYS('2012-10-01')),
PARTITION p_Oct VALUES LESS THAN (TO_DAYS('2012-11-01')),  
PARTITION p_Nov VALUES LESS THAN (TO_DAYS('2012-12-01')),
PARTITION p_Dec VALUES LESS THAN MAXVALUE );
like image 94
Dhileepan Avatar answered Nov 20 '25 12:11

Dhileepan


I think it's not supported in MySQL < 5.5 try this: Manual here

ALTER TABLE tbl_rtdata PARTITION BY RANGE COLUMNS (fld_date) (
  PARTITION Apr_0 VALUES LESS THAN ('2012-05-01'),
  PARTITION May_1 VALUES LESS THAN ('2012-06-01'),
  PARTITION Dec_8 VALUES LESS THAN (MAXVALUE)
  );
like image 24
Omesh Avatar answered Nov 20 '25 13:11

Omesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!