JOINからmjnEmployeeDepartmentを除いて同じ2つのクエリがあります。最初のクエリはLEFT OUTER JOINを使用し、2番目のクエリはINNER JOINを使用します。どちらも同じデータを返しますが、INNER JOINの実行には4.5分かかりますが、LEFT OUTER JOINの実行には4秒かかります。誰でもここで起こっていることを示唆することはできますか?内部結合がクエリのパフォーマンスを無効にします
私はSMS 2017のコードをSQL 2012データベースに対して実行しています。
Select
Count(*) --23878 00:00:00
From
dbo.mjnEmployee as e
Inner Join dbo.mjnEmployeeStatus as s
on e.EmployeeID = s.EmployeeID
Inner Join dbo.mjnEmployeeEmploymentInfo as RankNo
On e.EmployeeId = RankNo.EmployeeID
Inner Join dbo.mjnEmployeeOfficeAssociation as Office
On e.EmployeeId = Office.EmployeeID
Inner Join dbo.mjnEmployeeEmploymentInfo as TrackNo
On e.EmployeeId = TrackNo.EmployeeID
Inner Join dbo.mjnEmployeeUnit as Unit
on e.EmployeeID = Unit.EmployeeID
And Unit.Iteration = 1
Left Outer Join dbo.mjnEmployeeDepartment as Department
on e.EmployeeID = Department.EmployeeID
Left Outer Join dbo.mjnEmployeeAssociation as Supervisor
On e.EmployeeId = Supervisor.ObjectEmployeeId
and Supervisor.EmployeeAssociationType = 2
Left Outer Join dbo.mjnEmployeeAssociation as Manager
On Manager.ObjectEmployeeId = e.EmployeeId
and Manager.EmployeeAssociationType = 1
Left Outer Join dbo.mjnEmployeeAssociation as Assistant
On e.EmployeeId = Assistant.ObjectEmployeeId
and Assistant.EmployeeAssociationType = 3
Left Outer Join dbo.mjnEmployeeAssociation as Advisor
On e.EmployeeId = Advisor.ObjectEmployeeId
and Advisor.EmployeeAssociationType = 4
Select
Count(*) --23878 00:04:37
From
dbo.mjnEmployee as e
Inner Join dbo.mjnEmployeeStatus as s
on e.EmployeeID = s.EmployeeID
Inner Join dbo.mjnEmployeeEmploymentInfo as RankNo
On e.EmployeeId = RankNo.EmployeeID
Inner Join dbo.mjnEmployeeOfficeAssociation as Office
On e.EmployeeId = Office.EmployeeID
Inner Join dbo.mjnEmployeeEmploymentInfo as TrackNo
On e.EmployeeId = TrackNo.EmployeeID
Inner Join dbo.mjnEmployeeUnit as Unit
on e.EmployeeID = Unit.EmployeeID
And Unit.Iteration = 1
Inner Join dbo.mjnEmployeeDepartment as Department
on e.EmployeeID = Department.EmployeeID
Left Outer Join dbo.mjnEmployeeAssociation as Supervisor
On e.EmployeeId = Supervisor.ObjectEmployeeId
and Supervisor.EmployeeAssociationType = 2
Left Outer Join dbo.mjnEmployeeAssociation as Manager
On Manager.ObjectEmployeeId = e.EmployeeId
and Manager.EmployeeAssociationType = 1
Left Outer Join dbo.mjnEmployeeAssociation as Assistant
On e.EmployeeId = Assistant.ObjectEmployeeId
and Assistant.EmployeeAssociationType = 3
Left Outer Join dbo.mjnEmployeeAssociation as Advisor
On e.EmployeeId = Advisor.ObjectEmployeeId
and Advisor.EmployeeAssociationType = 4
私の最初の考えはインデックスの欠如です。 – duffymo
私もDuffyですが、インナー結合だけでなく、左の結合も欠けていませんか?また、私は実行計画を見てSMSは新しいインデックスを示唆していません。 –
ごくまれに[実際の実行計画を含める](https://stackoverflow.com/a/7359705/1260204)、[計画を貼り付ける](https://www.brentozar.com/pastetheplan)を使用することができます/)あなたの質問にリンクを共有してください。また、[あなた自身で読む](https://stackoverflow.com/a/759097/1260204)、おそらくあなたのクエリでパフォーマンスの問題を把握することができます。最後に、実行中のクエリとともに[schema DDL](https://en.wikipedia.org/wiki/Data_definition_language)を含めます。 – Igor