为什么查询版本2这么快?
我怀疑DB Engine正在多次调用Table-Valued-Function“GetUsageStatistic”,所以有一种方法来告诉引擎“GetUsageStatistic”是确定性的,应该只调用一次?
查询版本1
--Takes ~10 minutes select * from RosterLevel r left join GetUsageStatistics( @mindate,@maxdate ) usage on r.UserID = usage.UserID;
查询版本2
--Takes ~10 seconds select * into #usage from GetUsageStatistics( @mindate,@maxdate ); select * from RosterLevel r left join #usage on r.UserID = #usage.UserID;