32 lines
1.2 KiB
Plaintext
32 lines
1.2 KiB
Plaintext
``++UNION++`` is significantly less performant compared to ``++UNION ALL++`` because it removes duplicated entries and run an internal ``++DISTINCT++`` to achieve this.
|
|
|
|
|
|
``++UNION ALL++`` is not removing duplicates and returns all the results from the queries. It performs faster in most of the cases compared to ``++UNION++``. Nevertheless, the quantity of data returned by ``++UNION ALL++`` can be significantly more important than with ``++UNION++``. On slow network, the performance gain to use ``++UNION ALL++`` instead of ``++UNION++`` can be challenged by the time lost to transfer more data than with ``++UNION++``.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,sql]
|
|
----
|
|
-- if you care about not having duplicated entries, then UNION is the good choice
|
|
SELECT EMAIL FROM EMPLOYEES UNION SELECT EMAIL FROM CUSTOMERS
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,sql]
|
|
----
|
|
-- if you don't care about duplicated entries in the results of this UNION, then UNION ALL should be preferred
|
|
SELECT EMAIL FROM EMPLOYEES UNION ALL SELECT EMAIL FROM CUSTOMERS
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|