开发者

How much more efficient is building a recordset with newquery vs a union & connecting to database?

How more efficient is building the query using queryNew()? I recently came across code creating a db call for a "dummy query开发者_开发技巧" that didn't connect to any table like this:

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

VS

<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)>


Avoid database connections.

For QofQ (i.e. dbtype="query"), while it seems like a good idea, in practice I've seen servers under load crash when multiple requests all hit the same QofQ. Based on stack traces, it appears the QofQ implementation single threads, blocking other threads.

On the other hand I also have code doing the querySetCell() thing and that has not been a performance issue.


Limiting Database calls would should always be preferred.


I'd prefer to use QueryNew over a QoQ. It'll give you more flexibility in the long run.

Incidentally you know you don't have to assign functions like querysetcell to a 'temporary' variable:

<cfset temp = querysetcell(IncludeList, "code", 0, 1)>

You can just do:

<cfset querysetcell(IncludeList, "code", 0, 1)>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜