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.

  1. Do you notice any performance impact if you remove DISTINCTROW?
  2. So you have indexes on CDT, Steuergerät, and Fehlerpfad. Have you also performed a compact operation (which updates the statistics)?
  3. Examine the query plan which is created for your query. It can be challenging to interpret, but perhaps it will turn up something useful. Use Microsoft Jet's ShowPlan to write more efficient queries
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top