Class: PgCanary::Rules::CartesianJoin

Inherits:
Base
  • Object
show all
Defined in:
lib/pg_canary/rules/definitions/cartesian_join.rb

Overview

A JOIN with no join condition — an explicit CROSS JOIN between real tables, or a comma join whose WHERE clause never connects the tables — produces a cross product whose row count is the product of both sides.

Constant Summary

Constants included from PgQuerySupport

PgQuerySupport::COMPARISON_OPS

Instance Method Summary collapse

Methods inherited from Base

all, #enabled?, options, rule_name

Instance Method Details

#check(query) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pg_canary/rules/definitions/cartesian_join.rb', line 13

def check(query)
  detections = []
  query.each_scope do |scope|
    scope.stmt.from_clause.each do |item|
      each_join(unwrap_node(item)) do |join|
        detections << join_detection(query, join) if unconditioned?(join)
      end
    end
    detections << comma_detection(query, scope) if comma_cartesian?(scope)
  end
  detections
end

#default_enabledObject



9
10
11
# File 'lib/pg_canary/rules/definitions/cartesian_join.rb', line 9

def default_enabled
  true
end