class NoSE::Plans::QueryPlanTree
A tree of possible query plans
Attributes
cost_model[RW]
root[R]
Public Class Methods
new(state, cost_model)
click to toggle source
# File lib/nose/plans/query_planner.rb, line 92 def initialize(state, cost_model) @root = RootPlanStep.new(state) @cost_model = cost_model end
Public Instance Methods
each() { |parent_steps cost_model| ... }
click to toggle source
Enumerate all plans in the tree
# File lib/nose/plans/query_planner.rb, line 114 def each nodes = [@root] until nodes.empty? node = nodes.pop if node.children.empty? # This is just an extra check to make absolutely # sure we never consider invalid statement plans fail unless node.state.answered? yield node.parent_steps @cost_model else nodes.concat node.children.to_a end end end
query()
click to toggle source
The query this tree of plans is generated for @return [Query]
# File lib/nose/plans/query_planner.rb, line 109 def query @root.state.query end
select_using_indexes(indexes)
click to toggle source
Select all plans which use only a given set of indexes
# File lib/nose/plans/query_planner.rb, line 98 def select_using_indexes(indexes) select do |plan| plan.all? do |step| !step.is_a?(Plans::IndexLookupPlanStep) || indexes.include?(step.index) end end end
size()
click to toggle source
Return the total number of plans for this statement @return [Integer]
# File lib/nose/plans/query_planner.rb, line 133 def size to_a.size end
to_color(step = nil, indent = 0)
click to toggle source
:nocov:
# File lib/nose/plans/query_planner.rb, line 138 def to_color(step = nil, indent = 0) step = @root if step.nil? this_step = ' ' * indent + step.to_color this_step << " [yellow]$#{step.cost.round 5}[/]" \ unless step.is_a?(RootPlanStep) || step.cost.nil? this_step + "\n" + step.children.map do |child_step| to_color child_step, indent + 1 end.reduce('', &:+) end