У меня есть этот запрос .. 214 Выполнение / мин, 44.42 Ср ЦП (мс) есть способ сделать это намного быстрее
SELECT P.Id id0,
P.ProgramId ProgramId1,
P.ProgramName ProgramName2,
P.ProgramLevel ProgramLevel3,
P.Department Department4,
P.Track Track5,
P.AcademicYear AcademicYear6,
P.StartTerm StartTerm7,
P.Delivery Delivery8,
P.Fee Fee9,
P.City City10,
P.STATE State11,
P.StartDate StartDate12,
P.Deadline Deadline13,
P.DeadlineDisplay DeadlineDisplay14,
P.ProgramType ProgramType15,
O.Id as OrganizationId16,
O.NAME OrganizationName17,
P.ApplicationType ApplicationType18,
P.Concentration Concentration19,
P.ZipCode ZipCode20,
P.Campus Campus21,
P.WADisplayName WADisplayName22,
P.UpdatedDate updateDate23,
AF.Id InstanceId24,
RD.Id stateId33
INTO #TempGetFullProgramSelectionInfo
FROM unicas_config..applicationForm AF
INNER JOIN UNICAS_CONFIG.. AcademicInstitution AI
ON AF.casid=AI.casid
INNER JOIN UNICAS_CONFIG..Organization O
ON O.academicInstitutionid=AI.id
INNER JOIN UNICAS_CONFIG..AssociationOrg asOrg
ON asOrg.FormId=AF.id
INNER JOIN UNICAS_CONFIG..Program P
ON P.AssociationOrgId=asOrg.Id and asOrg.OrganizationId=O.id AND AF.Id = 6286
INNER JOIN unicas_config..ReferenceData RD
ON P.STATE = RD.ValueId AND RD.ValueAbbr ='US'
INNER JOIN unicas_config..ReferenceDataSet RS
ON RD.ReferenceSetId = RS.SetId AND RS.NAME = 'LK_States'
Теперь это, если я разделю на 2 запроса
select RD.ValueId, RD.id into #temp1
from unicas_config..ReferenceData RD
INNER JOIN unicas_config..ReferenceDataSet RS ON RD.ReferenceSetId= RS.SetId AND RS.NAME= 'LK_States'
where RD.ValueAbbr='US';
SELECT P.Id id0,
P.ProgramId ProgramId1,
P.ProgramName ProgramName2,
P.ProgramLevel ProgramLevel3,
P.Department Department4,
P.Track Track5,
P.AcademicYear AcademicYear6,
P.StartTerm StartTerm7,
P.Delivery Delivery8,
P.Fee Fee9,
P.City City10,
P.STATE State11,
P.StartDate StartDate12,
P.Deadline Deadline13,
P.DeadlineDisplay DeadlineDisplay14,
P.ProgramType ProgramType15,
O.Id as OrganizationId16,
O.NAME OrganizationName17,
P.ApplicationType ApplicationType18,
P.Concentration Concentration19,
P.ZipCode ZipCode20,
P.Campus Campus21,
P.WADisplayName WADisplayName22,
P.UpdatedDate updateDate23,
AF.Id InstanceId24,
RD.Id stateId33
INTO #TempGetFullProgramSelectionInfo
FROM unicas_config..applicationForm AF
INNER JOIN UNICAS_CONFIG.. AcademicInstitution AI
ON AF.casid=AI.casid
INNER JOIN UNICAS_CONFIG..Organization O
ON O.academicInstitutionid=AI.id
INNER JOIN UNICAS_CONFIG..AssociationOrg asOrg
ON asOrg.FormId=AF.id
INNER JOIN UNICAS_CONFIG..Program P
ON P.AssociationOrgId=asOrg.Id and asOrg.OrganizationId=O.id AND AF.Id = 6286
INNER JOIN #temp1 RD ON P.STATE= RD.ValueId;
используя запрос, рекомендованный Фрисби
Использование Hash join