我正在尝试强制SQL服务器使用hash match for exists子句,如下所示。
FROM
[Dbo].[360 Nrc Data] AS [nrc]
WHERE
[CALENDAR_DATE] BETWEEN @START_DATE AND @End_Date
AND EXISTS (SELECT 1
FROM [staging].[FACT_DTV_RETENTION_EVENT_STEP_1] AS [fact]
WHERE [fact].[CD_PORTFOLIO_ID] = [nrc].[Cd_Portfolio_Id]
AND [fact].[Event_Date] = [nrc].[CALENDAR_DATE])
GROUP BY
[Calendar_Date], [Cd_Portfolio_Id])
强制查询提示的常规方法如下所示,但Left Semi Join比join
更有效[_fact_date_and_portfolio] AS [fact]
inner hash join
[dbo].[360 TA Offer] AS [offr]
答案 0 :(得分:2)
没有提示语法来指定特定半连接或反半连接运算符的物理连接类型。
但是由于此计划只有一个联接,您只需将OPTION (HASH JOIN)
添加到查询的末尾即可。提示适用于所有连接,但没有任何其他连接。