当我尝试使用以下查询更新我的种子文件表(我的种子文件站点只允许共享开源内容)时
UPDATE `torrents` SET `leech` = '0', `seed` = '1' WHERE `id` = '26784'
更新仅包含 20,000 条记录的表大约需要 0.5 秒。我的其他查询执行时间不到 0.0478 秒(SELECT 查询)
CREATE TABLE IF NOT EXISTS `torrents` (
`id` int(11) NOT NULL,
`hash_info` varchar(255) NOT NULL,
`category_slug` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
`size` bigint(20) NOT NULL,
`age` int(11) NOT NULL,
`description` text NOT NULL,
`trackers` longtext NOT NULL,
`magnet` longtext,
`files` longtext,
`parent_category` int(11) NOT NULL,
`category` int(11) NOT NULL,
`publish_date` int(11) DEFAULT NULL,
`uploader` int(11) NOT NULL,
`seed` int(11) DEFAULT '0',
`leech` int(11) DEFAULT '0',
`file_key` varchar(255) DEFAULT NULL,
`comments_count` int(11) DEFAULT '0'
) ENGINE=InnoDB AUTO_INCREMENT=26816 DEFAULT CHARSET=latin1;
有什么解决办法吗?
最佳答案
基于索引列的查找比非索引列的查找快得多。随着数据量的增加,这种行为会更加明显。
在 Id 列上创建索引并检查它是否有助于提高查询性能。
关于mysql - 慢更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45170426/