Class: PgCanary::Rules::ImplicitCast
- Defined in:
- lib/pg_canary/rules/definitions/implicit_cast.rb
Overview
Comparing an integer-family column with a numeric/float literal (age = 1.5) makes PostgreSQL cast the column to numeric, which disables its index. Restricted to cases provable from the AST alone.
Constant Summary collapse
- INTEGER_TYPES =
%w[smallint integer bigint].freeze
- NUMERIC_TYPE_NAMES =
%w[numeric decimal float4 float8].freeze
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
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pg_canary/rules/definitions/implicit_cast.rb', line 16 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) && comparison_expr?(node) detections << inspect_comparison(query, scope, node) end end detections.compact end |
#default_enabled ⇒ Object
9 10 11 |
# File 'lib/pg_canary/rules/definitions/implicit_cast.rb', line 9 def default_enabled true end |