I would like to know which of the following examples is best for closing a record set object in my situation?
1)
This object closes the object inside the loop, but the next time it opens, a new object opens. If there were 1000 entries, this opens the object 1000 times and closes it 1000 times. This is what I usually did:
SQL = " ... "
Set rs1 = conn.Execute(SQL)
While NOT rs1.EOF
SQL = " ... "
Set rs2 = conn.Execute(SQL)
If NOT rs2.EOF Then
Response.Write ( ... )
End If
rs2.Close : set rs2 = Nothing
rs1.MoveNext
Wend
rs1.Close : Set rs1 = Nothing
2)
This example is what I want to know about. Does object closure (rs2.close) persist until the loop completes, improves or decreases performance? If there were 1000 records, this would open 1000 objects, but only close them once:
SQL = " ... "
Set rs1 = conn.Execute(SQL)
While NOT rs1.EOF
SQL = " ... "
Set rs2 = conn.Execute(SQL)
If NOT rs2.EOF Then
Response.Write ( ... )
End If
rs1.MoveNext
Wend
rs1.Close : Set rs1 = Nothing
rs2.Close : set rs2 = Nothing
I hope I explained myself well enough, and this is not too stupid.
UPDATE
For those who believe that my request can be modified to avoid problems with N + 1 (second request), here it is:
-. ; "photoSearch" "" . -, "photoSearch" , "photoID", "headline", "caption", "people", "dateCaptured" "keywords". (, , , ). , "" , ; , , , , , . 500K +, 2000+ .
, :
( : , - "-" . , , )
SQL = "SELECT photoID FROM photoSearch
WHERE MATCH (headline, caption, people, keywords)
AGAINST ('"&booleanSearchStr&"' IN BOOLEAN MODE)
AND dateCaptured BETWEEN '"&fromDate&"' AND '"&toDate&"' LIMIT 0,50;"
Set rs1 = conn.Execute(SQL)
While NOT rs1.EOF
SQL = "SELECT photoID, setID, eventID, locationID, headline, caption, instructions, dateCaptured, dateUploaded, status, uploaderID, thumbH, thumbW, previewH, previewW, + more FROM photos LEFT JOIN events AS e USING (eventID) LEFT JOIN location AS l USING (locationID) WHERE photoID = "&rs1.Fields("photoID")&";"
Set rs2 = conn.Execute(SQL)
If NOT rs2.EOF Then
Response.Write ( .. photo data .. )
End If
rs2.Close
rs1.MoveNext
Wend
rs1.Close
, , "photoSearch" "" , , . "photoSearch", - . , , , , . , . , .