Class: Benedictus::Plan::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/benedictus/plan/node.rb

Constant Summary collapse

RECOGNIZED_KEYS =
[
  "Node Type", "Relation Name", "Alias", "Index Name",
  "Startup Cost", "Total Cost", "Plan Rows", "Plan Width",
  "Actual Startup Time", "Actual Total Time",
  "Actual Rows", "Actual Loops",
  "Filter", "Index Cond", "Join Filter", "Hash Cond", "Recheck Cond",
  "Sort Method", "Sort Key", "Sort Space Type", "Sort Space Used",
  "Join Type", "Strategy", "Parent Relationship", "Subplan Name"
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, children: []) ⇒ Node

Returns a new instance of Node.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/benedictus/plan/node.rb', line 18

def initialize(raw, children: [])
  @raw                = raw
  @node_type          = raw["Node Type"]
  @relation_name      = raw["Relation Name"]
  @alias_name         = raw["Alias"]
  @index_name         = raw["Index Name"]
  @startup_cost       = raw["Startup Cost"]
  @total_cost         = raw["Total Cost"]
  @plan_rows          = raw["Plan Rows"]
  @plan_width         = raw["Plan Width"]
  @actual_startup_time = raw["Actual Startup Time"]
  @actual_total_time  = raw["Actual Total Time"]
  @actual_rows        = raw["Actual Rows"]
  @actual_loops       = raw["Actual Loops"]
  @filter             = raw["Filter"]
  @index_cond         = raw["Index Cond"]
  @join_filter        = raw["Join Filter"]
  @hash_cond          = raw["Hash Cond"]
  @recheck_cond       = raw["Recheck Cond"]
  @sort_method        = raw["Sort Method"]
  @sort_key           = raw["Sort Key"]
  @sort_space_type    = raw["Sort Space Type"]
  @sort_space_used    = raw["Sort Space Used"]
  @join_type          = raw["Join Type"]
  @strategy           = raw["Strategy"]
  @parent_relationship = raw["Parent Relationship"]
  @subplan_name       = raw["Subplan Name"]
  @children           = children
  @attrs              = raw.reject { |k, _| RECOGNIZED_KEYS.include?(k) || k == "Plans" }
  @warnings           = []
end

Instance Attribute Details

#actual_loopsObject (readonly)

Returns the value of attribute actual_loops.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def actual_loops
  @actual_loops
end

#actual_rowsObject (readonly)

Returns the value of attribute actual_rows.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def actual_rows
  @actual_rows
end

#actual_startup_timeObject (readonly)

Returns the value of attribute actual_startup_time.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def actual_startup_time
  @actual_startup_time
end

#actual_total_timeObject (readonly)

Returns the value of attribute actual_total_time.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def actual_total_time
  @actual_total_time
end

#alias_nameObject (readonly)

Returns the value of attribute alias_name.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def alias_name
  @alias_name
end

#attrsObject (readonly)

Returns the value of attribute attrs.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def attrs
  @attrs
end

#childrenObject (readonly)

Returns the value of attribute children.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def children
  @children
end

#filterObject (readonly)

Returns the value of attribute filter.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def filter
  @filter
end

#hash_condObject (readonly)

Returns the value of attribute hash_cond.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def hash_cond
  @hash_cond
end

#index_condObject (readonly)

Returns the value of attribute index_cond.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def index_cond
  @index_cond
end

#index_nameObject (readonly)

Returns the value of attribute index_name.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def index_name
  @index_name
end

#join_filterObject (readonly)

Returns the value of attribute join_filter.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def join_filter
  @join_filter
end

#join_typeObject (readonly)

Returns the value of attribute join_type.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def join_type
  @join_type
end

#node_typeObject (readonly)

Returns the value of attribute node_type.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def node_type
  @node_type
end

#parent_relationshipObject (readonly)

Returns the value of attribute parent_relationship.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def parent_relationship
  @parent_relationship
end

#plan_rowsObject (readonly)

Returns the value of attribute plan_rows.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def plan_rows
  @plan_rows
end

#plan_widthObject (readonly)

Returns the value of attribute plan_width.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def plan_width
  @plan_width
end

#recheck_condObject (readonly)

Returns the value of attribute recheck_cond.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def recheck_cond
  @recheck_cond
end

#relation_nameObject (readonly)

Returns the value of attribute relation_name.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def relation_name
  @relation_name
end

#sort_keyObject (readonly)

Returns the value of attribute sort_key.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def sort_key
  @sort_key
end

#sort_methodObject (readonly)

Returns the value of attribute sort_method.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def sort_method
  @sort_method
end

#sort_space_typeObject (readonly)

Returns the value of attribute sort_space_type.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def sort_space_type
  @sort_space_type
end

#sort_space_usedObject (readonly)

Returns the value of attribute sort_space_used.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def sort_space_used
  @sort_space_used
end

#startup_costObject (readonly)

Returns the value of attribute startup_cost.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def startup_cost
  @startup_cost
end

#strategyObject (readonly)

Returns the value of attribute strategy.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def strategy
  @strategy
end

#subplan_nameObject (readonly)

Returns the value of attribute subplan_name.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def subplan_name
  @subplan_name
end

#total_costObject (readonly)

Returns the value of attribute total_cost.



6
7
8
# File 'lib/benedictus/plan/node.rb', line 6

def total_cost
  @total_cost
end

#warningsObject

Returns the value of attribute warnings.



16
17
18
# File 'lib/benedictus/plan/node.rb', line 16

def warnings
  @warnings
end

Instance Method Details

#analyzed?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/benedictus/plan/node.rb', line 50

def analyzed?
  !actual_total_time.nil?
end

#leaf?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/benedictus/plan/node.rb', line 54

def leaf?
  children.empty?
end

#targetObject



58
59
60
61
62
# File 'lib/benedictus/plan/node.rb', line 58

def target
  return alias_name if alias_name && relation_name && alias_name != relation_name

  relation_name
end