主题:分页优化
ymboy
[专家分:10] 发布于 2007-06-12 08:51:00
有两个语言的后台代码,一个是JSP,一个是ASP的.
处理同一张表,数据有17万多,JSP的很快,差不多1秒,ASP是我自己做的,竟然要用13左右的时间啊!哎呀..太悲哀了...技术相差太远了啊...小弟是初学者.之前做的都是小数据的网站.刚换了一家公司,这里要做一个大项目,数据量比较多,现在是10多万,以后会更多.请大家提点建议..不然这样的速度根本不能用
回复列表 (共12个回复)
沙发
wangsdong [专家分:21390] 发布于 2007-06-12 08:56:00
把你的asp查询的代码和显示的代码贴出来,让别人找找
板凳
yaozheng [专家分:28410] 发布于 2007-06-12 09:19:00
这和某种语言是没关系的,关键看你的sql是否写的优化。
3 楼
ymboy [专家分:10] 发布于 2007-06-12 09:38:00
<%
set rs=Server.Createobject("ADODB.Recordset")
rs.open "select pkid,productname,isaudit,from product where isaudit > -1 order by isaudit desc,pkid desc",conn,1,2
if not rs.eof then
if page="" or not isnumeric(page) then
page=1
end if
if page<1 then
page=1
end if
rs.pagesize=16
rs.absolutepage=page
t=rs.pagesize
do while not rs.eof and t>0
t=t-1
Response.Write rs("productname") & "<br />"
rs.movenext
loop
%>
call PageShow()
<%
else
response.write "没有数据"
end if
rs.close
set rs=nothing
%>
4 楼
ymboy [专家分:10] 发布于 2007-06-12 09:41:00
Private Function GetURL()
Dim strurl,str_url,i,j,search_str,result_url
search_str="page="
strurl=Request.ServerVariables("URL")
Strurl=split(strurl,"/")
i=UBound(strurl,1)
str_url=strurl(i)'得到当前页文件名
str_params=Trim(Request.ServerVariables("QUERY_STRING"))
If str_params="" Then
result_url=str_url &"?"
Else
If InstrRev(str_params,search_str)=0 Then
result_url=str_url & "?" & str_params & "&"
Else
j=InstrRev(str_params,search_str)-2
If j=-1 Then
result_url=str_url & "?"
Else
str_params=Left(str_params,j)
result_url=str_url & "?" & str_params & "&"
End If
End If
End If
GetURL=result_url
End Function
Function PageShow()
p_count=rs.pagecount
r_count=rs.recordcount
page=cstr(page)
if p_count < 10 then
for i=1 to p_count
if page=cstr(i) then
str=str&"<font color='red'>"&i&"</font> "
else
str=str&"<A href='"&GetURL()&"page="&i&"'>["&i&"]</a> "
end if
next
if page<=1 then
if p_count > 1 then
str=str & "<A href='"&GetURL()&"page="&page+1&"'>下一页</a>"
end if
else
if page < cstr(p_count) then
str="<A href='"&GetURL()&"page="&page-1&"'>上一页</a> "&str & "<A href='/"&GetURL()&"page="&page+1&"'>下一页</a>"
else
str="<A href='"&GetURL()&"page="&page-1&"'>上一页</a> "&str
end if
end if
else
if p_count-page>3 then
endpage=page+4
starpage=page-5
else
endpage=p_count
starpage=p_count-10
end if
if page>6 then
for i=starpage to endpage
if page=cstr(i) then
str=str&"<font color='red'>"&i&"</font> "
else
str=str&"<A href='"&GetURL()&"page="&i&"'>["&i&"]</a> "
end if
next
else
for i=1 to 10
if page=cstr(i) then
str=str&"<font color='red'>"&i&"</font> "
else
str=str&"<A href='"&GetURL()&"page="&i&"'>["&i&"]</a> "
end if
next
end if
if page<=1 then
if p_count > 1 then
str=str & "<A href='"&GetURL()&"page="&page+1&"'>下一页</a>"
end if
else
if int(page) < int(p_count) then
str="<A href='"&GetURL()&"page="&page-1&"'>上一页</a> "&str & "<A href='"&GetURL()&"page="&page+1&"'>下一页</a>"
else
str="<A href='"&GetURL()&"page="&page-1&"'>上一页</a> "&str
end if
end if
end if
response.write "总共"&r_count&"条/"&p_count&"页记录 "&"<A href='"&GetURL()&"page=1'>首页</a> "& str & " <A href='"&GetURL()&"page="&p_count&"'>尾页</a> 转到:<input type='text' name='page' onfocus='this.select();' size=4 maxlength=10 class=smallInput value="&page&"> <input type='button' class='contents' value='GO' name='cndok' onClick=""if(document.all.page.value!=''){location='"& GetURL()&"page='+document.all.page.value;}"">"
End Function
5 楼
ymboy [专家分:10] 发布于 2007-06-12 09:42:00
PageShow() 这个是分页函数..是我自己写的..写得很不好..大家见笑了...
6 楼
wangsdong [专家分:21390] 发布于 2007-06-12 10:47:00
call PageShow()
怎么不在<% %>之间?
7 楼
ymboy [专家分:10] 发布于 2007-06-12 11:13:00
我表来有很多<td>为了看起来方便,我把他去掉了,忘了加<%%>
在我的代码里面是可以用的..
就是速度慢啊..
8 楼
ymboy [专家分:10] 发布于 2007-06-12 11:18:00
怎么都人帮忙啊..
UP
9 楼
lrj525 [专家分:260] 发布于 2007-06-12 14:50:00
Select Top "&PSize&" * From Expert Where ID Not In(Select Top "&PSize*(Page-1)&" ID From Expert Order By Title ASC) Order By Title ASC
PSize'每页条数
Page'当前页数
用这种分页方式我感觉效率会高点
10 楼
liulei001 [专家分:12820] 发布于 2007-06-12 14:55:00
没什么可悲哀的,应用不同,当然侧重点不同。
ASP仍然是目前最廉价最快速的解决方案。
至于处理数据表的问题,用存储过程完全可以解决。
数据库本身的效率和功能是任何程序都比不了的。
我来回复