I wonder if ColdFusion can get the execution plan from Microsoft SQL Server?
Or even the Estimated execution plan.
It would be nice to get a query back of all the costs.
I wonder if ColdFusion can get the execution plan from Microsoft SQL Server? Or
Share
As mentioned in the link @James posted, there are several methods you can use to retrieve the information about the execution plan using a simple
cfquery. A couple things to keep in mind:SET SHOWPLANoptions are usually applied to the session connection meaning they may persist beyond the current request if you are using connection pooling (which is undesirable). Be sure to always disable the setting at the end of the query – even if an error occurs.Some
SET SHOWPLANoptions return multiple resultsets.CFQueryonly returns a single resultset. So it may not capture all of the data returned.Most of the system views and procedures (sys.dm_exec_sql_text, etcetera …) require elevated permissions. The datasource user must be granted special access to use these objects. So keep in mind the security implications.
UPDATE:
As @Travis mentioned in the comments,
SET SHOWPLANoptions must be run separately. So you need separate cfquery’s to toggle the settingON|OFFbefore and after the main query. Here is a quick and dirty example. Note, the transaction is to ensure the same connection is used throughout. It may be overkill, but should not hurt anything.