LambtonWorm
Registered User.
- Local time
- Today, 18:53
- Joined
- Jun 24, 2012
- Messages
- 12
Hi all.
Intro:
I'm a DB/Access novice, doing an internship at a firm with no real in-house IT expertise, so I'd be very grateful for any advice on optimising this query. Am I doing something wrong, or is is this the best possible performance?
Background:
I've made an Excel Application for running backtests, using an Access DB for data. I'm using DAO as I thought it would be faster.
I have a query which I'm calling from excel VBA. It calculates the sum of profit of all records on the fly. It works fine. But it seems slow at 6 milliseconds or more on the test machine. It is called hundreds of thousands of times during a backtest.
Is the inner JOIN expensive? I established a 1->many relationship within Access, for all the relevant tables, enforcing referential integrity, which I assumed would index behind the scenes and speed things up. Seems no faster with or without this.
Code:
Here is a legible example of the query SQL string :
Here is the query itself:
,where g_dbFAT is a global variable representing the database itself, set by WorkSpace.OpenDatabase
Summary:
Can this (and other) queries, called from Excel VBA using DAO OpenRecordset method, be sped up in any way?
Is 6 milliseconds reasonable, am I expecting too much?
Is there any further way of indexing?
Is DAO appropriate and is MS Access the limiting factor? If so what should I use?
Many Thanks
Intro:
I'm a DB/Access novice, doing an internship at a firm with no real in-house IT expertise, so I'd be very grateful for any advice on optimising this query. Am I doing something wrong, or is is this the best possible performance?
Background:
I've made an Excel Application for running backtests, using an Access DB for data. I'm using DAO as I thought it would be faster.
I have a query which I'm calling from excel VBA. It calculates the sum of profit of all records on the fly. It works fine. But it seems slow at 6 milliseconds or more on the test machine. It is called hundreds of thousands of times during a backtest.
Is the inner JOIN expensive? I established a 1->many relationship within Access, for all the relevant tables, enforcing referential integrity, which I assumed would index behind the scenes and speed things up. Seems no faster with or without this.
Code:
Here is a legible example of the query SQL string :
Code:
SELECT Sum([myTbl.Contracts]*(1234-[myTbl.TradedPrice])*tblStatic!PointValue-Abs([myTbl.Contracts])*tblStatic!ClearingCosts)
AS SumOfProfit, tblStatic.CCY
FROM tblStatic INNER JOIN myTbl ON tblStatic.Asset = myTbl.Security
GROUP BY tblStatic.CCY, myTbl.Confirmed, myTbl.Security
HAVING (((myTbl.Confirmed)=Yes) AND ((myTbl.Security)='myAsset'));
Code:
Public Function DBQ_cGetAllProfit(sTBL As String, sAsset As String, siSpot As Single) As Currency
Dim sSQL As String
Dim rst As DAO.Recordset
'-- Get records
sSQL = "SELECT Sum([" & sTBL & ".Contracts]*(" & CStr(siSpot) & "-[" & sTBL & ".TradedPrice])*tblStatic!PointValue-Abs([" & sTBL & ".Contracts])*tblStatic!ClearingCosts) " & _
"AS SumOfProfit, tblStatic.CCY " & _
"FROM tblStatic INNER JOIN " & sTBL & " ON tblStatic.Asset = " & sTBL & ".Security " & _
"GROUP BY tblStatic.CCY, " & sTBL & ".Confirmed, " & sTBL & ".Security " & _
"HAVING (((" & sTBL & ".Confirmed)=Yes) AND ((" & sTBL & ".Security)='" & sAsset & "'));"
Set rst = g_dbFAT.OpenRecordset(sSQL)
If Not rst.RecordCount = 0 Then
If Not IsNull(rst.Fields("SumOfProfit").Value) Then
DBQ_cGetAllProfit = rst.Fields("SumOfProfit").Value
End If
End If
'-- Tidy up
rst.Close
Set rst = Nothing
End Function
Summary:
Can this (and other) queries, called from Excel VBA using DAO OpenRecordset method, be sped up in any way?
Is 6 milliseconds reasonable, am I expecting too much?
Is there any further way of indexing?
Is DAO appropriate and is MS Access the limiting factor? If so what should I use?
Many Thanks