Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Need some performance help, please!


Reply
 
Thread Tools Display Modes
  #1  
Old 01-09-2003, 07:34 AM
shizox shizox is offline
Freshman
 
Join Date: Jan 2003
Posts: 29
Arrow Need some performance help, please!


hi guys, i have the following code that i would like to tune to make it run better either from SQL point or VB. currently it runs about 7 seconds. we have about 30,000 records in our database and we plan to grow it to 3,000,000 (yup, i need some help).

the recordset rstCandidates (main loop) has only 1,300 records when it takes 7 seconds.

thanks guys.
Code:
    'code to get recordset with one column of IDs
  

    'go through all of them
    While Not rstCandidates.EOF
        arPreselectedCandidates = rstCandidates.GetRows(50) 
	'this will return quoted ids separated by comma ex: 'id01','id02',etc

        strPreselectedCandidates = GetPreselectedCandidatesString(arPreselectedCandidates)

        Set rstCanTemp = New ADODB.Recordset

        strSQL = "SELECT * FROM table1 " & _
        "WHERE Contact_ID IN (" & strPreselectedCandidates & "); "
       
        strSQL = strSQL & "SELECT * FROM table2 " & _
        "WHERE Contact_ID IN (" & strPreselectedCandidates & "); "
        
        strSQL = strSQL & "SELECT * FROM table3 " & _
        "WHERE Contact_ID IN (" & strPreselectedCandidates & "); "

        
        With rstCanTemp
            Set .ActiveConnection = con
            .Source = strSQL
            .CursorLocation = adUseClient
            .CursorType = adOpenForwardOnly
            .LockType = adLockReadOnly
            .Open
        End With
  
        'i found that running it once is faster then 3 separate queries.
      
        If Not rstCanTemp.EOF Then arr1 = rstCanTemp.GetRows
        Set rstCanTemp = rstCanTemp.NextRecordset

        If Not rstCanTemp.EOF Then arr2 = rstCanTemp.GetRows
        Set rstCanTemp = rstCanTemp.NextRecordset

        If Not rstCanTemp.EOF Then arr3 = rstCanTemp.GetRows
        rstCanTemp.Close


	.
	.
	.

    loop
Reply With Quote
  #2  
Old 01-09-2003, 07:58 AM
Stewie
Guest
 
Posts: n/a
Default

do you really need ALL of the fields in the tables?
Reply With Quote
  #3  
Old 01-09-2003, 07:58 AM
shizox shizox is offline
Freshman
 
Join Date: Jan 2003
Posts: 29
Default

i'm simply concatinating the string 3 times joining 3 separate queries, i don't really know what your asking
Reply With Quote
  #4  
Old 01-09-2003, 07:59 AM
shizox shizox is offline
Freshman
 
Join Date: Jan 2003
Posts: 29
Default

which fields?
__________________
HARDFIND.COM - buy/sale/trade hardware free!
Reply With Quote
  #5  
Old 01-09-2003, 07:59 AM
Stewie
Guest
 
Posts: n/a
Default

try this aswell

.CursorLocation = adUseserver

you could also use a stored procedure to do the searching in SQL
Reply With Quote
  #6  
Old 01-09-2003, 08:03 AM
shizox shizox is offline
Freshman
 
Join Date: Jan 2003
Posts: 29
Default

Quote:
Originally posted by Stewie
try this aswell

.CursorLocation = adUseserver
Server side cursor doesn't support mutirecordsets and its usually slower than client side
Reply With Quote
  #7  
Old 01-09-2003, 08:07 AM
Stewie
Guest
 
Posts: n/a
Default

When i say do you need all the fields in the tables i meant, Do you need to Select all of the fields in the tables?
how many fields are there?

because i have found that in a table with about 10-15 fields, if i only select the 2 i need or whatever. it is a heck of a lot faster than grabbing all fields
Reply With Quote
  #8  
Old 01-09-2003, 08:09 AM
shizox shizox is offline
Freshman
 
Join Date: Jan 2003
Posts: 29
Default

Quote:
Originally posted by Stewie
When i say do you need all the fields in the tables i meant, Do you need to Select all of the fields in the tables?
how many fields are there?

because i have found that in a table with about 10-15 fields, if i only select the 2 i need or whatever. it is a heck of a lot faster than grabbing all fields
ohh, gotcha.

and the answer is i don't in reality, i changed the queries in this example to make it easier to read for you guys.

thanks
Reply With Quote
  #9  
Old 01-09-2003, 08:13 AM
Stewie
Guest
 
Posts: n/a
Default

maybe your just cursed with a slow network like me!!

but i think you should try making it a stored procedure, because they can make things really fast!
Reply With Quote
  #10  
Old 01-09-2003, 08:19 AM
shizox shizox is offline
Freshman
 
Join Date: Jan 2003
Posts: 29
Default

Quote:
Originally posted by Stewie
maybe your just cursed with a slow network like me!!

but i think you should try making it a stored procedure, because they can make things really fast!
lol, its not the network issue as this runs on my development box.
and i cant really use stored procedure since the queries contain 'IN ()' clause and optimizer will have to compile the SP everytime it runs, thus no performance gain...

thanks for your thought though
Reply With Quote
  #11  
Old 01-09-2003, 08:29 AM
Stewie
Guest
 
Posts: n/a
Default

im doing well..
*moves aside lets the experts help*
Reply With Quote
  #12  
Old 01-09-2003, 09:50 AM
MrFerrari MrFerrari is offline
Regular
 
Join Date: Dec 2002
Location: Calgary Alberta, Canada
Posts: 56
Default

I assume you are using MS SQL? Which version are you using? Also, I assume you have indecies (thats the plural of index right?) set up as well? How many fields from these tables are you querying, as you said you simplified the queries?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->