 |
 |

01-09-2003, 07:34 AM
|
|
Freshman
|
|
Join Date: Jan 2003
Posts: 29
|
|
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
|
|

01-09-2003, 07:58 AM
|
|
|
|
do you really need ALL of the fields in the tables?
|
|

01-09-2003, 07:58 AM
|
|
Freshman
|
|
Join Date: Jan 2003
Posts: 29
|
|
i'm simply concatinating the string 3 times joining 3 separate queries, i don't really know what your asking 
|
|

01-09-2003, 07:59 AM
|
|
Freshman
|
|
Join Date: Jan 2003
Posts: 29
|
|
__________________
HARDFIND.COM - buy/sale/trade hardware free!
|

01-09-2003, 07:59 AM
|
|
|
|
try this aswell
.CursorLocation = adUseserver
you could also use a stored procedure to do the searching in SQL
|
|

01-09-2003, 08:03 AM
|
|
Freshman
|
|
Join Date: Jan 2003
Posts: 29
|
|
Quote:
Originally posted by Stewie
try this aswell
.CursorLocation = adUseserver
|
Server side cursor doesn't support mutirecordsets and its usually slower than client side
|
|

01-09-2003, 08:07 AM
|
|
|
|
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
|
|

01-09-2003, 08:09 AM
|
|
Freshman
|
|
Join Date: Jan 2003
Posts: 29
|
|
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
|
|

01-09-2003, 08:13 AM
|
|
|
|
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!
|
|

01-09-2003, 08:19 AM
|
|
Freshman
|
|
Join Date: Jan 2003
Posts: 29
|
|
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
|
|

01-09-2003, 08:29 AM
|
|
|
|
im doing well..
*moves aside lets the experts help*
|
|

01-09-2003, 09:50 AM
|
|
Regular
|
|
Join Date: Dec 2002
Location: Calgary Alberta, Canada
Posts: 56
|
|
|
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?
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|