最大5分で実行される以下のSQLステートメントがあります。結合を追加すると、タイムアウトになるまでsqlステートメントが実行されます。SQLステートメントに追加するとなぜこれが発生するのか教えていただけませんか?これらは、ベースSQLに追加した結合です。
このステートメントをベースSQLに追加しました
inner join ahsrelate.dbo.ahs_encounter ahs_encounter_1
on AHS_Encounter_1.PatientID=AHS_Patient.ID
またはこのステートメントをベースSQLに追加しました
inner join AHS_Medication
on ahs_medication.patientid=AHS_Patient.ID
ベースSQL
SELECT distinct
AHS_Patient.FullName,
AHS_Patient_Iorg.OrganizationMrn,
AHS_Patient.SexName,
AHS_Patient.DateOfBirth,
Finding1.NumericResult,
Finding2.NumericResult,
AHS_Problem.ICD9DiagnosisCode,
AHS_Encounter.EncounterDTTM,
AHS_Encounter.EncounterTypeName,
AHS_Result.EntryCode,
AHS_Result_1.EntryCode,
AHS_Result.NumericResult,
AHS_Result_1.NumericResult,
AHS_Result.ClinicalDTTM,
AHS_Result_1.ClinicalDTTM,
AHS_Provider.FullName,
AHS_Problem.Problem,
AHS_Problem.ProblemStatusName,
AHS_Encounter.ApptLocationName,
AHS_Encounter.AppointmentStatusName
FROM AHSRelate.dbo.AHS_Patient AHS_Patient
INNER JOIN AHSRelate.dbo.Finding1 Finding1
ON AHS_Patient.ID=Finding1.PatientID
AND Finding1.EntryMnemonic='BP SYS'
INNER JOIN AHSRelate.dbo.Finding2 Finding2
ON AHS_Patient.ID=Finding2.PatientID
AND Finding2.EntryMnemonic='BP DIAS'
INNER JOIN AHSRelate.dbo.AHS_Result AHS_Result
ON AHS_Patient.ID=AHS_Result.PatientID
AND AHS_Result.EntryCode IN ('D5353078', 'Q25015900')
INNER JOIN AHSRelate.dbo.AHS_Result AHS_Result_1
ON AHS_Patient.ID=AHS_Result_1.PatientID
AND AHS_Result_1.EntryCode IN ('D5353037', 'Q25003000')
INNER JOIN AHSRelate.dbo.AHS_Encounter AHS_Encounter
ON AHS_Encounter.PatientID=AHS_Patient.ID
AND AHS_Encounter.AppointmentStatusName='Pending'
AND AHS_Encounter.EncounterTypeName='Appointment'
and AHS_Encounter.EncounterDTTM >= getdate()-1
and AHS_Encounter.EncounterDTTM <= getdate()+1
INNER JOIN AHSRelate.dbo.AHS_Problem AHS_Problem
ON AHS_Patient.ID=AHS_Problem.PatientID
INNER JOIN AHSRelate.dbo.AHS_Patient_Iorg AHS_Patient_Iorg
ON AHS_Patient.ID=AHS_Patient_Iorg.PersonID
inner JOIN AHSRelate.dbo.AHS_Provider AHS_Provider
ON AHS_Encounter.Provider2ID=AHS_Provider.ID
ORDER BY
AHS_Patient.FullName,
AHS_Result.ClinicalDTTM DESC,
AHS_Result_1.ClinicalDTTM DESC