MS 访问中的慢 运行 查询

SLOW running query in MS access

是什么导致此查询执行时间过长。子查询块是否造成混乱?

SELECT WD.IdentityUserID, WD.Email, AD.mail
FROM WD INNER JOIN AD ON WD.IdentityUserID = AD.GGDComputerUserId
WHERE (((AD.mail) Not In (SELECT EMAIL FROM WD)));

不确定这是否有帮助,但您可以尝试通过预先过滤掉电子邮件来减少 "right side" 加入的大小:

SELECT  
 WD.IdentityUserID,  
 WD.Email,  
 T.mail  
FROM WD  
INNER JOIN  
 (  
    SELECT
     mail,  
     GGDComputerUserId     
    FROM AD  
    WHERE  
     mail Not In (SELECT EMAIL FROM WD)  
 ) T  
ON WD.IdentityUserID = T.GGDComputerUserId;  

(如果查询已经为此进行了优化,那么这没有什么区别)

我认为问题在于,对于 INNER JOIN 的每条记录,您都在遍历 WD table 的所有记录。

SELECT WD.IdentityUserID, WD.Email, AD.mail
FROM WD 
INNER JOIN AD ON WD.IdentityUserID = AD.GGDComputerUserId
WHERE NOT EXISTS(SELECT EMAIL FROM WD WHERE EMAIL = AD.mail);