温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mysql partition table use to_days bug

发布时间:2020-08-10 22:57:05 来源:ITPUB博客 阅读:163 作者:psufnxk2000 栏目:MySQL数据库
to_days分区表 bug

CREATE TABLE `aaaaaaaaaa` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `year` int(4) NOT NULL,
  `month` int(2) NOT NULL,
  `day` int(2) NOT NULL,
  `startTime` datetime NOT NULL,
  `endTime` datetime NOT NULL,
  `version` varchar(12) NOT NULL DEFAULT '',
  `source` varchar(12) NOT NULL DEFAULT '',
  `sid` varchar(12) NOT NULL,
  `valid` int(8) NOT NULL,
  `error` int(8) NOT NULL,
  `total` int(8) NOT NULL,
  PRIMARY KEY (`id`,`startTime`,`version`,`source`,`sid`),
  KEY `aaaaaaaaaa_index_startTime` (`startTime`),
  KEY `aaaaaaaaaa_index_endTime` (`endTime`),
  KEY `aaaaaaaaaa_muti_index` (`year`,`month`,`source`),
  KEY `aaaaaaaaaa_index_source` (`source`),
  KEY `month_index` (`month`),
  KEY `year_index` (`year`)
) ENGINE=InnoDB AUTO_INCREMENT=1267666446 DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (to_days(startTime))
(PARTITION p20160405 VALUES LESS THAN (736425) ENGINE = InnoDB,
 PARTITION p20160620 VALUES LESS THAN (736501) ENGINE = InnoDB,
 PARTITION p20160706 VALUES LESS THAN (736517) ENGINE = InnoDB) */
 
 
  执行下面的sql,mysql 会crash
 select sid as sid,source as source,sum(valid) as valid,sum(error) as error from aaaaaaaaaa where startTime>="2016-07-08 10:00:00" 
 
  通过下面的方法可以fix
 alter table aaaaaaaaaa add PARTITION  (partition p_max values less than(maxvalue));
 


另:

CREATE TABLE `aaaaaaaaaa` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `year` int(4) NOT NULL,
  `month` int(2) NOT NULL,
  `day` int(2) NOT NULL,
  `startTime` datetime NOT NULL,
  `endTime` datetime NOT NULL,
  `version` varchar(12) NOT NULL DEFAULT '',
  `source` varchar(12) NOT NULL DEFAULT '',
  `sid` varchar(12) NOT NULL,
  `valid` int(8) NOT NULL,
  `error` int(8) NOT NULL,
  `total` int(8) NOT NULL,
  PRIMARY KEY (`id`,`startTime`,`version`,`source`,`sid`)
  ) ENGINE=InnoDB AUTO_INCREMENT=1267666446 DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (to_days(startTime))
(PARTITION p20160405 VALUES LESS THAN (736425) ENGINE = InnoDB,
 PARTITION p20160620 VALUES LESS THAN (736501) ENGINE = InnoDB,
 PARTITION p20160706 VALUES LESS THAN (736517) ENGINE = InnoDB) */
 
 这样不会出现上面的问题
 
 
 
 但如果把starttime列加上索引 ,就会有这个问题
 CREATE TABLE `aaaaaaaaaa` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `year` int(4) NOT NULL,
  `month` int(2) NOT NULL,
  `day` int(2) NOT NULL,
  `startTime` datetime NOT NULL,
  `endTime` datetime NOT NULL,
  `version` varchar(12) NOT NULL DEFAULT '',
  `source` varchar(12) NOT NULL DEFAULT '',
  `sid` varchar(12) NOT NULL,
  `valid` int(8) NOT NULL,
  `error` int(8) NOT NULL,
  `total` int(8) NOT NULL,
  PRIMARY KEY (`id`,`startTime`,`version`,`source`,`sid`),
  KEY `aaaaaaaaaa_index_startTime` (`startTime`)
) ENGINE=InnoDB AUTO_INCREMENT=1267666446 DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (to_days(startTime))
(PARTITION p20160405 VALUES LESS THAN (736425) ENGINE = InnoDB,
 PARTITION p20160620 VALUES LESS THAN (736501) ENGINE = InnoDB,
 PARTITION p20160706 VALUES LESS THAN (736517) ENGINE = InnoDB) */
 
 MOS没有找到相关的bug
 5.1 5.6 中都没有这个问题,5.5.24中有这个问题
 
转载请注明源出处
QQ 273002188 欢迎一起学习
QQ 群 236941212
oracle,mysql,PG 相互交流
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI