+ -
当前位置:首页 → 问答吧 → 这样写 查询语句,查询非常慢,看下有什么办法能优化提高速度不?

这样写 查询语句,查询非常慢,看下有什么办法能优化提高速度不?

时间:2011-06-30

来源:互联网

<%if classId<>"" then
sqlPt="select * from Product where class1Id in ("&listChildClassId(classId)&") order by id desc"
else

sqlPt="select * from product order by id desc"
fileName="product.asp"
menuTitle="All Products"
 
end if



'列出某类下所有子类(包括自己)的classId
function listChildClassId(classId)
  dim ClassIds,rs
  sqlT="select * from pro_c1 where p_class1id="&classId
set rs=conn.execute(sqlT)
if not (rs.eof or rs.bof) then
do until rs.eof
classIds=classIds&","&listChildClassId(rs("class1Id"))
rs.movenext
Loop
end if
rs.close
Set rs=nothing
listChildClassId=classId&classIds
end function

%>

作者: ren0594   发布时间: 2011-06-30

建立一个mapping表。把对于的关系保存。这样,可以减少查数据库。

作者: dogfish   发布时间: 2011-06-30