[Solved] SLOW running query in MS access

EverSQL Database Performance Knowledge Base

SLOW running query in MS access

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:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. 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.
  2. 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:
SELECT
        WD.IdentityUserID,
        WD.Email,
        AD.mail 
    FROM
        WD 
    INNER JOIN
        AD 
            ON WD.IdentityUserID = AD.GGDComputerUserId 
    WHERE
        (
            (
                (
                    AD.mail
                ) NOT IN (
                    SELECT
                        WD.EMAIL 
                    FROM
                        WD
                )
            )
        )

Related Articles



* original question posted on StackOverflow here.