I am using SQL Server 2014 Enterprise in Windows Server 2012.
I have checked Min
and Max Allocated Memory for SQL Server
is configured properly.
Yesterday, Users ran few reports parallely multiple times and got a lot of alerts (High CPU and High Memory). From below query, I found the top CPU utilized queries:
...
...
FROM sys.dm_exec_query_stats AS qs
cross apply sys.dm_exec_sql_text(qs.sql_handle) AS st
cross apply sys.dm_exec_query_plan (qs.plan_handle) AS qp
ORDER BY (total_worker_time/execution_count) desc, qs.last_execution_time DESC
I found the top 10 queries are exactly same except few changes in WHERE clause. execution_count = 1
for all queries. The queries are inserting records to a #temp table with below format:
Insert into #Temp(col1, col2,............)
Select
.
.
From
(
Select
.
.
Where (CONTAINS(val1, ' "xx1*" ') OR CONTAINS(val2, ' "yy1*" ') OR CONTAINS(val3, ' "zz1*" ')..........30-35 CONTAIN blocks)
-- here "xx*", "yy*" values are changing in each query (I guess this is due to parameter selection by end users)
) x
If these dynamic queries are the culprit, then what would be the solution to this (as Users are not going to stop running the queries)?
Can I ask to convert the report queries to SPs? How can I avoid the different execution plans that I am getting?
I manually killed the highly utilized queries, but this is not the solution.
Looking for help.
Update:
I do not see any Memory issue anymore. But the CPU still reaches to 100%.
I observed this above particular query (used in a report) is accessed by user frequently and the CPU utilization reaches to 100% when this query runs. It is happening regularly. The WHERE clause changes for each execution based on report parameter selection by the user (I don't know how exactly the report is designed or how the parameters are getting passed).
Additionally, I have checked the table statistics (everyday gets updated), Index correctly defined. The base table deals with more than 3 millions of rows(val1, val2...used in CONTAIN belong to this table).
What are the ways to tune this query?