mardi 17 février 2015

Does SQL Server cache scalar function results when used simultaneously in SELECT, WHERE and GROUP BY?


Vote count:

0




Consider this contrived example:



SELECT
Foo,
dbo.ExpensiveScalarFunction( Bar ),
COUNT(*)
FROM
Source
WHERE
dbo.ExpensiveScalarFunction( Bar ) <> 'abc'
GROUP BY
Foo,
dbo.ExpensiveScalarFunction( Bar )
HAVING
dbo.ExpensiveScalarFunction( Bar ) > 'abd'


Would ExpensiveScalarFunction be evaluated 4 times for each row, or only once? Is SQL Server able to identify that the function is deterministic and optimize for that case?



asked 21 secs ago

Dai

28.3k






Does SQL Server cache scalar function results when used simultaneously in SELECT, WHERE and GROUP BY?

Aucun commentaire:

Enregistrer un commentaire