Reputation: 827
I've written a web application in ASP which reads 3600 rows from a MySQL database (v5.1.63) and outputs the data in an HTML table. I'm using a recordset to get the data and pagesize/cursorlocation to let the user step forward/backward between the pages. The database contains some 200.000 rows right now but is continuously growing.
The page takes longer and longer to load (approx. 15-20 seconds now) and I would like to optimize it if possible.
I would be very interested in getting tips on how to improve the performance.
Here is the database structure:
# Col Type Collation Attributes Null Default 1 ID int(11) No None AUTO_INCREMENT 2 mean varchar(5) utf8_general_ci No None 3 max varchar(5) utf8_general_ci No None 4 min varchar(5) utf8_general_ci No None 5 dt varchar(20) utf8_general_ci No None 6 dir varchar(2) utf8_general_ci No None 7 log text utf8_general_ci No None
Here is the code I'm using:
' Opening the db
Set oConn = Server.CreateObject("ADODB.Connection")
Set oRS = Server.CreateObject("ADODB.Recordset")
oConn.ConnectionString =
"DRIVER={MySQL};SERVER=<server>;DATABASE=<database>;UID=<uid>;PWD=<pwd>;"
oConn.Open
' Retrieve 3600 records
sSQL = "SELECT * FROM mytable ORDER BY id DESC"
oRS.CursorLocation = adUseServer
oRS.PageSize = 6*600
oRS.Open sSQL, oConn, adOpenForwardOnly, adLockReadOnly
nPageCount = oRS.PageCount
...code to set the page selected by the user (nPage)
oRS.AbsolutePage = nPage
Do While Not (oRS.EOF Or oRS.AbsolutePage <> nPage)
...
Response.Write("<td>" & oRS("dt") & "</td>")
Response.Write("<td>" & oRS("mean") & "</td>")
Response.Write("<td>" & oRS("min") & "</td>")
Response.Write("<td>" & oRS("max") & "</td>")
...
oRS.MoveNext
Loop
oRS.Close
Upvotes: 1
Views: 334
Reputation: 7683
If you're using MySQL as the RDMS - it would be far more efficient if you performed the paging using mySqls LIMIT
clause:
i.e. to get 10 items per page for a given querystring page number:
ItemsPerPage = 10
PageNumber = request.querystring("Page")
if PageNumber = "" then
PageNumber = 0
end if
Limit = PageNumber * ItemsPerPage
Query = "SELECT * FROM mytable ORDER BY id DESC LIMIT " & Limit & ", " & ItemsPerPage
Upvotes: 2