0

I have a DAO recordset that opens the following query:

SELECT sd.pointnumber
FROM (sdn INNER JOIN sd ON sdn.filename=sd.filename) 
INNER JOIN o ON sd.oID = o.id
WHERE o.id = [oID] 
And sdn.Line <>  [sdnLine];

Table sd has about 500,000 records and 30 columns, table sdn has about 5000 records and 4 columns. Table O has 6 records and 12 columns.

I open the recordset with:

Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("oSdSdn2")
qdf.Parameters("oID") = oID
qdf.Parameters("sdnLine") = line
Set rs = qdf.OpenRecordset(dbOpenForwardOnly)

When I have the database open as the only user, the first time I call .MoveNext on rs, it takes 1-2 minutes to execute; after that, each .MoveNext happens in less than a second. When there are multiple users in the database, every .MoveNext takes 1-2 minutes.

Tables are already indexed on sdn.Line, o.id, and sd.oID.

I tried structuring the query differently in the hopes of reducing the total number of rows to process:

select pointnumber from
(select pointnumber,filename from sd where oID=[oID]) sd
inner join
sdn
on
sd.filename=sdn.filename
where
sdn.line<>[sdnLine]

This didn't change the time at all. Is there any way to speed up this query, especially if there are multiple users?

1 Answer 1

0

It's not your query. It's your table. Your filters are on the smaller tables, so index are not required for them. However, your big table sd would need an index on filename, based on how you use it your query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.