所以我想在MySQL中第一次嘗試分區任何幫助將不勝感激。我想什麼分區做之前不到CUR日期分區1,下週在分區2和最大值爲獲得分區3.MySQL中的第一次嘗試範圍分區
create TABLE diagnostics_daily_device_summary (
ID bigint(20) NOT NULL AUTO_INCREMENT,
timestamp datetime,
- 還有其他領域包括在內,但爲求例子我就不打擾 在
PRIMARY KEY (ID, timestamp)
)
PARTITION BY RANGE (yearweek(timestamp))(
PARTITION p1 VALUES LESS THAN (yearweek(curdate())),
PARTITION p2 VALUES LESS THAN (yearweek(date_add(curdate(), interval 7 day))),
PARTITION p3 VALUES LESS THAN maxvalue
);
扔我需要保持過去的3週數據,這就是爲什麼我將它分解爲年周格式。
當我運行查詢,我發現了錯誤信息是這樣的
錯誤代碼:在(子)分區函數1064常數,隨機或時區相關的表述不準靠近「),PARTITION p201547值小於(年周(DATE_ADD(CURDATE(),間隔7 d」列70
我不太知道如何解決它。
此外,我想每星期和滴添加一個新的一週上週,我從一個在線來源獲得了這一行代碼
USE demotimeparts;
DROP PROCEDURE IF EXISTS rotateTimePartition;
DELIMITER //
CREATE PROCEDURE rotateTimePartition (newPartValue DATETIME)
BEGIN
DECLARE keepStmt VARCHAR(2000) default @stms;
DECLARE partitionToDrop VARCHAR(64);
SELECT 201501
INTO partitionToDrop
-- FROM SCHEMA_NAME.partitions
WHERE table_schema='SCHEMA_NAME'
AND tabe_name='diagnostics_daily_device_summary'
AND partition_ordinary_position=1;
SET @stmt = CONCAT ('ALTER TABLE diagnostics_daily_device_summary DROP PARTITION' , partitionToDrop);
PREPARE pStmt FROM @stmt;
EXECUTE pStmt;
DEALLOCATE PREPARE pStmt;
SET @stmt = CONCAT ('ALTER TABLE diagnostics_daily_device_summary ADD PARTITION (PARTITION Y',
DATE_FORMAT(newPartValue, '%Y%m%d'),
' VALUES LESS THAN (TO_DAYS(\'',
DATE_FORMAT(newPartValue, '%Y-%m-%d'),
'\')))');
PREPARE pStmt FROM @stmt;
EXECUTE pStmt;
DEALLOCATE PREPARE pStmt;
SET @stmt = keepStmt;
END //
DELIMITER;
就像我說的任何幫助將不勝感激!再次感謝你。