我有一个关于SQL 2016 SP2的SQL视图,它连接了14个没有谓词的表。
WHEN dsp.DimSourceSystemID=2 THEN edsp.CyberExposureGroup
WHEN dsp.DimSourceSystemID=4 THEN vdsp.CyberExposureGroup
ELSE 'Unknown' END AS CyberExposureGroup
FROM dwh.DimPolicy dsp
INNER JOIN Eclipse.DimPolicyExt edsp
ON dsp.DimEclipsePolicyExtID = edsp.DimEclipsePolicyExtID
INNER JOIN Velocity.DimPolicyExt vdsp
ON dsp.DimVelocityPolicyExtID = vdsp.DimVelocityPolicyExtID
INNER JOIN DWH.DimProgramme dp
ON dsp.DimProgrammeID = dp.DimProgrammeID
INNER JOIN DWH.DimPricingLeaderStatus dpls
ON edsp.DimPricingLeaderStatusID = dpls.DimPricingLeaderStatusID
INNER JOIN DWH.DimPlacingBasis dpb
ON dsp.DimPlacingBasisID = dpb.DimPlacingBasisID
INNER JOIN DWH.DimCoverageBasis dcb
ON dsp.DimCoverageBasisID = dcb.DimCoverageBasisID
--INNER JOIN DWH.DimNewRenewed dnr
-- ON dsp.DimNewRenewedID = dnr.DimNewRenewedID
INNER JOIN DWH.DimSubClass dsc
ON edsp.DimSubClassID = dsc.DimSubClassID
INNER JOIN DWH.DimStatsMinorClass dsminc
ON edsp.DimStatsMinorClassID = dsminc.DimStatsMinorClassID
INNER JOIN DWH.DimStatsMajorClass dsmajc
ON edsp.DimStatsMajorClassID = dsmajc.DimStatsMajorClassID
----------------------R5--------------------------
INNER JOIN DWH.DimCoverholder cv
ON edsp.DimCoverholderID = cv.DimCoverholderID
----------------------R7--------------------------
LEFT JOIN dwh.DimPlacingBasis MDPB
ON MDPB.MasterDataPlacingBasis = edsp.MasterPlacingBasis
INNER JOIN DWH.DimAssured da
ON dsp.DimAssuredID = da.DimAssuredID
--Underwriter Information R15
INNER JOIN DWH.DimUnderwriter duw
ON dsp.DimUnderwriterID = duw.DimUnderwriterID
我想使用循环连接提示,这样查询的并行性开销就会更少。
WHEN dsp.DimSourceSystemID=2 THEN edsp.CyberExposureGroup
WHEN dsp.DimSourceSystemID=4 THEN vdsp.CyberExposureGroup
ELSE 'Unknown' END AS CyberExposureGroup
FROM dwh.DimPolicy dsp
INNER LOOP JOIN Eclipse.DimPolicyExt edsp
ON dsp.DimEclipsePolicyExtID = edsp.DimEclipsePolicyExtID
INNER LOOP JOIN Velocity.DimPolicyExt vdsp
ON dsp.DimVelocityPolicyExtID = vdsp.DimVelocityPolicyExtID
INNER LOOP JOIN DWH.DimProgramme dp
ON dsp.DimProgrammeID = dp.DimProgrammeID
INNER LOOP JOIN DWH.DimPricingLeaderStatus dpls
ON edsp.DimPricingLeaderStatusID = dpls.DimPricingLeaderStatusID
INNER LOOP JOIN DWH.DimPlacingBasis dpb
ON dsp.DimPlacingBasisID = dpb.DimPlacingBasisID
INNER LOOP JOIN DWH.DimCoverageBasis dcb
ON dsp.DimCoverageBasisID = dcb.DimCoverageBasisID
--INNER JOIN DWH.DimNewRenewed dnr
-- ON dsp.DimNewRenewedID = dnr.DimNewRenewedID
INNER LOOP JOIN DWH.DimSubClass dsc
ON edsp.DimSubClassID = dsc.DimSubClassID
INNER LOOP JOIN DWH.DimStatsMinorClass dsminc
ON edsp.DimStatsMinorClassID = dsminc.DimStatsMinorClassID
INNER LOOP JOIN DWH.DimStatsMajorClass dsmajc
ON edsp.DimStatsMajorClassID = dsmajc.DimStatsMajorClassID
----------------------R5--------------------------
INNER LOOP JOIN DWH.DimCoverholder cv
ON edsp.DimCoverholderID = cv.DimCoverholderID
----------------------R7--------------------------
LEFT LOOP JOIN dwh.DimPlacingBasis MDPB
ON MDPB.MasterDataPlacingBasis = edsp.MasterPlacingBasis
INNER LOOP JOIN DWH.DimAssured da
ON dsp.DimAssuredID = da.DimAssuredID
--Underwriter Information R15
INNER LOOP JOIN DWH.DimUnderwriter duw
ON dsp.DimUnderwriterID = duw.DimUnderwriterID
这是可行的,查询运行得更快,但会牺牲更多的IO,但令我惊讶的是,对于两个不同版本的视图,我得到的行数略有不同。7877287行,而7877285行。这是一个数据仓库,但没有插入。那么连接提示会影响行的总数吗?或者这可能是一个错误吗?
好吧,我自己已经解决了问题所在——这是SSMS中的一个错误!我使用的是SSMS 18.6,右下角显示的行数不正确。如果你真的查看结果选项卡中的行数,那么它们确实是对应的,也就是说连接提示没有区别,这是有意义的