Class: AwesomeExplain::PlanTree
- Inherits:
-
Object
- Object
- AwesomeExplain::PlanTree
- Defined in:
- app/models/awesome_explain/plan_tree.rb
Instance Attribute Summary collapse
-
#collscan ⇒ Object
Returns the value of attribute collscan.
-
#ids ⇒ Object
Returns the value of attribute ids.
-
#root ⇒ Object
Returns the value of attribute root.
-
#stages_count ⇒ Object
Returns the value of attribute stages_count.
Class Method Summary collapse
Instance Method Summary collapse
- #collscan? ⇒ Boolean
-
#treeviz ⇒ Object
Breadth First Traversal.
Instance Attribute Details
#collscan ⇒ Object
Returns the value of attribute collscan.
3 4 5 |
# File 'app/models/awesome_explain/plan_tree.rb', line 3 def collscan @collscan end |
#ids ⇒ Object
Returns the value of attribute ids.
3 4 5 |
# File 'app/models/awesome_explain/plan_tree.rb', line 3 def ids @ids end |
#root ⇒ Object
Returns the value of attribute root.
3 4 5 |
# File 'app/models/awesome_explain/plan_tree.rb', line 3 def root @root end |
#stages_count ⇒ Object
Returns the value of attribute stages_count.
3 4 5 |
# File 'app/models/awesome_explain/plan_tree.rb', line 3 def stages_count @stages_count end |
Class Method Details
.build(plan) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/awesome_explain/plan_tree.rb', line 9 def self.build(plan) tree = PlanTree.new tree.ids = (2..500).to_a root = PlanNode.build(plan) root.id = 1 tree.stages_count = 1 build_recursive(plan.dig('inputStage'), root, tree) tree.root = root tree end |
.build_recursive(data, parent, tree) ⇒ Object
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 'app/models/awesome_explain/plan_tree.rb', line 20 def self.build_recursive(data, parent, tree) return unless data.present? if data.dig('inputStages').present? # Parent doesn't change data.dig('inputStages').each do |stage| node = PlanNode.build(stage, parent) node.id = tree.ids.shift parent.children << node tree.stages_count += 1 tree.collscan = 1 if node.collscan? && !tree.collscan build_recursive(stage.dig('inputStage'), node, tree) end elsif data.dig('inputStage').present? # Parent changes node = PlanNode.build(data, parent) node.id = tree.ids.shift parent.children << node tree.stages_count += 1 tree.collscan = 1 if node.collscan? && !tree.collscan build_recursive(data.dig('inputStage'), node, tree) elsif data.dig('inputStage').nil? # Parent doesn't change node = PlanNode.build(data, parent) node.id = tree.ids.shift tree.stages_count += 1 tree.collscan = 1 if node.collscan? && !tree.collscan parent.children << node end end |
Instance Method Details
#collscan? ⇒ Boolean
5 6 7 |
# File 'app/models/awesome_explain/plan_tree.rb', line 5 def collscan? collscan end |
#treeviz ⇒ Object
Breadth First Traversal
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/awesome_explain/plan_tree.rb', line 51 def treeviz return unless root.present? output = [] queue = [root] while(!queue.empty?) do node = queue.shift output << node.treeviz node.children.each do |child| queue << child end end output end |