I created a table called test with fields n and f(n)
Temporary 3 different update routines - recordset without transaction - recordset with transaction - update request
Sub updateFunction_noTrans() Dim rs As Recordset Set rs = CurrentDb.OpenRecordset("test") rs.MoveFirst Do Until rs.EOF rs.Edit rs("f(n)") = rs("n") + 1 rs.Update rs.MoveNext Loop End Sub
This is basically what you do, a direct set of records when editing a field
Sub updateFunction_yesTrans() Dim i As Long Dim commitSize As Long Dim rs As Recordset commitSize = 5000 Set rs = CurrentDb.OpenRecordset("test") DBEngine.Workspaces(0).BeginTrans rs.MoveFirst Do Until rs.EOF rs.Edit rs("f(n)") = rs("n") + 1 rs.Update rs.MoveNext i = i + 1 If i = commitSize Then DBEngine.Workspaces(0).CommitTrans DBEngine.Workspaces(0).BeginTrans i = 0 End If Loop DBEngine.Workspaces(0).CommitTrans End Sub
This is the same idea, but with transactions. I commit 5,000 records at a time, since a certain limit was set between 9k-10k per commit. You can change this, I believe, by going to the registry.
Sub updateFunction_updateQuery() CurrentDb.Execute ("UPDATE test SET test.[f(n)] = [n]+1;") End Sub
This is faster than any of the record set methods. For instance. about 2 million records took ~ 20 seconds without transactions, ~ 18-19 seconds with transactions, ~ 14 seconds with an update request.
All this is under the assumption that the updated field depends on the values calculated from other intruders inside these records.
To really speed up these actions, sometimes it depends on the situation, and more details are required if it is not applied.
Edit: Used the old kernel 2 duos + field indices
source share