I have been working on Coldfusion / MS SQL for many years, and this is one of the strangest problems I have seen. Since then, the problem itself has been resolved, but I do not quite understand what happened; this question is trying to get a clear idea of the probable cause.
Problem
In a stable production environment, for no apparent reason, one request starts to return in about 1000-1500 ms (about 10 times slower than usual). I managed to highlight this:
<cfquery datasource="#ds#" name="query"> select 1 from eLearning.v_courseCompletion cc where cc.memberIncId = <cfqueryparam value="3" cfsqltype="cf_sql_integer"> and cc.courseId = <cfqueryparam value="25" cfsqltype="cf_sql_integer"> and cc.currentCourseCompleted = 1 </cfquery>
What is strange, this behavior is compounded when inside the loop, even when there is one iteration, as in this example:
<cfloop from="1" to="1" index="i"> <cfquery datasource="#ds#" name="query"> select 1 from eLearning.v_courseCompletion cc where cc.memberIncId = <cfqueryparam value="3" cfsqltype="cf_sql_integer"> and cc.courseId = <cfqueryparam value="25" cfsqltype="cf_sql_integer"> and cc.currentCourseCompleted = 1 </cfquery> </cfloop>
It should be exactly the same as above, right? The loop should have no effect, but instead this test runs about 10 times slower, returning between 7000-16000 ms. This is how the problem was discovered; the request (buried inside the method of the object) is called from the body of the cycle, if the cycle is repeated more than 5 or 6 times, the request expires.
For me, this indicated a problem on the part of Coldfusion, but restarting the service or even the machine did nothing.
Meanwhile, when I was isolated, I noticed that making any changes to the request itself made the performance return to the expected level of about 150-190 ms. For example:
- Change selected fields (i.e.
select * ) - Removing a table alias (
cc ) - Replacing either
<cfqueryparam> with an inline value - Removing any of the conditions
Any of these changes fixed the problem, but when you run the original query, the performance problem will return.
Decision
At this point, I realized that the query execution plan was corrupted or something like some Googling and started DBCC FREEPROCCACHE against the database server. This fixed the problem immediately. Great, the problem is resolved ....
Question
Since then, though, I have done a little more research, and the consensus seems to be that the implementation plans are "not damaged." There are a few conversations of similar problems related to stored procedures, and the sniffing option , but I do not use sp. We choose from a rather complex view, though ( eLearning.v_courseCompletion ) with nested joins. This is problem?
Basically, what really happened here? How can I stop him again?
.. and what the hell is connected with cycles in CF?!?
Versions
- Coldfusion 9.0.2.282541 (64 bit)
- SQL Server Express 10.50.4297 (64 bit)
- Both servers are the Datacenter (64-bit) Win Server 2008 R2