Class: ActiveRecord::Materialized::AggregateAnalysis
- Inherits:
-
Object
- Object
- ActiveRecord::Materialized::AggregateAnalysis
- Extended by:
- T::Sig
- 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.
26 27 28 29 |
# File 'lib/activerecord/materialized/aggregate_analysis.rb', line 26 def initialize(relation) @relation = relation @aggregate_columns = T.let(nil, T.nilable(T::Array[Column])) end |
Instance Method Details
#aggregate_columns ⇒ Object
32 33 34 |
# File 'lib/activerecord/materialized/aggregate_analysis.rb', line 32 def aggregate_columns @aggregate_columns ||= T.unsafe(@relation).select_values.filter_map { |value| classify(value) } end |
#delta_maintainable? ⇒ Boolean
37 38 39 |
# File 'lib/activerecord/materialized/aggregate_analysis.rb', line 37 def delta_maintainable? single_table? && grouped? && !having? && distributive_aggregates? && aggregate_columns.any?(&:counts_rows) end |
#distributive_aggregates? ⇒ Boolean
42 43 44 |
# File 'lib/activerecord/materialized/aggregate_analysis.rb', line 42 def distributive_aggregates? aggregate_columns.any? && aggregate_columns.all? { |column| distributive?(column) } end |
#row_count_column ⇒ Object
47 48 49 |
# File 'lib/activerecord/materialized/aggregate_analysis.rb', line 47 def row_count_column aggregate_columns.find(&:counts_rows) end |