Hi,
The following query sometimes runs efficiently; gives quick results, CPU and IO utilization is also up to the mark. But sometimes the query takes very long time to execute. At that time I do not observe any blocks as well. Also the CPU and IO is too huge for running this query. It seems the engine picks up wrong execution plan some times.
This query is fired through some product. So there is no scope to change the query. Any suggestions for the engine to pick up right execution plan?
select i . bpd_instance_id as instanceId , i . instance_name as instanceName , bpd . name as bpdName , istatus . name as instanceStatus , t . subject as taskSubject , tpriority . name as taskPriority , t . due_date as taskDueDate , t . attached_form_ref as taskAttachedInfoPathFormRef , t . attached_ext_activity_ref as taskAttachedExtActivityRef , t . task_id as taskId , tstatus . name as taskStatus , tuser . user_name as assignedToUser , tpriority . ranking as taskPriorityRanking from msadmin.lsw_task t with ( nolock ) inner join msadmin.lsw_bpd_instance i with ( nolock ) on t . bpd_instance_id = i . bpd_instance_id left join msadmin.lsw_task_status_codes tstatus on t . status = tstatus . status_value left join msadmin.lsw_bpd_status_codes istatus on i . execution_status = istatus . status_id left join msadmin.lsw_priority tpriority on t . priority_id = tpriority . priority_id left join msadmin.lsw_bpd bpd on i . cached_bpd_version_id = bpd . version_id left join msadmin.lsw_usr_xref tuser on t . user_id = tuser . user_id where ( t . status in ( '11','12' ) and ( t . user_id = 5909 or t . task_id in (
select t . task_id
from msadmin.lsw_task t with ( NOLOCK )
inner join msadmin.lsw_usr_grp_mem_xref m with ( NOLOCK )
on t . group_id = m . group_id
where m . user_id = 5909
and t . user_id = -1
) or t . task_id in (
select t . task_id
from msadmin.lsw_task t with ( NOLOCK )
inner join msadmin.lsw_grp_grp_mem_exploded_xref x with ( NOLOCK )
on t . group_id = x . container_group_id
inner join msadmin.lsw_usr_grp_mem_xref m with ( NOLOCK )
on m . group_id = x . group_id
where m . user_id = 5909
and t . user_id = -1
) ) ) order by taskDueDate , taskPriorityRanking , instanceId , taskId