성능 문제가 생겼습니다. 그래서 나는 나의 접근 방식이 무엇인지 확신 할 수 없다.해시 일치 오른쪽 외부 조인을 사용하여 SQL Server 성능 문제를 개선하는 방법
7 분 이상 걸리는 쿼리입니다.
INSERT INTO SubscriberToEncounterMapping(PatientEncounterID, InsuranceSubscriberID)
SELECT
PV.PatientVisitId AS PatientEncounterID,
InsSub.InsuranceSubscriberID
FROM
DB1.dbo.PatientVisit PV
JOIN
DB1.dbo.PatientVisitInsurance PVI ON PV.PatientVisitId = PVI.PatientVisitId
JOIN
DB1.dbo.PatientInsurance PatIns on PatIns.PatientInsuranceId = PVI.PatientInsuranceId
JOIN
DB1.dbo.PatientProfile PP On PP.PatientProfileId = PatIns.PatientProfileId
LEFT OUTER JOIN
DB1.dbo.Guarantor G ON PatIns.PatientProfileId = G.PatientProfileId
JOIN
Warehouse.dbo.InsuranceSubscriber InsSub ON InsSub.InsuranceCarriersID = PatIns.InsuranceCarriersId
AND InsSub.OrderForClaims = PatIns.OrderForClaims
AND ((InsSub.GuarantorID = G.GuarantorId) OR (InsSub.GuarantorID IS NULL AND G.GuarantorId IS NULL))
JOIN
Warehouse.dbo.Encounter E ON E.PatientEncounterID = PV.PatientVisitId
실행 계획은
해시 일치 오른쪽 외부 그 비용 89 % 쿼리의
에게 가입이 있음을 주장한다. 오른쪽 외부 없다
문제가 어디 내가 볼 수 없습니다 쿼리에 가입 할 수 있습니다.
첫째 :
Guarantor
에서 나는 당신이 ..... 또한 열 당신의'SELECT' 목록에서 사용하는'InsSub' 별칭을 사용 명세서에있는 테이블을 참조하지 않습니다 당신을 * 정말로이 두 가지 정보를 얻기 위해 모든 테이블에 가입해야합니까? –해시 일치의 세부 정보를 표시 할 수 있습니까? 프로브 란 무엇이며 출력은 무엇입니까? 스크린 샷에서 분명하지 않습니다. 나는이 술어가 당신의 이슈를 일으킨다 고 생각할 것이다 -'(InsSub.GuarantorID = G.GuarantorId) 또는 (InsSub.GuarantorID IS NULL과 G.GuarantorId가 NULL이다)', 당신은 두 개의 질의를 사용하고 결과를 결합하는 것을 고려할 수있다. 이처럼 OR 연산자를 사용하면 하위 최적화 계획이 생기고 두 개의 개별 쿼리가 인덱스를 더 잘 활용할 수 있습니다. – GarethD
@ GarethD 아마도 join에서 두 술어를 사용하는 대신 where 절에서 EXISTS를 사용합니까? – dfundako