和Oracle不一樣的是:MySQL沒有全局索引,只有分區索引,因此對於MySQL的分區表來說,限制比Oracle要多一些:
1、分區鍵必須是主鍵的一部分
2、分區鍵的數據類型必須是整形(包括時間類型)
3、分區鍵不能為NULL
下面是一個基於時間的表分區定義:
PARTITION BY RANGE (TO_DAYS(START)) ( PARTITION p201401 VALUES LESS THAN (TO_DAYS('20140201')), PARTITION p201402 VALUES LESS THAN (TO_DAYS('20140301')), PARTITION p201403 VALUES LESS THAN (TO_DAYS('20140401')), PARTITION p201404 VALUES LESS THAN (TO_DAYS('20140501')), PARTITION p201405 VALUES LESS THAN (TO_DAYS('20140601')), PARTITION p201406 VALUES LESS THAN (TO_DAYS('20140701')), PARTITION p201407 VALUES LESS THAN (TO_DAYS('20140801')), PARTITION p201408 VALUES LESS THAN (TO_DAYS('20140901')), PARTITION p201409 VALUES LESS THAN (TO_DAYS('20141001')), PARTITION p201410 VALUES LESS THAN (TO_DAYS('20141101')), PARTITION p201411 VALUES LESS THAN (TO_DAYS('20141201')), PARTITION p201412 VALUES LESS THAN (TO_DAYS('20150101')), PARTITION pmax VALUES LESS THAN maxvalue );