Class: NoSE::Plans::PlanStep

Inherits:
Object
  • Object
show all
Includes:
Supertype
Defined in:
lib/nose/plans.rb

Overview

A single step in a statement plan

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Supertype

included

Constructor Details

#initializePlanStep

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

#childrenObject

Returns the value of attribute children.



11
12
13
# File 'lib/nose/plans.rb', line 11

def children
  @children
end

#costObject (readonly)

Returns the value of attribute cost.



11
12
13
# File 'lib/nose/plans.rb', line 11

def cost
  @cost
end

#fieldsObject (readonly)

Returns the value of attribute fields.



11
12
13
# File 'lib/nose/plans.rb', line 11

def fields
  @fields
end

#parentObject

Returns the value of attribute parent.



10
11
12
# File 'lib/nose/plans.rb', line 10

def parent
  @parent
end

#stateObject

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

Returns:



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_indexPlanStep

Find the closest index to this step

Returns:



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)

Returns:



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_colorObject

: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