Class: PgCanary::Rules::UnindexedWhere

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

Overview

Tier 2 (opt-in): equality/range predicates on columns with no index whose leading column could serve them. Depends on production table size — a 30-row lookup table is fine without indexes — hence disabled by default.

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



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

def check(query)
  query.each_scope.with_object([]) do |scope, detections|
    next unless scope.where_clause

    predicate_columns(query, scope).each do |table, columns|
      next unless applicable_table?(query, table)
      next if served_by_index?(query, table, columns)

      detections << build(query, table, columns)
    end
  end
end

#default_enabledObject



10
11
12
# File 'lib/pg_canary/rules/definitions/unindexed_where.rb', line 10

def default_enabled
  false
end