Link to home
Start Free TrialLog in
Avatar of MFredin
MFredinFlag for United States of America

asked on

MySQL partitioning trouble

I'm trying to partition a MySQL 5.5 MyISAM table but getting an error.  Partitioning by state.  phy_st (varchar) is a column mytable and the values are the state abbreviations.  From what I've read, this should work.  What am I missing here?

ALTER TABLE mytable
PARTITION BY LIST COLUMN(phy_st)
    PARTITION p1 VALUES IN('NY','FL','GA'),
    PARTITION p2 VALUES IN('TX','MI','CA'),
    PARTITION p3 VALUES IN('MN','IN','IL'),    
    PARTITION p4 VALUES IN('WI','NJ','AL'),
    PARTITION p5 VALUES IN('OH','KY','NC'),
    PARTITION p6 VALUES IN('MD','TN','CO'),    
    PARTITION p7 VALUES IN('MO','IA','NE'),
    PARTITION p8 VALUES IN('MA','OK','OR'),
    PARTITION p9 VALUES IN('VA','SC','AZ'),    
    PARTITION p10 VALUES IN('PA','WA','UT'),    
    PARTITION p11 VALUES IN('LA','KS','MS'),
    PARTITION p12 VALUES IN('WV','AR','CT'),
    PARTITION p13 VALUES IN('ME','ID','NM'),    
    PARTITION p14 VALUES IN('ON','NH','MT'),
    PARTITION p15 VALUES IN('SD','RI','WY'),
    PARTITION p16 VALUES IN('QC','NV','ND'),
    PARTITION p17 VALUES IN('DE','BN','VT'),  
    PARTITION p18 VALUES IN('TA','BC','AB'),
    PARTITION p19 VALUES IN('CI','MB','NB'),
    PARTITION p20 VALUES IN('NL','SK','SO'),    
    PARTITION p21 VALUES IN('DC','SI','CH'),
    PARTITION p22 VALUES IN('MX','NS','JA'),
    PARTITION p23 VALUES IN('GJ','BS','DF'),    
    PARTITION p24 VALUES IN('MC','VC','DG'),
    PARTITION p25 VALUES IN('PE','SL','AG'),
    PARTITION p26 VALUES IN('YT','QE','HD','PU','TL'),    
    PARTITION p27 VALUES IN('ZA','CL','GU','CP','MR','NA'),
    PARTITION p28 VALUES IN('MP','TB','AS','OA','GE','CS','YU','NT','QI')
);


Error:

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COLUMN(phy_st)

    PARTITION p1 VALUES IN('NY','FL','GA'),
    PARTITION p2 ' at line 2
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MFredin

ASKER

Hi angelIII,

I tried:
ALTER TABLE fmcsa
PARTITION BY LIST(phy_st)
    PARTITION p1 VALUES IN('NY','FL','GA'),
    PARTITION p2 VALUES IN('TX','MI','CA'),
    PARTITION p3 VALUES IN('MN','IN','IL'),  
    PARTITION p28 VALUES IN('MP','TB','AS','OA','GE','CS','YU','NT','QI')
);

and got the same error
Avatar of MFredin

ASKER

sorry... missed a "(" in there.  Fixed that and here's the new error:

[Err] 1064 - VALUES value must be of same type as partition function near ''FL','GA'),
    PARTITION p2 VALUES IN('TX','MI','CA'),
    PARTITION p3 VALUE' at line 4
Avatar of MFredin

ASKER

another important update... I double checked my version and I was actually on 5.1.  I upgraded to 5.5 and getting this error:


VALUES value for partition 'p1' must have type INT

I was pretty sure with 5.5 you could partition on varchar
Hi,

I think instead of using LIST partitioning you should use COLUMN partitioning, see: http://dev.mysql.com/doc/refman/5.5/en/partitioning-columns.html
Because with LIST partitioning only numeric values are allowed.
Avatar of MFredin

ASKER

I tried:

ALTER TABLE fmcsa
PARTITION BY LIST COLUMNS(phy_st) (
    PARTITION p1 VALUES IN( 'NY','FL','GA'),
    PARTITION p2 VALUES IN( 'TX','MI','CA'),....

but got

[Err] 1503 - A PRIMARY KEY must include all columns in the table's partitioning function
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
http://dev.mysql.com/doc/refman/5.1/en/partitioning-list.html
This is done by using PARTITION BY LIST(expr) where expr is a column value or an expression based on a column value and returning an integer value