class NoSE::Plans::PlanStep
A single step in a statement plan
Attributes
children[R]
cost[R]
fields[R]
parent[RW]
state[RW]
Public Class Methods
inherited(child_class)
click to toggle source
Add the Subtype
module to all step classes @return [void]
# File lib/nose/plans.rb, line 82 def self.inherited(child_class) child_class.send(:include, Subtype) end
new()
click to toggle source
# File lib/nose/plans.rb, line 13 def initialize @children = Set.new @parent = nil @fields = Set.new end
Public Instance Methods
add_fields_from_index(index)
click to toggle source
Mark the fields in this index as fetched @return [void]
# File lib/nose/plans.rb, line 42 def add_fields_from_index(index) @fields += index.all_fields end
calculate_cost(cost_model)
click to toggle source
Calculate the cost of executing this step in the plan @return [Integer]
# File lib/nose/plans.rb, line 76 def calculate_cost(cost_model) @cost = cost_model.method((subtype_name + '_cost').to_sym).call self end
children=(children)
click to toggle source
Set the children of the current plan step @return [void]
# File lib/nose/plans.rb, line 29 def children=(children) @children = children.to_set # Track the parent step of each step children.each do |child| child.instance_variable_set(:@parent, self) fields = child.instance_variable_get(:@fields) + self.fields child.instance_variable_set(:@fields, fields) end end
parent_index()
click to toggle source
Find the closest index to this step @return [PlanStep]
# File lib/nose/plans.rb, line 67 def parent_index step = parent_steps.to_a.reverse_each.find do |parent_step| parent_step.is_a? IndexLookupPlanStep end step.index unless step.nil? end
parent_steps(cost_model = nil)
click to toggle source
Get the list of steps which led us here If a cost model is not provided, statement plans using this step cannot be evaluated on the basis of cost
(this is to support PlanStep#parent_index
which does not need cost) @return [QueryPlan]
# File lib/nose/plans.rb, line 52 def parent_steps(cost_model = nil) steps = nil if @parent.nil? steps = QueryPlan.new state.query, cost_model else steps = @parent.parent_steps cost_model steps << self end steps end
to_color()
click to toggle source
:nocov:
# File lib/nose/plans.rb, line 20 def to_color # Split on capital letters and remove the last two parts (PlanStep) self.class.name.split('::').last.split(/(?=[A-Z])/)[0..-3] \ .map(&:downcase).join(' ').capitalize end