我有以下存储过程:
CREATE PROCEDURE testProc(IN p_idProject INTEGER)
BEGIN
DECLARE nowTime DATETIME;
SET @nowTime = NOW();
SELECT
idCustomer
FROM NextCalls WHERE @nowTime-nextCall =
(SELECT MAX(@nowTime - nextCall)
FROM NextCalls
WHERE idProject = p_idProject AND nextCall < @nowTime)
LIMIT 1;
END $$
列上设置了索引nextCall
。mysql-slow.log
不幸的是,它作为未正确使用索引的查询被登录到文件中。这个过程非常非常频繁地使用,我很乐意避免错误的索引。是否可以重写以实现这一目标?