AP 14 - Avoid implicit cross join

Severity

Warning Warning

Type

Readability

Correctness

Problem

It is possible to generate a cartesian product using CROSS JOINs. However, you should avoid writing implicit CROSS JOINS with the ANSI-89 syntax.

SELECT t1.col1
      ,t2.col1
  FROM t1
      ,t2

Tables t1 and t2 are cross joined implicitly without specifying the CROSS JOIN clause.

By using the implicit CROSS JOIN syntax you run the risk of creating cartesian products by accident. This can be catastrophic for query performance and might even crash your database.

Solution

Follow the ANSI-92 SQL syntax when writing explicit CROSS JOINs by using the CROSS JOIN syntax.

SELECT t1.col1
      ,t2.col1
  FROM t1
 CROSS
  JOIN t2

Legitimate use of the anti pattern

Never use the implicit CROSS JOIN syntax