Class: ActiveRecord::Materialized::AggregateAnalysis
- Inherits:
-
Object
- Object
- ActiveRecord::Materialized::AggregateAnalysis
- Defined in:
- lib/activerecord/materialized/aggregate_analysis.rb
Overview
Decides whether a view can be maintained by applying signed deltas (summary-delta IVM) instead of re-aggregating a partition's base rows. True only for a single-table GROUP BY without HAVING whose aggregates are all distributive (SUM/COUNT/COUNT(*)) and which carries a trustworthy row count so emptied partitions can be detected; everything else falls back to scoped recompute, which is always correct.
Defined Under Namespace
Classes: Column
Instance Method Summary collapse
- #aggregate_columns ⇒ Object
- #delta_maintainable? ⇒ Boolean
- #distributive_aggregates? ⇒ Boolean
-
#initialize(relation) ⇒ AggregateAnalysis
constructor
A new instance of AggregateAnalysis.
- #row_count_column ⇒ Object
Constructor Details
#initialize(relation) ⇒ AggregateAnalysis
Returns a new instance of AggregateAnalysis.
19 20 21 22 |
# File 'lib/activerecord/materialized/aggregate_analysis.rb', line 19 def initialize(relation) @relation = relation @aggregate_columns = nil end |
Instance Method Details
#aggregate_columns ⇒ Object
24 25 26 |
# File 'lib/activerecord/materialized/aggregate_analysis.rb', line 24 def aggregate_columns @aggregate_columns ||= @relation.select_values.filter_map { |value| classify(value) } end |
#delta_maintainable? ⇒ Boolean
28 29 30 |
# File 'lib/activerecord/materialized/aggregate_analysis.rb', line 28 def delta_maintainable? single_table? && grouped? && !having? && distributive_aggregates? && aggregate_columns.any?(&:counts_rows) end |
#distributive_aggregates? ⇒ Boolean
32 33 34 |
# File 'lib/activerecord/materialized/aggregate_analysis.rb', line 32 def distributive_aggregates? aggregate_columns.any? && aggregate_columns.all? { |column| distributive?(column) } end |
#row_count_column ⇒ Object
36 37 38 |
# File 'lib/activerecord/materialized/aggregate_analysis.rb', line 36 def row_count_column aggregate_columns.find(&:counts_rows) end |