我有下面的sql語句,最多5分鐘內運行。當我添加任何連接時,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
你正在使用哪些DBMS?你能附上解釋計劃嗎?你在加入的列上有索引嗎? – 2013-02-13 23:46:11
你在說什麼叫做性能調整。無論您使用的是什麼DBMS,都是一個龐大的主題,無法在解決stackoverflow問題的上下文中解決。您最好的辦法是發佈解釋或執行計劃,試圖讓我們確定您的查詢中存在哪些問題。 – 2013-02-13 23:48:18
我正在使用Microsoft SQL。我在所有連接上都有索引。我無法制定解釋計劃。 – QYT 2013-02-13 23:48:39