2013-11-28 23 views
4

我有一個表結構喜歡 -收到錯誤1503:主鍵必須包括在表的分區函數的所有列

CREATE TABLE `cdr` (`id` bigint(20) NOT NULL AUTO_INCREMENT, 
        `dataPacketDownLink` bigint(20) DEFAULT NULL, 
        `dataPacketUpLink` bigint(20) DEFAULT NULL, 
        `dataPlanEndTime` datetime DEFAULT NULL, 
        `dataPlanStartTime` datetime DEFAULT NULL, 
        `dataVolumeDownLink` bigint(20) DEFAULT NULL, 
        `dataVolumeUpLink` bigint(20) DEFAULT NULL, 
        `dataplan` varchar(255) DEFAULT NULL, 
        `dataplanType` varchar(255) DEFAULT NULL, 
        `createdOn` datetime DEFAULT NULL, 
        `deviceName` varchar(500) DEFAULT NULL, 
        `duration` int(11) NOT NULL, 
        `effectiveDuration` int(11) NOT NULL, 
        `hour` int(11) DEFAULT NULL, 
        `eventDate` datetime DEFAULT NULL, 
        `msisdn` bigint(20) DEFAULT NULL, 
        `quarter` int(11) DEFAULT NULL, 
        `validDays` int(11) DEFAULT NULL, 
        `dataLeft` bigint(20) DEFAULT NULL, 
        `completedOn` datetime DEFAULT NULL, 
       PRIMARY KEY (`id`), 
       KEY `msisdn_index` (`msisdn`), 
       KEY `eventdate_index` (`eventDate`) 
      ) ENGINE=MyISAM AUTO_INCREMENT=55925171 DEFAULT CHARSET=latin1 

,當我創建的分區 -

ALTER TABLE cdr PARTITION BY RANGE (TO_DAYS(eventdate)) (
    PARTITION p01 VALUES LESS THAN (TO_DAYS('2013-09-01')), 
    PARTITION p02 VALUES LESS THAN (TO_DAYS('2013-09-15')), 
    PARTITION p03 VALUES LESS THAN (TO_DAYS('2013-09-30')), 
    PARTITION p04 VALUES LESS THAN (MAXVALUE)); 

得到

error 1503: A primary key must include all columns in the table's partitioning function 

我已閱讀無處不在關於此,但沒有得到任何東西,所以請讓我知道如何partit離開這張桌子。我有超過2000萬條記錄。

謝謝。

+0

[主要必須包括表的分區位置錯誤中的所有列?](http://stackoverflow.com/questions/11896067/a-primary-must-include-all-columns-in-the- tables-partitioning-location-error) – Barmar

回答

2

我已經通過添加帶主鍵的eventdate解決了這個問題。

0

可能的解決方案:

  1. 變化EVENTDATE到EVENTDATE上 'ALTER TABLE CDR PARTITION BY RANGE(TO_DAYS(EVENTDATE))'
  2. 變化EVENTDATE到時間戳。 (mysql不能在日期時間分區)
+0

呃,從什麼時候起,MySQL還沒有能夠在DATETIME上進行分區?根據他們的文檔:「通過RANGE對錶進行分區,對於分區表達式,使用在DATE,TIME或DATETIME列上運行並返回整數值的函數」 https://dev.mysql.com/doc/ refman/5.5/EN /分區range.html – dave

相關問題