Class: NoSE::Plans::PlanStep
- Includes:
- Supertype
- Defined in:
- lib/nose/plans.rb
Overview
A single step in a statement plan
Direct Known Subclasses
FilterPlanStep, IndexLookupPlanStep, LimitPlanStep, PrunedPlanStep, RootPlanStep, SortPlanStep, UpdatePlanStep
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#cost ⇒ Object
readonly
Returns the value of attribute cost.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#state ⇒ Object
Returns the value of attribute state.
Class Method Summary collapse
-
.inherited(child_class) ⇒ void
Add the Subtype module to all step classes.
Instance Method Summary collapse
-
#add_fields_from_index(index) ⇒ void
Mark the fields in this index as fetched.
-
#calculate_cost(cost_model) ⇒ Integer
Calculate the cost of executing this step in the plan.
-
#initialize ⇒ PlanStep
constructor
A new instance of PlanStep.
-
#parent_index ⇒ PlanStep
Find the closest index to this step.
-
#parent_steps(cost_model = nil) ⇒ QueryPlan
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.
-
#to_color ⇒ Object
:nocov:.
Methods included from Supertype
Constructor Details
#initialize ⇒ PlanStep
Returns a new instance of PlanStep.
13 14 15 16 17 |
# File 'lib/nose/plans.rb', line 13 def initialize @children = Set.new @parent = nil @fields = Set.new end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
11 12 13 |
# File 'lib/nose/plans.rb', line 11 def children @children end |
#cost ⇒ Object (readonly)
Returns the value of attribute cost.
11 12 13 |
# File 'lib/nose/plans.rb', line 11 def cost @cost end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
11 12 13 |
# File 'lib/nose/plans.rb', line 11 def fields @fields end |
#parent ⇒ Object
Returns the value of attribute parent.
10 11 12 |
# File 'lib/nose/plans.rb', line 10 def parent @parent end |
#state ⇒ Object
Returns the value of attribute state.
10 11 12 |
# File 'lib/nose/plans.rb', line 10 def state @state end |
Class Method Details
.inherited(child_class) ⇒ void
This method returns an undefined value.
Add the Subtype module to all step classes
82 83 84 |
# File 'lib/nose/plans.rb', line 82 def self.inherited(child_class) child_class.send(:include, Subtype) end |
Instance Method Details
#add_fields_from_index(index) ⇒ void
This method returns an undefined value.
Mark the fields in this index as fetched
42 43 44 |
# File 'lib/nose/plans.rb', line 42 def add_fields_from_index(index) @fields += index.all_fields end |
#calculate_cost(cost_model) ⇒ Integer
Calculate the cost of executing this step in the plan
76 77 78 |
# File 'lib/nose/plans.rb', line 76 def calculate_cost(cost_model) @cost = cost_model.method((subtype_name + '_cost').to_sym).call self end |
#parent_index ⇒ PlanStep
Find the closest index to this step
67 68 69 70 71 72 |
# 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) ⇒ QueryPlan
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)
52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 ⇒ Object
:nocov:
20 21 22 23 24 |
# 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 |