Class: PgCanary::Rules::JsonbSearchWithoutGin
- Includes:
- IndexPredicates
- Defined in:
- lib/pg_canary/rules/definitions/jsonb_search_without_gin.rb
Overview
Searching a jsonb column in WHERE:
- containment/existence operators (@>, <@, ?, ?|, ?&) need a GIN index on the column
- key extraction (->> etc.) compared against a value needs a matching expression index
Constant Summary collapse
- CONTAINMENT_OPS =
%w[@> <@ ? ?| ?&].freeze
- EXTRACTION_OPS =
%w[-> ->> #> #>>].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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pg_canary/rules/definitions/jsonb_search_without_gin.rb', line 20 def check(query) detections = [] query.each_scope do |scope| next unless scope.where_clause walk_within_scope(scope.where_clause) do |node| next unless node.is_a?(PgQuery::A_Expr) && node.kind == :AEXPR_OP operator = operator_name(node) if CONTAINMENT_OPS.include?(operator) detections << inspect_containment(query, scope, node, operator) elsif EXTRACTION_OPS.include?(operator) detections << inspect_extraction(query, scope, node, operator) end end end detections.compact end |
#default_enabled ⇒ Object
13 14 15 |
# File 'lib/pg_canary/rules/definitions/jsonb_search_without_gin.rb', line 13 def default_enabled true end |