如何优化以下T-SQL的性能,以便只调用一次heavyFunctionCall函数。
在表变量、临时表、CTEsor中寻找最快的选项?
SQL:
select dbo.heavyFunctionCall(a, b, c)
from T
where dbo.heavyFunctionCall(a, b, c) > 10发布于 2015-02-24 12:00:09
这样做只会在每一行上运行一次函数,而不是两次:
SELECT *
FROM (
SELECT dbo.heavyFunctionCall(a, b, c) AS x
FROM T) a
WHERE x > 10发布于 2015-02-24 12:15:47
declare proc tst (@x int) -- set @x whatever you want.
-- the execution plan will be the same.
as
begin
SELECT *
FROM (
SELECT dbo.heavyFunctionCall(a, b, c) AS result
FROM T) resultx
WHERE result > @x
end发布于 2015-02-24 14:32:11
也许这是:
select hFC.result
from T
cross apply ( select dbo.heavyFunctionCall(T.a, T.b, T.c) result ) hFC
where hFC.result > 10https://stackoverflow.com/questions/28694968
复制相似问题