Class: NoSE::Plans::FilterPlanStep

Inherits:
PlanStep show all
Defined in:
lib/nose/plans/filter.rb

Overview

A query plan performing a filter without an index

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(eq, range, state = nil) ⇒ FilterPlanStep

Returns a new instance of FilterPlanStep.



9
10
11
12
13
14
15
16
17
18
# File 'lib/nose/plans/filter.rb', line 9

def initialize(eq, range, state = nil)
  @eq = eq
  @range = range
  super()

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

Instance Attribute Details

#eqObject (readonly)

Returns the value of attribute eq.



7
8
9
# File 'lib/nose/plans/filter.rb', line 7

def eq
  @eq
end

#rangeObject (readonly)

Returns the value of attribute range.



7
8
9
# File 'lib/nose/plans/filter.rb', line 7

def range
  @range
end

Class Method Details

.apply(parent, state) ⇒ Object

Check if filtering can be done (we have all the necessary fields)



44
45
46
47
48
49
50
51
# File 'lib/nose/plans/filter.rb', line 44

def self.apply(parent, state)
  # Get fields and check for possible filtering
  filter_fields, eq_filter, range_filter = filter_fields parent, state
  return nil if filter_fields.empty?

  FilterPlanStep.new eq_filter, range_filter, state \
    if required_fields?(filter_fields, parent)
end

Instance Method Details

#==(other) ⇒ Boolean

Two filtering steps are equal if they filter on the same fields

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/nose/plans/filter.rb', line 22

def ==(other)
  other.instance_of?(self.class) && \
    @eq == other.eq && @range == other.range
end

#hashObject



27
28
29
# File 'lib/nose/plans/filter.rb', line 27

def hash
  [@eq.map(&:id), @range.nil? ? nil : @range.id].hash
end

#to_colorObject

:nocov:



32
33
34
35
36
37
38
39
40
# File 'lib/nose/plans/filter.rb', line 32

def to_color
  "#{super} #{@eq.to_color} #{@range.to_color} " +
    begin
      "#{@parent.state.cardinality} " \
        "-> #{state.cardinality}"
    rescue NoMethodError
      ''
    end
end