Class: PgCanary::Rules::UnionInsteadOfUnionAll
- Defined in:
- lib/pg_canary/rules/definitions/union_instead_of_union_all.rb
Overview
UNION without ALL deduplicates the combined result by sorting/hashing all rows. When the branches cannot overlap (or duplicates are acceptable), UNION ALL skips that work. Whether deduplication is intended is the author's call, hence opt-in.
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
12 13 14 15 16 17 18 19 20 |
# File 'lib/pg_canary/rules/definitions/union_instead_of_union_all.rb', line 12 def check union = scopes.find { |scope| scope.stmt.op == :SETOP_UNION && !scope.stmt.all } return [] unless union [detection( message: "UNION (without ALL) sorts/hashes the entire combined result to remove duplicates.", suggestion: "If the branches cannot produce overlapping rows — or duplicates are acceptable — use UNION ALL." )] end |