What causing this query to execute long time. Is sub query block creating a mess?
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)));
How to optimize this SQL query?
The following recommendations will help you in your SQL tuning process. You'll find 3 sections below:
Description of the steps you can take to speed up the query.
The optimal indexes for this query, which you can copy and create in your database.
An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
Avoid Subqueries (query line: 16): We advise against using subqueries as they are not optimized well by the optimizer. Therefore, it's recommended to join a newly created temporary table that holds the data, which also includes the relevant search index.
Create Optimal Indexes (modified query below): The recommended indexes are an integral part of this optimization effort and should be created before testing the execution duration of the optimized query.
Optimal indexes for this query:
ALTER TABLE `AD` ADD INDEX `ad_idx_ggdcomputeruserid` (`GGDComputerUserId`);
The optimized query:
ON WD.IdentityUserID = AD.GGDComputerUserId
) NOT IN (