MySQL partitioning trouble

MFredin
MFredin used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
please remove COLUMN from the syntax

Author

Commented:
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

Author

Commented:
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
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Author

Commented:
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

Commented:
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.

Author

Commented:
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
Commented:
Ah, so you should create a unique key that includes the phy_st column. You could create a unique index that's a combination of the actual primary key and the phy_st column.
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial