这个查询需要近2分钟才能执行(更改了9条记录):
UPDATE table1 t1
SET t1.code_id = null, t1.code_group = null
WHERE t1.another_id IN (SELECT t2.another_id
FROM table2 t2
WHERE ((t2.id_parent = 2658 AND t2.year = 2016)
OR (t2.id = 2658 AND t2.year = 2016)))
仅执行此查询需要0.0030秒:
SELECT t2.another_id
FROM table2 t2
WHERE ((t2.id_parent = 2658 AND t2.year = 2016)
OR (t2.id = 2658 AND t2.year = 2016))
并返回一个由整数形式组成的三行数据表。以下是这两个表的信息:
CREATE TABLE IF NOT EXISTS `table1`
(
`another_id` int(11) NOT NULL,
`table1_id` int(11) NOT NULL,
`code_group` varchar(1) DEFAULT NULL,
`code_id` int(10) DEFAULT NULL,
PRIMARY KEY (`another_id`,`table1_id`),
KEY `another_id` (`another_id`),
KEY `code_group` (`code_group`,`code_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `table2`
(
`id_year` int(11) NOT NULL,
`id` int(11) NOT NULL,
`id_parent` int(11) DEFAULT NULL,
`another_id` int(11) NOT NULL,
`code_group` varchar(1) DEFAULT NULL,
`code_id` int(10) DEFAULT NULL,
PRIMARY KEY (`id_year`,`id`),
KEY `id_parent` (`id_year`,`id_parent`)
KEY `another_id` (`another_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_polish_ci;
有没有人能告诉我为什么执行这个查询需要2分钟?