|
数据库表StockInOutDtl有10万条记录,我在存储过程中执行下列语句只用了1秒:
insert into @tmpStock
SELECT B.ArtID , B.ArtDesc , B.Units , -B.Qty as Qty , 0, A.ST
From StockInOut A Left Outer Join StockInOutDtl B
On A.SheetID=B.SheetID
Inner Join RefArtList C On B.ArtID=C.ArtID
Where A.IssueDate>=@RenewDate
And B.ArtID=@ArtID
但没有"Inner Join RefArtList C On B.ArtID=C.ArtID"一行,即下列语句却要9秒:
insert into @tmpStock
SELECT B.ArtID , B.ArtDesc , B.Units , -B.Qty as Qty , 0, A.ST
From StockInOut A Left Outer Join StockInOutDtl B
On A.SheetID=B.SheetID
Where A.IssueDate>=@RenewDate
And B.ArtID=@ArtID |
|