私は最近、クライアントのストアドプロシージャでいくつかのパフォーマンスチューニングを始めました。私はこのコードの断片にぶつかり、より効率的に動作させる方法を見つけることができませんでした。ストアドプロシージャで選択肢が多すぎますか?
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
これらのテーブルは、それらの中に単一の列を持っています....参加しないでください:\ –