Class: NoSE::Plans::IndexLookupPlanStep

Inherits:
PlanStep show all
Extended by:
Forwardable
Defined in:
lib/nose/plans/index_lookup.rb

Overview

Superclass for steps using indices

Instance Attribute Summary collapse

Attributes inherited from PlanStep

#children, #cost, #fields, #parent, #state

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PlanStep

#add_fields_from_index, #calculate_cost, inherited, #parent_index, #parent_steps

Methods included from Supertype

included

Constructor Details

#initialize(index, state = nil, parent = nil) ⇒ IndexLookupPlanStep

Returns a new instance of IndexLookupPlanStep.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/nose/plans/index_lookup.rb', line 12

def initialize(index, state = nil, parent = nil)
  super()
  @index = index

  if state && state.query
    all_fields = state.query.all_fields
    @fields = (@index.hash_fields + @index.order_fields).to_set + \
              (@index.extra.to_set & all_fields)
  else
    @fields = @index.all_fields
  end

  return if state.nil?
  @state = state.dup
  update_state parent
  @state.freeze
end

Instance Attribute Details

#eq_filterObject (readonly)

Returns the value of attribute eq_filter.



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

def eq_filter
  @eq_filter
end

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#limitObject (readonly)

Returns the value of attribute limit.



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

def limit
  @limit
end

#order_byObject (readonly)

Returns the value of attribute order_by.



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

def order_by
  @order_by
end

#range_filterObject (readonly)

Returns the value of attribute range_filter.



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

def range_filter
  @range_filter
end

Class Method Details

.apply(parent, index, state) ⇒ IndexLookupPlanStep

Check if this step can be applied for the given index, returning a possible application of the step

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/nose/plans/index_lookup.rb', line 50

def self.apply(parent, index, state)
  # Validate several conditions which identify if this index is usable
  begin
    check_joins index, state
    check_forward_lookup parent, index, state
    check_parent_index parent, index, state
    check_all_hash_fields parent, index, state
    check_graph_fields parent, index, state
    check_last_fields index, state
  rescue InvalidIndex
    return nil
  end

  IndexLookupPlanStep.new(index, state, parent)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Two index steps are equal if they use the same index



42
43
44
# File 'lib/nose/plans/index_lookup.rb', line 42

def ==(other)
  other.instance_of?(self.class) && @index == other.index
end

#to_colorObject

:nocov:



31
32
33
34
35
36
37
38
# File 'lib/nose/plans/index_lookup.rb', line 31

def to_color
  if @state.nil?
    "#{super} #{@index.to_color}"
  else
    "#{super} #{@index.to_color} * " \
      "#{@state.cardinality}/#{@state.hash_cardinality} "
  end
end