Hi,
I've got 2 table variables inside of an SQL 2000 function:
@tmpBigList(BItemID, BRank)
@tmpSmallList (ItemID, Rank)
The following UPDATE statement can run for a long time if @TmpTable1
has 500 rows and @TmpTable2 has 35,000 rows.
UDPATE @tmpBigList
SET BRank = t.Rank
FROM @tmpBigList
JOIN @tmpSmallList t on t.ItemID = BItemID
Looking at the Query Plan, you see that the INNER JOIN Of @tmpBigList
to @TmpSmallList results in 500 * 35,000 = 17,500,000 rows being
returned from @TmpSmallList. That takes a long time.
An index would help, but it appears that you can't add an index to a
table variable.
Changing to a temp table does not work since it's in a function.
Thanks,
Joe Landes