この SQL サーバー クエリの調整を手伝ってください。これがテーブルvcompanyquicksearch
上のビューです。company
どのインデックスを作成する必要がありますか? 24% のコストがかかる実行計画でソート操作が行われています。つまり、
[CCEP_DEV].[dbo].[Company].vchContactFirstName Descending,
[CCEP_DEV].[dbo].[Company].iCompanyId Ascending
2回目の選別が行われている理由がわかりません...誰かが理由を提案できますか?
select top *
from vCompanyquicksearch
LEFT OUTER JOIN ReferenceParameters r1
on vCompanyquicksearch.iCompanyTypeCode = r1.iParameterId AND
r1.iSiteId =1
LEFT OUTER JOIN ReferenceParameters r2
on vCompanyquicksearch.iCompanySubTypeCode = r2.iParameterId AND
r2.iSiteId =1
LEFT OUTER JOIN ReferenceParameters r3
on vCompanyquicksearch.iPhoneTypeId = r3.iParameterId AND
r3.iSiteId =1
LEFT OUTER JOIN Country c ON
vCompanyquicksearch.chCountryCode = c.chCountryCode AND
ISNULL(vCompanyquicksearch.chCountryCode,'''') <> '''' and
c.iSiteId = 1
LEFT OUTER JOIN Region r ON
vCompanyquicksearch.chCountryCode = r.chCountryCode AND
ISNULL(vCompanyquicksearch.chCountryCode,'''') <> '''' AND
vCompanyquicksearch.chRegionCode = r.chRegionCode AND
ISNULL(vCompanyquicksearch.chRegionCode,'''') <> '''' and
r.iSiteId = 1
where vCompanyquicksearch.isiteid = 1 and vCompanyquicksearch.tirecordstatus = 1 and vCompanyquicksearch.iCompanyId in (
select distinct * from (
select customer_id from csu_customer_policy
inner join csu_policy on csu_policy.policy_number = csu_customer_policy.policy_number
and csu_policy.data_source = csu_customer_policy.data_source
where csu_policy.vehicle_no in(
'sgv3976r')
and csu_customer_policy.delete_status = 0 and csu_customer_policy.site_id = ' 1 '
) yTable
) Order by vchName desc