使用调度程序的Mysql动态表分区维护程序

时间:2016-03-23 08:02:21

标签: mysql stored-procedures mysql-workbench partitioning

我创建了一个下表分区维护程序 为unixtime表格column日期partition工作....但它没有创建新的分区 non-partitioned表..

当我调试此程序时,我发现原因PARTITION_DESCRIPTION 对于非分区/新表显示为null。

DELIMITER $$

CREATE DEFINER=`developer`@`%` PROCEDURE `ankit_UpdatePartitions`(dbname varchar(100), 
tblname varchar(100), today_date DATE, add_week INT)
BEGIN

        DECLARE max_date date;
        DECLARE droppart_sql date;
        DECLARE new_date date;

        -- max partititon date
    --  SELECT STR_TO_DATE(MAX(from_unixtime(PARTITION_DESCRIPTION)), '''%Y-%m-%d''') 
        SELECT MAX(date(from_unixtime(PARTITION_DESCRIPTION)))
        INTO max_date
        FROM INFORMATION_SCHEMA.PARTITIONS
        WHERE TABLE_NAME=tblname AND TABLE_SCHEMA=dbname;

        -- create partitions for next future week
        if (max_date < today_date +INTERVAL add_week week)
        Then
            SET new_date := max_date + INTERVAL 1 DAY;
            SET @partition_query := CONCAT('ALTER TABLE ', tblname, ' ADD PARTITION 
                                            (
                                                PARTITION p',CAST(((new_date - INTERVAL 1 DAY)+0) as char(8)),
                                                ' VALUES LESS THAN (', unix_timestamp(new_date) , ')
                                            );'
                                         );
            PREPARE stmt FROM @partition_query;
            EXECUTE stmt;
            DEALLOCATE PREPARE stmt;

    --      SELECT STR_TO_DATE(MAX(PARTITION_DESCRIPTION), '''%Y-%m-%d''')
            SELECT MAX(date(from_unixtime(PARTITION_DESCRIPTION)))
            INTO max_date
            FROM INFORMATION_SCHEMA.PARTITIONS
            WHERE TABLE_NAME=tblname
            AND TABLE_SCHEMA=dbname;

            SET max_date := new_date;
        END if;
END

我应该在代码中更新什么来为non_partitionpartition表创建新的动态分区。

0 个答案:

没有答案