Class: NoSE::Plans::QueryPlan
- Inherits:
-
AbstractPlan
- Object
- AbstractPlan
- NoSE::Plans::QueryPlan
- 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
-
#cost_model ⇒ Object
Returns the value of attribute cost_model.
-
#query ⇒ Object
Returns the value of attribute query.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
-
#<=>(other) ⇒ Boolean
Two plans are compared by their execution cost.
-
#cost ⇒ Numeric
The estimated cost of executing the query using this plan.
-
#group ⇒ String
Groups for plans are stored in the query.
-
#indexes ⇒ Array<Index>
Get the indexes used by this query plan.
-
#initialize(query, cost_model) ⇒ QueryPlan
constructor
A new instance of QueryPlan.
-
#name ⇒ String
Name plans after the associated query.
-
#params ⇒ Object
Parameters to this execution plan.
-
#select_fields ⇒ Array<Fields::Field>
Fields selected by this plan.
-
#weight ⇒ Fixnum
The weight of this query for a given workload.
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_model ⇒ Object
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 |
#query ⇒ Object
Returns the value of attribute query.
157 158 159 |
# File 'lib/nose/plans/query_planner.rb', line 157 def query @query end |
#steps ⇒ Object (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
206 207 208 |
# File 'lib/nose/plans/query_planner.rb', line 206 def <=>(other) cost <=> other.cost end |
#cost ⇒ Numeric
The estimated cost of executing the query using this plan
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 |
#group ⇒ String
Groups for plans are stored in the query
183 184 185 |
# File 'lib/nose/plans/query_planner.rb', line 183 def group @query.group end |
#indexes ⇒ Array<Index>
Get the indexes used by this query plan
219 220 221 |
# File 'lib/nose/plans/query_planner.rb', line 219 def indexes @steps.select { |step| step.is_a? IndexLookupPlanStep }.map(&:index) end |
#name ⇒ String
Name plans after the associated query
189 190 191 |
# File 'lib/nose/plans/query_planner.rb', line 189 def name @query.text end |
#params ⇒ Object
Parameters to this execution plan
200 201 202 |
# File 'lib/nose/plans/query_planner.rb', line 200 def params @query.conditions end |
#select_fields ⇒ Array<Fields::Field>
Fields selected by this plan
195 196 197 |
# File 'lib/nose/plans/query_planner.rb', line 195 def select_fields @query.select end |
#weight ⇒ Fixnum
The weight of this query for a given workload
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 |