rspec/rules/S4950/plsql/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

36 lines
1.3 KiB
Plaintext

== Why is this an issue?
``++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)
=== on 23 Oct 2018, 10:36:07 Alexandre Gigleux wrote:
Merged with RSPEC-1571 which was better described to cover the case of ``++UNION ALL++``.
endif::env-github,rspecator-view[]