82 lines
2.1 KiB
Plaintext
82 lines
2.1 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Conditions in the `WHERE` clause that either reinforce or contradict the definitions of their columns are redundant, as they are always either unconditionally true or unconditionally false. For example, including `AND column IS NOT NULL` is unnecessary if the column is already defined as non-null.
|
|
|
|
include::../../../shared_content/plsql/data_dictionary.adoc[]
|
|
|
|
== How to fix it
|
|
|
|
Ensure that the conditions in the `WHERE` clause are not always true or false.
|
|
|
|
=== Code examples
|
|
|
|
Given the following table:
|
|
|
|
[source,sql]
|
|
----
|
|
CREATE TABLE Product
|
|
(
|
|
Id INT,
|
|
Name VARCHAR(6),
|
|
Price INT NOT NULL
|
|
)
|
|
----
|
|
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,sql,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
SELECT Name, Price FROM Product
|
|
WHERE
|
|
Name = 'Too long name' -- Noncompliant; always false. This column can contain only 6 characters
|
|
AND Price IS NOT NULL -- Noncompliant; always true. This column is NOT NULL
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,sql,diff-id=1,diff-type=compliant]
|
|
----
|
|
SELECT Name, Price FROM Product
|
|
WHERE
|
|
Name = 'Name'
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
* Based on the definition of "ccc", this condition is always ["TRUE"|"FALSE"].
|
|
* Based on the constraints on "ccc", this condition is always ["TRUE"|"FALSE"].
|
|
* Change this condition so that it does not always evaluate to ["TRUE"|"FALSE"].
|
|
|
|
|
|
=== Highlighting
|
|
|
|
problem condition
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== relates to: S2583
|
|
|
|
=== relates to: S3633
|
|
|
|
=== on 17 Jun 2016, 15:03:20 Ann Campbell wrote:
|
|
from \https://www.researchgate.net/publication/222432151_Semantic_errors_in_SQL_queries_A_quite_complete_list:
|
|
|
|
|
|
Error 27: Uncorrelated EXISTS-subqueries.If an EXISTS-subquery makes no reference to a tuple variable from theouter query, is is either globally true or globally false. This is a very unusualbehaviour. Actually, uncorrelated EXISTS-subqueries are simply missing joinconditions (possibly for anti-joins).
|
|
|
|
|
|
Not sure if we want to handle this here or in RSPEC-3647
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|