Hi Experts,
I have a report that takes too long to generate. Below is the fuctions that generates the report.
How can I update my function to speed it?
Could I use a static variable to speed it up?
Should I use Temp tables?
Sub Main() dim dt as datatable = "select * from orders,items where orders.itemid = item.itemid and invdate between Jan and Dec" for each dr as datarow in dt.rows call ProcFunc(dr) next drend subSub ProcFunc(dr as datarow) dim dtProc as datatable = "select * from bigtable, itemdetail where bigtable.itemid = itemdetail.itemid and location = " & dr!location for each drSlowProc in dtProc.rows dim Cost as decimal = CalcLanded(dr!cost, drSlowProc!duty, dr!location) dim dtThis as datatable = "select * from hugetable where location = " & dr!location & " and Cost between 10 and 20" call OtherFunc(Cost, drThis) next drSlowProcend sub
Any process that has nested searches is going to be slow. Can you show us what you are trying to generate as this will allow us to perhaps come up with a better solution.
Qlemo
Using repetive SQL calls to get data is almost always a costly operation, because of the overhead involved for each SQL call.
So the first try is to make it a single SQL getting all data as required. And only the data required, that is you should restrict the columns to retrieve to allow for SQL, disk I/O, network I/O and memory optimization.
Also, in ProcFunc you are calling the SQL for hugetable in a loop though it does not have any changing parameters. You need to run that SQL only once per DR record, so move it infront of the FOR loop.