Class: PgCanary::Rules::LeadingWildcardLike

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

Overview

LIKE / ILIKE with a leading wildcard ('%foo', '%foo%') cannot use a btree index regardless of table size. Only a pg_trgm GIN/GiST index helps, so we stay silent when one exists on the column. Bind parameters ($1) are resolved from the event's binds.

Constant Summary collapse

LIKE_KINDS =
%i[AEXPR_LIKE AEXPR_ILIKE].freeze

Constants included from IndexPredicates

IndexPredicates::TRGM_ACCESS_METHODS

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



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pg_canary/rules/definitions/leading_wildcard_like.rb', line 18

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

    walk_within_scope(scope.where_clause) do |node|
      detections << inspect_expr(query, scope, node) if like_expr?(node)
    end
  end
  detections.compact
end

#default_enabledObject



12
13
14
# File 'lib/pg_canary/rules/definitions/leading_wildcard_like.rb', line 12

def default_enabled
  true
end