class NoSE::Plans::ExecutionPlans
Simple DSL
for constructing execution plans
Constants
- LOAD_PATH
The subdirectory execution plans are loaded from
Attributes
groups[R]
mix[R]
schema[R]
weights[R]
Public Class Methods
new(&block)
click to toggle source
# File lib/nose/plans/execution_plan.rb, line 13 def initialize(&block) @groups = Hash.new { |h, k| h[k] = [] } @weights = Hash.new { |h, k| h[k] = {} } @mix = :default instance_eval(&block) if block_given? # Reset the mix to force weight assignment self.mix = @mix end
Public Instance Methods
DefaultMix(mix)
click to toggle source
Set the default mix for these plans @return [void]
# File lib/nose/plans/execution_plan.rb, line 77 def DefaultMix(mix) self.mix = mix end
Group(name, weight = 1.0, **mixes, &block)
click to toggle source
Define a group of query execution plans @return [void]
# File lib/nose/plans/execution_plan.rb, line 83 def Group(name, weight = 1.0, **mixes, &block) @group = name # Save the weights if mixes.empty? @weights[name][:default] = weight else @weights[name] = mixes end instance_eval(&block) if block_given? end
Plan(name, &block)
click to toggle source
Define a single plan within a group @return [void]
# File lib/nose/plans/execution_plan.rb, line 98 def Plan(name, &block) return unless block_given? plan = QueryExecutionPlan.new(@group, name, @schema, self) # Capture one level of nesting in plans if @parent_plan.nil? @parent_plan = plan if @parent_plan.nil? set_parent = true else set_parent = false end plan.instance_eval(&block) # Reset the parent plan if it was set @parent_plan = nil if set_parent @groups[@group] << plan end
Schema(name)
click to toggle source
Set the schema to be used by the execution plans @return [void]
# File lib/nose/plans/execution_plan.rb, line 69 def Schema(name) @schema = Schema.load name NoSE::DSL.mixin_fields @schema.model.entities, QueryExecutionPlan NoSE::DSL.mixin_fields @schema.model.entities, ExecutionPlans end
Support(&block)
click to toggle source
Add support queries for updates in a plan @return [void]
# File lib/nose/plans/execution_plan.rb, line 121 def Support(&block) # XXX Hack to swap the group name and capture support plans old_group = @group @group = '__SUPPORT__' instance_eval(&block) if block_given? @parent_plan.query_plans = @groups[@group] @parent_plan.query_plans.each do |plan| plan.instance_variable_set(:@group, old_group) end @groups[@group] = [] @group = old_group end
calculate_cost(cost_model)
click to toggle source
Populate the cost of each plan @return [void]
# File lib/nose/plans/execution_plan.rb, line 26 def calculate_cost(cost_model) @groups.each_value do |plans| plans.each do |plan| plan.steps.each do |step| cost = cost_model.index_lookup_cost step step.instance_variable_set(:@cost, cost) end plan.query_plans.each do |query_plan| query_plan.steps.each do |step| cost = cost_model.index_lookup_cost step step.instance_variable_set(:@cost, cost) end end # XXX Only bother with insert statements for now plan.update_steps.each do |step| cost = cost_model.insert_cost step step.instance_variable_set(:@cost, cost) end end end end
mix=(mix)
click to toggle source
Set the weights on plans when the mix is changed @return [void]
# File lib/nose/plans/execution_plan.rb, line 52 def mix=(mix) @mix = mix @groups.each do |group, plans| plans.each do |plan| plan.instance_variable_set :@weight, @weights[group][@mix] plan.query_plans.each do |query_plan| query_plan.instance_variable_set :@weight, @weights[group][@mix] end end end end