Class: Benedictus::Heuristics::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/benedictus/heuristics/registry.rb

Constant Summary collapse

DEFAULT_HEURISTICS =
[
  SeqScanOnLargeTable,
  RowEstimateDrift,
  ExternalSort,
  NestedLoopBlowup,
  ExpensivePerRowScan
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(heuristics = nil, config: {}) ⇒ Registry

Returns a new instance of Registry.



14
15
16
17
# File 'lib/benedictus/heuristics/registry.rb', line 14

def initialize(heuristics = nil, config: {})
  source = heuristics || DEFAULT_HEURISTICS
  @heuristics = source.map { |h| instantiate(h, config) }
end

Class Method Details

.annotate(tree, config: {}) ⇒ Object



28
29
30
# File 'lib/benedictus/heuristics/registry.rb', line 28

def self.annotate(tree, config: {})
  new(config: config).annotate(tree)
end

Instance Method Details

#annotate(tree) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/benedictus/heuristics/registry.rb', line 19

def annotate(tree)
  tree.each_node do |node|
    @heuristics.each do |heuristic|
      node.warnings.concat(heuristic.apply(node))
    end
  end
  tree
end