Class: PgCanary::Rules::ArraySearchWithoutGin
- Includes:
- IndexPredicates
- Defined in:
- lib/pg_canary/rules/definitions/array_search_without_gin.rb
Overview
Searching an array column (@>, <@, &&, or value = ANY(column)) without a GIN index scans every row.
Constant Summary collapse
- ARRAY_OPS =
%w[@> <@ &&].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
#check ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pg_canary/rules/definitions/array_search_without_gin.rb', line 16 def check detections = [] each_scope do |scope| next unless scope.where_clause scope.where_clause.walk_scope do |node| next unless node.is_a?(PgQuery::A_Expr) case node.kind when :AEXPR_OP operator = node.operator next unless ARRAY_OPS.include?(operator) detections << inspect_sides(scope, [node.lexpr, node.rexpr], operator) when :AEXPR_OP_ANY detections << inspect_sides(scope, [node.rexpr], "= ANY(column)") end end end detections.compact end |