在我以前的经验中,并行成本阈值并不能帮助降低CXPACKET。
CXPACKET
由于不正确的统计信息会导致高等待时间,从而导致偏斜现象。
- 有关CXPACKET等待的更多信息:倾斜的并行性
- Microsoft Connect项目
- 我的查询是(不是)因为并行而等待吗?-蒂姆·福特
以下是我用来查找同时包含CXPacket和“ 其他等待 ”的会话的SQL (请参见下面的数据)。
的SQL
DECLARE @RawResult TABLE ([database_id] INT,[session_id] INT,exec_context_id INT, [blocking_session_id] INT,task_state VARCHAR(20),
[cpu_time] BIGINT,[wait_duration_ms] BIGINT, [wait_type] VARCHAR(100),[resource_description] nvarchar(3072),
[sql_handle] varbinary(64),[plan_handle] varbinary(64)
)
INSERT INTO @RawResult
SELECT
[R].[database_id],
[S].[session_id],
[W].exec_context_id,
[W].blocking_session_id,
[T].task_state,
[R].[cpu_time],
[W].[wait_duration_ms],
[W].[wait_type],
[W].[resource_description],
[R].[sql_handle],
[R].[plan_handle]
FROM sys.dm_os_waiting_tasks [W]
INNER JOIN sys.dm_os_tasks [T] ON
[W].[waiting_task_address] = [T].[task_address]
INNER JOIN sys.dm_exec_sessions [S] ON
[W].[session_id] = [S].[session_id]
INNER JOIN sys.dm_exec_requests [R] ON
[S].[session_id] = [R].[session_id]
WHERE [S].[is_user_process] = 1
--AND S.session_id <> @@SPID--???
--ORDER BY [W].[session_id],[W].[exec_context_id];
SELECT
DB_NAME(C.database_id) AS database_name,
C.[database_id],
C.[session_id],
C.exec_context_id,
C.blocking_session_id,
C.task_state,
C.[cpu_time],
C.[wait_duration_ms],
C.[wait_type],
C.[sql_handle],
C.[plan_handle],
[H].text,
[P].[query_plan],
C.[resource_description]
FROM @RawResult C
OUTER APPLY sys.dm_exec_sql_text (C.[sql_handle]) [H]
OUTER APPLY sys.dm_exec_query_plan (C.[plan_handle]) [P]
WHERE C.[session_id] IN
(
SELECT A.[session_id]
FROM @RawResult A
INNER JOIN @RawResult B
ON A.[session_id] = B.[session_id]
AND A.wait_type='CXPACKET'
AND B.wait_type <> 'CXPACKET'
)
ORDER BY C.[session_id],C.[exec_context_id]
大型扫描也可能是根本原因的一部分。当我从上述查询中检查执行计划时,我在数据库中发现了一个这样的扫描。执行计划中也缺少索引建议。