Class: PgCanary::Rules::UnindexedJoin
- Includes:
- IndexPredicates
- Defined in:
- lib/pg_canary/rules/definitions/unindexed_join.rb
Overview
Tier 2 (opt-in): join-condition columns with no index leading with them. Unlike active_record_doctor's static association check, this looks at joins that actually ran, so raw-SQL joins are covered too.
Constant Summary
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
15 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/unindexed_join.rb', line 15 def check(query) detections = [] query.each_scope do |scope| join_columns(scope).each do |table, column| next unless applicable_table?(query, table) next if index_leading_with?(query, table, column) detections << detection( query, table: table, columns: column, message: "Join condition on #{table}.#{column} has no index leading with it — " \ "joins on unindexed columns degrade as the tables grow.", suggestion: <<~SUGGESTION.chomp Consider indexing the join column: CREATE INDEX index_#{table}_on_#{column} ON #{table} (#{column}); SUGGESTION ) end end detections end |
#default_enabled ⇒ Object
11 12 13 |
# File 'lib/pg_canary/rules/definitions/unindexed_join.rb', line 11 def default_enabled false end |