2012-02-06 3 views
1

테이블에 값을 반환하는보기가 있습니다. 이 프로세스는 오랜 시간이 걸립니다 ... 그래서 인덱싱을하면 더 잘 작동한다고 느낍니다. 아무도 날 볼 수있는 색인을 추가 가이드 plz 수 있습니다.클러스터 된/비 클러스터형 인덱스 만들기

ALTER View [dbo].[GetApplicationBudgetAndUtilized] 
as 

Select *, (convert(money,isnull(TotalBudget,0)) - convert(money,isnull(Utilized,0))) as [Left] from (
SELECT Distinct PM.PKID AS ProgramID, F.PKID as FundID, I.PKID as ProjectID, 
MYB.PKID AS MultiYearBudgetID, 
(Select Isnull(Sum(IsNull(PBC1.BudgetAmount,0)),0) from ProgramBudgetConfiguration PBC1 
Where pbc1.MultiYearBgtIdFkId = pbc.MultiYearBgtIdFkId and PBC1.IsActive = 1 and LOVBudgetTypeIDFKID = 'BT_INC' group 
by pbc1.MultiYearBgtIdFkId) AS TotalProgramBudget, 
App.TotalBudget, 
I.PKID, 

(Case when exists (Select 'x' from InstallationTransactionHeader Where ParentPrjNumber = I.PKID and IsDelete = 0) 
then 
(case 
when not exists (select cast(isnull(I1.CustInstallIncAmt,0.00) + isnull(I1.SPInstIncentiveAmt,0.00) + isnull(I1.ThirdPartyIncentive,0.00) as Money) 
from InstallationTransactionHeader I1 where I1.ParentPrjNumber is not null and I1.StatusFKID in ('ITS_SUB','ITS_APP','ITS_VRF') and 
I1.ParentPrjNumber = I.PKID and I1.FundRequestIDFKID is not null) then (select '0') 
else 
(select isnull(sum(cast(isnull(I1.CustInstallIncAmt,0.00) + isnull(I1.SPInstIncentiveAmt,0.00) + isnull(I1.ThirdPartyIncentive,0.00) as Money)),0) 
from InstallationTransactionheader I1 where I1.StatusFKID in ('ITS_SUB','ITS_APP','ITS_VRF') and I1.ParentPrjNumber is not null and 
I1.ParentPrjNumber = I.PKID and I1.isdelete = 0 and I1.FundRequestIDFKID is not null group by I1.parentPrjNumber) 
End) 
else 
--isnull(cast(isnull(I.CustInstallIncAmt,0.00) + isnull(I.SPInstIncentiveAmt,0.00) + isnull(I.ThirdPartyIncentive,0.00) as Money),0) 
(case 
when not exists (select isnull(cast(isnull(I.CustInstallIncAmt,0.00) + isnull(I.SPInstIncentiveAmt,0.00) + isnull(I.ThirdPartyIncentive,0.00) as Money),0) from 
InstallationTransactionHeader I where StatusFKID in ('ITS_SUB','ITS_APP','ITS_VRF') and IsDelete = 0 and 
PKID = I.PKID and I.FundRequestIDFKID is not null) then 0--(select '0') 
else 
(select isnull(sum(cast(isnull(I1.CustInstallIncAmt,0.00) + isnull(I1.SPInstIncentiveAmt,0.00) + isnull(I1.ThirdPartyIncentive,0.00) as Money)),0) 
from InstallationTransactionheader I1 where I1.StatusFKID in ('ITS_SUB','ITS_APP','ITS_VRF') and IsDelete = 0 and I1.FundRequestIDFKID is not null and 
PKID = I.PKID) 
End) 
End) as Utilized 

--Cast(App.TotalBudget - (isnull(I.CustInstallIncAmt,0.00) + isnull(I.SPInstIncentiveAmt,0.00) + isnull(I.ThirdPartyIncentive,0.00)) as Money) as [Left] 
FROM 
(SELECT PKID as FundID, ProgramID AS ProgramID, (ISNULL(IncentiveAmount,0.00) + ISNULL(CustInstallIncAmt, 0.00) + ISNULL(SPInstIncentiveAmt, 0.00)) AS TotalBudget 
FROM dbo.FundRequestHeader AS F WHERE (IsDelete = 0) AND (IsActive = 1) AND (StatusFKID in ('IAS_APP','IAS_CAN'))) AS App 
INNER JOIN dbo.ProgramMaster AS PM 
INNER JOIN dbo.MultiYearBudget AS MYB ON PM.PKID = MYB.ProgramIDFKID 
INNER JOIN dbo.ProgramBudgetConfiguration AS PBC ON MYB.PKID = PBC.MultiYearBgtIdFkId ON App.ProgramID = PM.PKID 
INNER JOIN dbo.FundRequestHeader AS F ON F.PKID = App.FundID 
INNER JOIN dbo.InstallationTransactionHeader AS I ON I.FundRequestIDFKID = F.PKID 
WHERE (PM.IsActive = 1) AND (MYB.IsActive = 1) AND (PBC.IsActive = 1) AND 
(PBC.LOVBudgetTypeIDFKID = 'BT_INC') And (F.StatusFKID in ('IAS_APP','IAS_CAN')) 
--and (1=case when(select ProgramTypeIDFKID from InstallationTransactionHEader where ProgramTypeIDFKID='IT_PRE' and ParentPrjNumber is null and PaymentSchedule=1)='IT_PRE' then 0 else 1 end) 
--and I.ProgramTypeIDFKID <> 'IT_PRE' or I.PaymentSchedule = 0 or (I.ProgramTypeIDFKID = 'IT_PRE' and I.PaymentSchedule = 1 and I.ParentPrjNumber is not null) 
and MYB.PKID = F.BudgetPeriodID and ((MYB.IsActive = 1))-- or ((MYB.status = 0) and F.StatusFKID ='IAS_APP')) 
and (MYB.Status = 1 or (MYB.Status =(case when exists(select M.status from MultiYearBudget M, FundRequestHeader F 
where F.ProgramID=M.ProgramIDFKID and F.ProgramTypeIDFKID <>'IT_FCFS' and M.Pkid=F.BudgetPeriodID 
and F.StatusFKID='IAS_APP' and F.ProgramID=PM.PKID and M.Status=0)then 0 else 1 end)) 

) 
)temp 

GO 

답변

0

인덱싱 된 뷰는 경우 limitations

특정, 내가 바로 그래서이 기사를 읽고 몇 가지 차단제를

  • SELECT *
  • 파생 테이블

을 볼 수 있고, 당신이 얼마나 멀리 있는지보십시오 ...

그러나, 당신은 당신이

내가 문서를 볼 수 없습니다입니다
+0

... 그것은 일부 웹 페이지의 문제를 보여주는 것 기지 테이블에 인덱스를 추가 할 수있는 실행 계획이 병목 현상을 식별 볼 수있을 것입니다 ... 수 u plz가 나를 더 인도합니다 ... – Prakash

+0

@Prakash : 링크를 수정했습니다 – gbn

+0

U ... 고맙습니다. 지금 읽었습니다. 나는 그것을 읽었고 어떤 도로 블록과 마주 치면 알려줍니다. – Prakash

관련 문제