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

Instance Method Summary collapse

Methods inherited from Base

all, check, default_enabled, enabled?, #initialize, option, options, rule_name

Constructor Details

This class inherits a constructor from PgCanary::Rules::Base

Instance Method Details

#checkObject



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
  detections = []
  each_scope do |scope|
    next unless scope.where_clause

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