Thread

  1. Re: Can anyone make this code tighter? Too slow, Please help!

    Mark Stosberg <mark@summersault.com> — 2007-02-09T21:04:31Z

    shane.eckel@seattlesoftware.com wrote:
    > I have this function in my C#.NET app that goes out to find the
    > business units for each event and returns a string (for my report).
    > I'm finding that for larger reports it takes too long and times out.
    > 
    > Does anyone know how I can speed this process up?  Is this code very
    > tight or could it be cleaner?  thanks in advance for your help, this
    > is a big issue used on several reports.
    
    Perhaps try "EXPLAIN ANALYZE" on this query, given a valid event ID:
    
                SELECT     Distinct Companies.Name
                            FROM         Companies INNER JOIN
                          ExpenseAllocations ON Companies.ID =
    ExpenseAllocations.BusinessUnitID
                            WHERE     (ExpenseAllocations.EventID =
    @EventID)
                            ORDER BY Companies.Name DESC
    
    
    #######
    Do the columns used in the join and WHERE clause have indexes?
    
    It's also possible the optimization needs to happen at a different level. Perhaps you are frequently
    looking up the same results in a large report, or throughout the day.
    
    If this part doesn't need to be up-to-second fresh, perhaps your application could
    cache some of the results of this function, instead of repeatedly asking the database
    to recompute it.
    
       Mark