최근에 클라이언트의 저장 프로 시저에서 성능 튜닝을 시작했는데이 코드 조각에 부딪혀 더 효율적으로 작동 할 수있는 방법을 찾지 못했습니다.너무 많은 선택 사항을 사용하는 저장 프로 시저?
declare @StationListCount int;
select @StationListCount = count(*) from @StationList;
declare @FleetsCnt int;
select @FleetsCnt=COUNT(*) from @FleetIds;
declare @StationCnt int;
select @StationCnt=COUNT(*) from @StationIds;
declare @VehiclesCnt int;
select @VehiclesCnt=COUNT(*) from @VehicleIds;
declare @TrIds table(VehicleId bigint,TrId bigint,InRange bit);
insert into @TrIds(VehicleId,TrId,InRange)
select t.VehicleID,t.FuelTransactionId,1
from dbo.FuelTransaction t
join dbo.Fleet f on f.FleetID = t.FleetID and [email protected]
where t.TransactionTime>[email protected] and (@To is null or t.TransactionTime<@To)
and (@StationListCount=0 or exists (select id fRom @StationList where t.FuelStationID = ID))
and (@FleetsCnt=0 or exists (select ID from @FleetIds where ID = t.FleetID))
and (@StationCnt=0 or exists (select ID from @StationIds where ID = t.FuelStationID))
and (@VehiclesCnt=0 or exists (select ID from @VehicleIds where ID = t.VehicleID))
and t.VehicleID is not null
insert 명령은 전체 절차를 느리게하고 리소스의 99 %를 사용합니다.
I am not sure but i think these nested loops are referring to the queries inside the where clause
나는 매우 내가 이것에 얻을 수있는 도움을 주셔서 감사합니다.
감사합니다.
exists 절을 사용하는 대신 테이블 조인을 시도 했습니까? – Sharad
이 테이블들은 그들에 하나의 컬럼을 가지고 있습니다 .... 합류하지 마세요 : \ –