UNION 和 CONCATENATION 运算符在性能方面有什么区别?
What is the difference between the UNION and CONCATENATION operators in terms of performance?
有时,可以在Explain Plan中看到CONCATENATION这一步。
我想知道联合运算符和串联运算符在性能调优方面有什么区别?
UNION 必须删除重复项,这很昂贵。 CONCATENATION 是执行 UNION ALL 时发生的步骤(它不会删除重复项,因此更便宜)。
首先,UNION
和 CONCATENATION
略有不同。
CONCATENATION
等同于 UNION-ALL
。这结合了输入表和 returns 所有行。
UNION
组合输入表。然后 returns distinct 行。
所以UNION
比CONCATENATION
多了一个sort/distinct操作。这种影响有多大取决于你的数据集。
当优化器执行 OR 扩展时,您会看到 CONCATENATION
。但请注意,从 Oracle 数据库 12.2 开始,this has changed:
- CONCATENATION is replaced with UNION-ALL.
- Each UNION-ALL branch can be subject to further query transformations, if applicable. This is not possible with
CONCATENATION.
- Parallel queries can execute UNION-ALL branches concurrently. Again, this is not possible with CONCATENATION.
所以UNION-ALL
可以为下面的每一个操作想出更好的方案。并且 运行 这些相同(如果使用并行)。所以在很多情况下这会比 CONCATENATION
.
更快
有时,可以在Explain Plan中看到CONCATENATION这一步。
我想知道联合运算符和串联运算符在性能调优方面有什么区别?
UNION 必须删除重复项,这很昂贵。 CONCATENATION 是执行 UNION ALL 时发生的步骤(它不会删除重复项,因此更便宜)。
首先,UNION
和 CONCATENATION
略有不同。
CONCATENATION
等同于 UNION-ALL
。这结合了输入表和 returns 所有行。
UNION
组合输入表。然后 returns distinct 行。
所以UNION
比CONCATENATION
多了一个sort/distinct操作。这种影响有多大取决于你的数据集。
当优化器执行 OR 扩展时,您会看到 CONCATENATION
。但请注意,从 Oracle 数据库 12.2 开始,this has changed:
- CONCATENATION is replaced with UNION-ALL.
- Each UNION-ALL branch can be subject to further query transformations, if applicable. This is not possible with CONCATENATION.
- Parallel queries can execute UNION-ALL branches concurrently. Again, this is not possible with CONCATENATION.
所以UNION-ALL
可以为下面的每一个操作想出更好的方案。并且 运行 这些相同(如果使用并行)。所以在很多情况下这会比 CONCATENATION
.