Class: AwesomeExplain::SqlPlanNode

Inherits:
Object
  • Object
show all
Defined in:
app/models/awesome_explain/sql_plan_node.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSqlPlanNode

Returns a new instance of SqlPlanNode.



26
27
28
29
# File 'app/models/awesome_explain/sql_plan_node.rb', line 26

def initialize
  @total_rows = 0
  @total_loops = 0
end

Instance Attribute Details

#actual_loopsObject

Returns the value of attribute actual_loops.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def actual_loops
  @actual_loops
end

#actual_rowsObject

Returns the value of attribute actual_rows.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def actual_rows
  @actual_rows
end

#actual_startup_timeObject

Returns the value of attribute actual_startup_time.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def actual_startup_time
  @actual_startup_time
end

#actual_total_timeObject

Returns the value of attribute actual_total_time.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def actual_total_time
  @actual_total_time
end

#childrenObject

Returns the value of attribute children.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def children
  @children
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def id
  @id
end

#index_conditionObject

Returns the value of attribute index_condition.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def index_condition
  @index_condition
end

#index_nameObject

Returns the value of attribute index_name.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def index_name
  @index_name
end

#join_typeObject

Returns the value of attribute join_type.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def join_type
  @join_type
end

#labelObject

Returns the value of attribute label.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def label
  @label
end

#parentObject

Returns the value of attribute parent.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def parent
  @parent
end

#recheck_conditionObject

Returns the value of attribute recheck_condition.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def recheck_condition
  @recheck_condition
end

#relation_nameObject

Returns the value of attribute relation_name.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def relation_name
  @relation_name
end

#rowsObject

Returns the value of attribute rows.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def rows
  @rows
end

#seq_scanObject Also known as: seq_scan?

Returns the value of attribute seq_scan.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def seq_scan
  @seq_scan
end

#startup_costObject

Returns the value of attribute startup_cost.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def startup_cost
  @startup_cost
end

#total_costObject

Returns the value of attribute total_cost.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def total_cost
  @total_cost
end

#total_loopsObject

Returns the value of attribute total_loops.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def total_loops
  @total_loops
end

#total_rowsObject

Returns the value of attribute total_rows.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def total_rows
  @total_rows
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def type
  @type
end

#widthObject

Returns the value of attribute width.



2
3
4
# File 'app/models/awesome_explain/sql_plan_node.rb', line 2

def width
  @width
end

Class Method Details

.build(data, parent = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/awesome_explain/sql_plan_node.rb', line 31

def self.build(data, parent = nil)
  instance = self.new
  instance.label = data.dig('Node Type')
  instance.type = data.dig('Node Type')
  instance.relation_name = data.dig('Relation Name')
  instance.startup_cost = data.dig('Startup Cost')
  instance.total_cost = data.dig('Total Cost')
  instance.rows = data.dig('Plan Rows')
  instance.width = data.dig('Plan Width')
  instance.actual_startup_time = data.dig('Actual Startup Time')
  instance.actual_total_time = data.dig('Actual Total Time')
  instance.actual_rows = data.dig('Actual Rows')
  instance.actual_loops = data.dig('Actual Loops')
  instance.recheck_condition = data.dig('Recheck Cond')
  instance.index_name = data.dig('Index Name')
  instance.index_condition = data.dig('Index Cond')
  instance.seq_scan = data.dig('Node Type') == 'Seq Scan'
  instance.parent = parent
  instance.children = []
  instance
end

Instance Method Details

#meta_dataObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/awesome_explain/sql_plan_node.rb', line 57

def 
  data = []
  data << "<strong>Join Type:</strong> #{join_type}" if join_type.present?
  data << "<strong>Rows:</strong> #{rows}" if rows.present?
  data << "<strong>Width:</strong> #{width}" if width.present?
  data << "<span #{seq_scan? ? 'class="bg-red-200 text-red-900 px-1 py-1 rounded-r"' : ''}><strong>Seq Scan:</strong> #{seq_scan?}</span>"
  data << "<strong>Index Name</strong> #{index_name}" if index_name.present?
  data << "<strong>Index Condition</strong> #{index_condition}" if index_condition.present?
  data << "<strong>Actual Rows</strong> #{actual_rows}" if actual_rows.present?
  data << "<strong>Actual Loops</strong> #{actual_loops}" if actual_loops.present?
  data << "<strong>Startup Cost</strong> #{startup_cost}" if startup_cost.present?
  data << "<strong>Total Cost</strong> #{total_cost}" if total_cost.present?
  data << "<strong>Actual Startup Time</strong> #{actual_startup_time}" if actual_startup_time.present?
  data << "<strong>Actual Total Time</strong> #{actual_total_time}" if actual_total_time.present?
  data
end

#meta_data_strObject



53
54
55
# File 'app/models/awesome_explain/sql_plan_node.rb', line 53

def 
  .join('<hr />')
end