스레드가 오래되었음을 알고 동일한 질문을 받았으며 테스트를 수행했으며 그 결과는 다음과 같습니다.
TestFunction이 독립적으로 실행될 경우 105를 반환하는 동안 FacCurrencyRate = 14264로 기록됩니다.
SELECT F.*, x.CurrencyKey, x.CurrencyName
FROM (
SELECT CurrencyKey, CurrencyName FROM dbo.TestFunction()
) x
INNER JOIN [dbo].[FactCurrencyRate] F ON x.CurrencyKey = f.CurrencyKey;
실행 시간은 ...
(14264 rows affected)
Table 'FactCurrencyRate'. Scan count 1, logical reads 75, physical reads 1, read-ahead reads 73, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'DimCurrency'. Scan count 1, logical reads 2, physical reads 1, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 31 ms, elapsed time = 749 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
제안 된 답변을 다음과 같이 사용하면 ...
select F.*, x.CurrencyKey, x.CurrencyName from [dbo].[FactCurrencyRate] F
cross apply dbo.TestFunction() x
실행 시간과 결과 개수는 ...
(1497720 rows affected)
Table 'FactCurrencyRate'. Scan count 1, logical reads 75, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Worktable'. Scan count 1, logical reads 38110, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'DimCurrency'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 2106 ms, elapsed time = 43242 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
여기서 볼 수있는 것은 내부 쿼리가보다 정확한 결과 집합을 제공하고 실행 시간이 훨씬 효율적이라는 것입니다. 더 나은 접근 방법으로 저를 수정하십시오!