union 与 union all 的表现 [英] performance of union versus union all
问题描述
我必须在多个表中运行一个 select 语句.我确信这些表返回不同的记录.无论如何,我都在使用 UNION ALL.
I have to run a select statement across several tables. I am sure the tables return different records. I am anyway using UNION ALL.
当我确定表返回不同的记录时,在性能方面使用 UNION 还是 UNION ALL 更好?
Is it better to use UNION or of UNION ALL in performance terms when I am sure the tables return different records?
推荐答案
当您不担心消除重复记录时,UNION ALL 的性能将比 UNION 更好,因为您避免了昂贵的 不同排序 操作.参见:SQL SERVER – Union 与 Union All 的区别 – 最佳性能比较
UNION ALL will perform better than UNION when you're not concerned about eliminating duplicate records because you're avoiding an expensive distinct sort operation. See: SQL SERVER – Difference Between Union vs. Union All – Optimal Performance Comparison
这篇关于union 与 union all 的表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!