Class: NoSE::Plans::QueryPlan

Inherits:
AbstractPlan show all
Extended by:
Forwardable
Includes:
Comparable, Enumerable
Defined in:
lib/nose/plans/query_planner.rb

Overview

A single plan for a query

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#partitions, #prefixes, #product_by, #sum_by

Constructor Details

#initialize(query, cost_model) ⇒ QueryPlan

Returns a new instance of QueryPlan.



167
168
169
170
171
# File 'lib/nose/plans/query_planner.rb', line 167

def initialize(query, cost_model)
  @steps = []
  @query = query
  @cost_model = cost_model
end

Instance Attribute Details

#cost_modelObject

Returns the value of attribute cost_model.



157
158
159
# File 'lib/nose/plans/query_planner.rb', line 157

def cost_model
  @cost_model
end

#queryObject

Returns the value of attribute query.



157
158
159
# File 'lib/nose/plans/query_planner.rb', line 157

def query
  @query
end

#stepsObject (readonly)

Returns the value of attribute steps.



156
157
158
# File 'lib/nose/plans/query_planner.rb', line 156

def steps
  @steps
end

Instance Method Details

#<=>(other) ⇒ Boolean

Two plans are compared by their execution cost

Returns:

  • (Boolean)


206
207
208
# File 'lib/nose/plans/query_planner.rb', line 206

def <=>(other)
  cost <=> other.cost
end

#costNumeric

The estimated cost of executing the query using this plan

Returns:

  • (Numeric)


212
213
214
215
# File 'lib/nose/plans/query_planner.rb', line 212

def cost
  costs = @steps.map(&:cost)
  costs.inject(0, &:+) unless costs.any?(&:nil?)
end

#groupString

Groups for plans are stored in the query

Returns:

  • (String)


183
184
185
# File 'lib/nose/plans/query_planner.rb', line 183

def group
  @query.group
end

#indexesArray<Index>

Get the indexes used by this query plan

Returns:



219
220
221
# File 'lib/nose/plans/query_planner.rb', line 219

def indexes
  @steps.select { |step| step.is_a? IndexLookupPlanStep }.map(&:index)
end

#nameString

Name plans after the associated query

Returns:

  • (String)


189
190
191
# File 'lib/nose/plans/query_planner.rb', line 189

def name
  @query.text
end

#paramsObject

Parameters to this execution plan



200
201
202
# File 'lib/nose/plans/query_planner.rb', line 200

def params
  @query.conditions
end

#select_fieldsArray<Fields::Field>

Fields selected by this plan

Returns:



195
196
197
# File 'lib/nose/plans/query_planner.rb', line 195

def select_fields
  @query.select
end

#weightFixnum

The weight of this query for a given workload

Returns:

  • (Fixnum)


175
176
177
178
179
# File 'lib/nose/plans/query_planner.rb', line 175

def weight
  return 1 if @workload.nil?

  @workload.statement_weights[@query]
end