快速询问有关查询效果的问题。 在过去的几天里,我一直在努力解决查询性能问题。 在MS Access中,我有一个没有任何条件的查询(有~15个连接),它返回我~50列(id,name等等)和~1200条记录(所有记录)。此查询的执行时间约为15分钟。 但是当我添加一个简单的标准时:WHERE ID< 10000(或任何其他数字大于我的上一个id)(我的最大ID为1139)所有查询都在眨眼间执行。 有人可以解释一下为什么这么简单的条件会极大地加速我的查询吗?
这是查询(由SQLView中的Access生成):
SELECT MasterTableT.ID
,[General:CompanyProgrammeNameT].[Company Programme Abbreviation] AS [Company Programme]
,[General:BlockNameT].[Block Name]
,[General:Position/JobTitleT].[Position/Job Title]
,[General:DeliveryStreamT].[Delivery Stream]
,[General:AgileTeamT].[Agile Team name]
,MasterTableT.[Modification Date]
,[General:ProgrammePeopleT].[Full Name] AS [Functional Manager]
,MasterTableT.[Expected: StartDate]
,MasterTableT.[Expected: EndDate]
,DateDiff("m", [MasterTableT] ! [Expected: StartDate], [MasterTableT] ! [Expected: EndDate]) AS [Expected Duration of involvement (months)]
,[General:LocationsT].Locations AS [Expected location]
,[General:TravelT].Travel AS [Expected Travel]
,[General:ProfileTypeT].[Profile type] AS [Expected Profile Type]
,[General:HireTypeT].[Hire Type] AS [Expected Type of Hire]
,[General:BA/GF and UnitT].[BA/GF and Unit Name] AS [If allocated, coming from BA/GF]
,MasterTableT.[Request Comments]
,[General:RecruitmentStatusT].[Recruitment Status]
,MasterTableT.[Employee Name]
,MasterTableT.[Employee User ID Number]
,MasterTableT.[Employee SOFT ID]
,[General:LocationsT_1].Locations AS [Actual Location]
,MasterTableT.[Actual: Allocation (%)]
,MasterTableT.[Actual: Start date in the Programme]
,MasterTableT.[Agreed: End Date in the programme]
,DateDiff("m", MasterTableT ! [Actual: Start Date in the programme], MasterTableT ! [Agreed: End Date in the programme]) AS [Time remaining in the Programme]
,[General:ProfileTypeT_1].[Profile type] AS [Actual Profile Type]
,[General:HireTypeT_1].[Hire Type] AS [Actual Type of Hire]
,[General:BA/GF and UnitT_1].[BA/GF and Unit Name] AS [Actual BA/GF and Unit]
,[General:ProgrammePeopleT_1].[Full Name] AS [Recruitment Driver]
,[General:ProgrammePeopleT_2].[Full Name] AS [Recruitment Manager]
,[General:ProgrammePeopleT_2].[Company ID] AS [Recruitment Manager ID]
,[General:ProgrammePeopleT_2].[Cost Center] AS [Recruitment Manager Cost Center]
,MasterTableT.[HR Comments]
,MasterTableT.[NIIDS number]
,IIf(IsNull([Actual: Start date in the Programme]), [Expected: StartDate], [Actual: Start date in the Programme]) AS [Expected/Actual StartDate]
,IIf(IsNull([Agreed: End Date in the programme]), [Expected: EndDate], [Agreed: End Date in the programme]) AS [Expected/Agreed End Date]
,MasterTableT.[Expected Allocation %]
,MasterTableT.[Training: GSU Intro]
,[General:PmoOrgLevel3].OrgL3Name
,[General:PmoOrgLevel4].OrgL4Name
,MasterTableT.[PMO: Org Level 5]
,MasterTableT.[Prioritized Recruitment]
FROM (
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
MasterTableT LEFT JOIN [General:AgileTeamT] ON MasterTableT.[Team Name ID] = [General:AgileTeamT].[ID Agile Team]
) LEFT JOIN [General:BA/GF and UnitT] ON MasterTableT.[Coming from: BA/GF/External and unit ID] = [General:BA/GF and UnitT].[ID BA/GF and Unit]
) LEFT JOIN [General:BlockNameT] ON MasterTableT.[Block Name ID] = [General:BlockNameT].[ID Block]
) LEFT JOIN [General:DeliveryStreamT] ON MasterTableT.[Delivery Stream ID] = [General:DeliveryStreamT].[ID Delivery Stream]
) LEFT JOIN [General:TravelT] ON MasterTableT.[Expected: Travel ID] = [General:TravelT].[ID Travel]
) LEFT JOIN [General:HireTypeT] ON MasterTableT.[Expected: Hire Type ID] = [General:HireTypeT].[ID Hire Type]
) LEFT JOIN [General:LocationsT] ON MasterTableT.[Expected: Location ID] = [General:LocationsT].[ID Location]
) LEFT JOIN [General:CompanyProgrammeNameT] ON MasterTableT.[Company Programmes ID] = [General:CompanyProgrammeNameT].[ID Company Programmes]
) LEFT JOIN [General:Position/JobTitleT] ON MasterTableT.[Position/Job Title ID] = [General:Position/JobTitleT].[Position/Job title ID]
) LEFT JOIN [General:ProfileTypeT] ON MasterTableT.[Expected: Profile Type ID] = [General:ProfileTypeT].[ID Profile type]
) LEFT JOIN [General:ProgrammePeopleT] ON MasterTableT.[Functional Owner ID] = [General:ProgrammePeopleT].[ID Programme People]
) LEFT JOIN [General:RecruitmentStatusT] ON MasterTableT.[Recruitment Status ID] = [General:RecruitmentStatusT].[ID Recruitment Status]
) LEFT JOIN [General:LocationsT] AS [General:LocationsT_1] ON MasterTableT.[Actual: Location ID] = [General:LocationsT_1].[ID Location]
) LEFT JOIN [General:ProfileTypeT] AS [General:ProfileTypeT_1] ON MasterTableT.[Actual: Profile type ID] = [General:ProfileTypeT_1].[ID Profile type]
) LEFT JOIN [General:HireTypeT] AS [General:HireTypeT_1] ON MasterTableT.[Actual: type of Hire ID] = [General:HireTypeT_1].[ID Hire Type]
) LEFT JOIN [General:BA/GF and UnitT] AS [General:BA/GF and UnitT_1] ON MasterTableT.[Actual: BA/GF/External and Unit ID] = [General:BA/GF and UnitT_1].[ID BA/GF and Unit]
) LEFT JOIN [General:ProgrammePeopleT] AS [General:ProgrammePeopleT_1] ON MasterTableT.[Recruitment Driver ID] = [General:ProgrammePeopleT_1].[ID Programme People]
) LEFT JOIN [General:ProgrammePeopleT] AS [General:ProgrammePeopleT_2] ON MasterTableT.[Recruitment Manager ID] = [General:ProgrammePeopleT_2].[ID Programme People]
) LEFT JOIN [General:PmoOrgLevel3] ON MasterTableT.[PMO: Org Level 3] = [General:PmoOrgLevel3].OrgL3ID
)
LEFT JOIN [General:PmoOrgLevel4] ON MasterTableT.[PMO: Org Level 4] = [General:PmoOrgLevel4].OrgL4ID
WHERE (((MasterTableT.ID) < 10000)); // <-- and this condition is my a query booster
这个查询不是我的,我刚从别人那里继承:) 没有任何与MSSQL Server相关的表...都在MS Access数据库文件中。
提前感谢您的解释。
答案 0 :(得分:2)
添加额外条件时,它可能会获得不同的执行路径。要查看执行计划,您可以enable it。在不知道查询的情况下,我想添加id会改变表连接方式的顺序,而不是先加入一些表,然后将其连接到带有id的表,该过程以不同的顺序完成,其中第一个连接只传递一个几张唱片而不是整张桌子。