我正在努力提高查询的性能,发现一种奇怪的情况。
查询看起来像
SELECT
some_columns_and_conditions,
SUM(val_1/100) as "val_1",
SUM(val_2/100) as "val_2",
SUM(val_3/100) as "val_3",
SUM(val_4/100) as "val_4",
SUM(val_5/100) as "val_5"
FROM
tab_1 tb1
INNER JOIN
tab_2 tb2 ON (tb1.col = tb2.col)
INNER JOIN
(SELECT few_cols
FROM tab_3
WHERE ... ) tb3 ON (tb2.id = tb3.id)
few_more_inner_joins
WHERE
<filterings>
GROUP BY
some_columns_and_conditions
ORDER BY
columns
它起作用,大约需要15分钟。
该查询正在处理4个表:
查询产生大约3-4行。
我试图用临时表重写。第一次尝试将运行时间减少2倍:
drop table #tmp
select ...
into #tmp
from ...
select * from #tmp
不幸的是,这对我来说是不可接受的。我需要通过查询达到类似的结果。
您能帮我解决一些问题吗?