I have a query in Microsoft Access, that needs c.a 6 seconds to return 1000 records.
SELECT DISTINCTROW tb_bauteile.*
FROM tb_bauteile
LEFT JOIN FehlerCodes_akt_Liste
ON tb_bauteile.CDT = FehlerCodes_akt_Liste.CDT
WHERE (( ( FehlerCodes_akt_Liste.Steuergerät ) = 'MEDC17' ))
ORDER BY FehlerCodes_akt_Liste.Fehlerpfad;
I put index on the neccessary fields. tb_bauteile has c.a 3000 records and FehlerCodes_akt_Liste has c.a 20000 records. If I delete Where and order Clause the query returns the records very fast. How can I optimize my query?
You have ...
tb_bauteile LEFT JOIN FehlerCodes_akt_Liste
But then this WHERE
clause ...
FehlerCodes_akt_Liste.Steuergerät = 'MEDC17'
That constraint makes the LEFT JOIN
moot ... your result set will include only rows where you have matches between tb_bauteile.CDT
and FehlerCodes_akt_Liste.CDT
. You may as well switch to an INNER JOIN
which should be faster.
Here are some other issues to examine.
DISTINCTROW
?CDT
, Steuergerät
, and Fehlerpfad
. Have you also performed a compact operation (which updates the statistics)?