Eu sei que o tópico é antigo, me fizeram a mesma pergunta, fiz um teste, o resultado da seguinte forma ...
Registros em FacCurrencyRate = 14264 enquanto TestFunction retorna 105 se executado independentemente.
SELECT F.*, x.CurrencyKey, x.CurrencyName
FROM (
SELECT CurrencyKey, CurrencyName FROM dbo.TestFunction()
) x
INNER JOIN [dbo].[FactCurrencyRate] F ON x.CurrencyKey = f.CurrencyKey;
O tempo de execução é ...
(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.
Se eu usar a resposta sugerida da seguinte maneira ...
select F.*, x.CurrencyKey, x.CurrencyName from [dbo].[FactCurrencyRate] F
cross apply dbo.TestFunction() x
O tempo de execução e a contagem de resultados são ...
(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.
O que vejo aqui é que a consulta interna traz um conjunto mais correto de resultados e o tempo de execução é muito mais eficiente. Corrija-me com uma abordagem melhor para realizar o mesmo!