A
Aaron
I have a section of code that runs and works as expected, except it
takes too long. The idea is to return a 90 percentile time from a
large table of maintenace actions, grouped by year, site, and part
number. The datafile has 2.2M records and 301K unique year, site,
part number combos, so execution time is an issue. I set this to run
over the weekend and it only returned 60K of the 301K rows, before I
had to break the code. Stepping through it shows that opening the
querydef w/ parameters takes the longest 5-8 seconds. Any ideas on
how I can speed this up would be great!
Public Function getTRR()
'genterates TRR number for compiled data file
Dim DB As DAO.Database
Dim qryTRR, rst, TRRlu, refrst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim i, j, k, TRRm As Integer
Dim strSQL As String
'make table to group distinct Fy, ORG, Niin
DoCmd.SetWarnings False
'DoCmd.OpenQuery "mk_reftbl"
'clear TRR Table
DoCmd.RunSQL ("DELETE TRR_look_up.* FROM TRR_look_up")
DoCmd.SetWarnings True
'set recordsets
Set DB = CurrentDb
Set refrst = DB.OpenRecordset("reftbl") 'table for unique
combinations
Set TRRlu = DB.OpenRecordset("TRR_look_up") 'reference table for
the output
Set qdf = DB.QueryDefs("qryTRRgrp")
Do While Not refrst.EOF
'set variable parameters to pass to the query
qdf.Parameters("paraFY") = refrst![Fiscal year]
qdf.Parameters("paraORG") = refrst![Action Org Code]
qdf.Parameters("paraNiin") = refrst![Rmvd NIIN]
Set rst = qdf.OpenRecordset()
If rst.RecordCount > 0 Then
k = 0
'pick 90th percentile
j = Int(0.9 * rst.RecordCount)
For i = 0 To j
TRRm = (rst![TRR] + 1) 'add 1 to make up the
difference with TAT
rst.MoveNext
Next
'open TRR look up table to add new records
TRRlu.AddNew
TRRlu![Fiscal year] = refrst![Fiscal year]
TRRlu![Org] = refrst![Action Org Code]
TRRlu![niin] = refrst![Rmvd NIIN]
TRRlu![TRRm] = TRRm
TRRlu.Update
Else
End If
refrst.MoveNext
Loop
TRRlu.Close
refrst.Close
DoCmd.DeleteObject acTable, "reftbl"
End Function
-and the query qryTRRgrp-
PARAMETERS paraFY Text ( 255 ), paraORG Text ( 255 ), paraNiin Text
( 255 );
SELECT FRC_M_lvl1.Fiscal_Year, FRC_M_lvl1.[Action Org Code],
FRC_M_lvl1.[Rmvd NIIN], FRC_M_lvl1.MCN, FRC_M_lvl1.TRR
FROM FRC_M_lvl1
WHERE (((FRC_M_lvl1.Fiscal_Year)=[paraFY]) AND ((FRC_M_lvl1.[Action
Org Code])=[paraORG]) AND ((FRC_M_lvl1.[Rmvd NIIN])=[paraNiin]))
ORDER BY FRC_M_lvl1.TRR;
Thanks for any help!
Aaron
takes too long. The idea is to return a 90 percentile time from a
large table of maintenace actions, grouped by year, site, and part
number. The datafile has 2.2M records and 301K unique year, site,
part number combos, so execution time is an issue. I set this to run
over the weekend and it only returned 60K of the 301K rows, before I
had to break the code. Stepping through it shows that opening the
querydef w/ parameters takes the longest 5-8 seconds. Any ideas on
how I can speed this up would be great!
Public Function getTRR()
'genterates TRR number for compiled data file
Dim DB As DAO.Database
Dim qryTRR, rst, TRRlu, refrst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim i, j, k, TRRm As Integer
Dim strSQL As String
'make table to group distinct Fy, ORG, Niin
DoCmd.SetWarnings False
'DoCmd.OpenQuery "mk_reftbl"
'clear TRR Table
DoCmd.RunSQL ("DELETE TRR_look_up.* FROM TRR_look_up")
DoCmd.SetWarnings True
'set recordsets
Set DB = CurrentDb
Set refrst = DB.OpenRecordset("reftbl") 'table for unique
combinations
Set TRRlu = DB.OpenRecordset("TRR_look_up") 'reference table for
the output
Set qdf = DB.QueryDefs("qryTRRgrp")
Do While Not refrst.EOF
'set variable parameters to pass to the query
qdf.Parameters("paraFY") = refrst![Fiscal year]
qdf.Parameters("paraORG") = refrst![Action Org Code]
qdf.Parameters("paraNiin") = refrst![Rmvd NIIN]
Set rst = qdf.OpenRecordset()
If rst.RecordCount > 0 Then
k = 0
'pick 90th percentile
j = Int(0.9 * rst.RecordCount)
For i = 0 To j
TRRm = (rst![TRR] + 1) 'add 1 to make up the
difference with TAT
rst.MoveNext
Next
'open TRR look up table to add new records
TRRlu.AddNew
TRRlu![Fiscal year] = refrst![Fiscal year]
TRRlu![Org] = refrst![Action Org Code]
TRRlu![niin] = refrst![Rmvd NIIN]
TRRlu![TRRm] = TRRm
TRRlu.Update
Else
End If
refrst.MoveNext
Loop
TRRlu.Close
refrst.Close
DoCmd.DeleteObject acTable, "reftbl"
End Function
-and the query qryTRRgrp-
PARAMETERS paraFY Text ( 255 ), paraORG Text ( 255 ), paraNiin Text
( 255 );
SELECT FRC_M_lvl1.Fiscal_Year, FRC_M_lvl1.[Action Org Code],
FRC_M_lvl1.[Rmvd NIIN], FRC_M_lvl1.MCN, FRC_M_lvl1.TRR
FROM FRC_M_lvl1
WHERE (((FRC_M_lvl1.Fiscal_Year)=[paraFY]) AND ((FRC_M_lvl1.[Action
Org Code])=[paraORG]) AND ((FRC_M_lvl1.[Rmvd NIIN])=[paraNiin]))
ORDER BY FRC_M_lvl1.TRR;
Thanks for any help!
Aaron