使用queryNew()构建查询的效率如何?我最近遇到一个代码,它为一个“伪查询”创建了一个数据库调用,这个“伪查询”没有连接到任何这样的表:

<CFQUERY NAME="IncludeList" ....>
Select 0 as code, 'Exclude' as description
UNION ALL
Select 1 as code, 'Include' as description
</CFQUERY>


<cfset IncludeList = queryNew("code, description","Integer, VarChar")>
<cfset newrow = queryaddrow(IncludeList, 2)>
<cfset temp = querysetcell(IncludeList, "code", 0, 1)>
<cfset temp = querysetcell(IncludeList, "description", "Exclude", 1)>
<cfset temp = querysetcell(IncludeList, "code", 1, 2)>
<cfset temp = querysetcell(IncludeList, "description", "Include", 2)>

最佳答案

避免数据库连接。
对于qofq(即dbtype="query"),虽然这看起来是个好主意,但实际上,我已经看到当多个请求都命中同一个qofq时,服务器在负载下崩溃。基于堆栈跟踪,它显示qofq实现单个线程,阻塞其他线程。
另一方面,我也有代码做querySetCell()的事情,这并不是性能问题。

09-27 21:29