我有一个 mySQL 查询,它正在工作,但是当涉及到 160 万次执行时,它不能满足我需要的性能,因为不断地重新执行NOT EXIST(new query)
INSERT INTO `votes` (`representatives_rID`, `events_eID`, `voteResult`)
SELECT `representatives`.`rID`,`events`.`eID`,?
FROM `representatives`, `events`
WHERE `events`.`eventDateTime` = ?
AND `representatives`.`rID` = ?
AND NOT EXISTS (SELECT * FROM `votes`
WHERE `votes`.`representatives_rID` = `representatives`.`rID`
AND `votes`.`events_eID` = `events`.`eID`);
在示意图中:
if (input one is in `representatives` AND input two is in `events` AND there is no row in `votes` that contains ( `votes`.`representatives_rID` = `representatives`.`rid` and `votes`.`events_eID` = `events`.`eID)) {
insert a row into votes containing `eid` from `events` and `rid` from `representatives` and input three;
}
有没有办法让这个更快,可能加入?