从InnoDB删除行非常慢

时间:2018-01-09 02:43:30

标签: mysql

因为我不能使用Truncate(只删除一小部分数据),这个表中的数据只需要保留当天的数据,所以每次在早上某个时候其他程序要处理数据,删除上一个表数据,删除使用CREATE TABLE `tbplaylog_copy` ( `Pid` int(11) NOT NULL AUTO_INCREMENT, `Company_id` int(11) NOT NULL DEFAULT '0' COMMENT '??id', `uid` int(11) NOT NULL COMMENT '"??ID"', `Devno` varchar(32) CHARACTER SET utf8 NOT NULL COMMENT '????', `Ad` int(11) NOT NULL COMMENT '????', `MakeTime` int(11) NOT NULL COMMENT '????', `LastTime` int(11) NOT NULL COMMENT '??????', `StartTime` int(11) NOT NULL COMMENT '???????(0,24*60)', `EndPoint` int(11) NOT NULL COMMENT '????????(0,24*60)', `Status` int(11) NOT NULL COMMENT '???1-????0-???', `Note` varchar(128) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT '????', `Valid` int(11) NOT NULL COMMENT '???', `Type` int(11) NOT NULL COMMENT '0,???1????2???', `PlayStartTime` int(11) NOT NULL DEFAULT '0', `PlayEndTime` int(11) NOT NULL DEFAULT '0', `DownloadTime` int(11) NOT NULL DEFAULT '0', `DeleteTime` int(11) NOT NULL DEFAULT '0', `TemplateId` int(11) NOT NULL DEFAULT '0', `ad_adnum` int(11) NOT NULL COMMENT '???ad_id', `length` int(11) NOT NULL, `DownloadPercent` int(11) NOT NULL DEFAULT '0' COMMENT '???????', `DownloadSuccess` int(11) NOT NULL DEFAULT '0' COMMENT '\r\n0-??\r\n1-??”', `Playlist_id` int(11) NOT NULL, `Delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1???', `Reset` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1???', `source` int(2) NOT NULL, `distribute` int(2) NOT NULL DEFAULT '-2' COMMENT '0??-2??', PRIMARY KEY (`Pid`), KEY `starttime` (`StartTime`) USING BTREE, KEY `Devno` (`Devno`), KEY `playstarttime` (`PlayStartTime`), KEY `index_playlist_id` (`Playlist_id`), KEY `ad` (`Ad`), KEY `company_id` (`Company_id`) ) ENGINE=InnoDB AUTO_INCREMENT=8760113 DEFAULT CHARSET=latin1; 删除表中数百万条记录,MySQL删除速度非常慢每10,000条记录大约需要4分钟左右,删除所有无用数据超过八个是不可接受的小时 。

有人告诉我,每次删除记录时,数据库都会相应地更新索引,这是一个非常慢的I / O操作,索引碎片越多,它就越慢。 我把它删除索引,然后删除数据,然后重建索引方法,并没有发现删除速度有所提高,但有时会发生:'锁定等待超时超时;尝试重新启动事务'

表信息:

 DELETE FROM tbplaylog WHERE tbplaylog.StartTime < ? OR tbplaylog.StartTime > ? ORDER BY Pid LIMIT 10000

查询声明:

externals

0 个答案:

没有答案
相关问题