1
0
Fork 0

Implemented a heatmap for querynodes to help optimizing the query. Increased font-size of descriptions. Now needs discussion what to do next

This commit is contained in:
Michael Hackstein 2014-12-09 13:03:44 +00:00
parent a4e92bc1dc
commit f540e02b26
3 changed files with 45 additions and 34 deletions

View File

@ -600,21 +600,43 @@
return JSON.stringify(data); return JSON.stringify(data);
}, },
heatmapColors: [
"#313695",
"#4575b4",
"#74add1",
"#abd9e9",
"#e0f3f8",
"#ffffbf",
"#fee090",
"#fdae61",
"#f46d43",
"#d73027",
"#a50026",
],
heatmap: function(value) {
return this.heatmapColors[Math.floor(value * 10)];
},
followQueryPath: function(root, nodes) { followQueryPath: function(root, nodes) {
var known = {}; var known = {};
var estCost = 0;
known[nodes[0].id] = root; known[nodes[0].id] = root;
var i, nodeData, j, dep; var i, nodeData, j, dep;
for (i = 1; i < nodes.length; ++i) { for (i = 1; i < nodes.length; ++i) {
nodeData = this.preparePlanNodeEntry(nodes[i]); nodeData = this.preparePlanNodeEntry(nodes[i], nodes[i-1].estimatedCost);
known[nodes[i].id] = nodeData; known[nodes[i].id] = nodeData;
dep = nodes[i].dependencies; dep = nodes[i].dependencies;
estCost = nodeData.estimatedCost;
for (j = 0; j < dep.length; ++j) { for (j = 0; j < dep.length; ++j) {
known[dep[j]].children.push(nodeData); known[dep[j]].children.push(nodeData);
} }
} }
return estCost;
}, },
preparePlanNodeEntry: function(node) { preparePlanNodeEntry: function(node, parentCost) {
console.log(node);
var json = { var json = {
estimatedCost: node.estimatedCost, estimatedCost: node.estimatedCost,
estimatedNrItems: node.estimatedNrItems, estimatedNrItems: node.estimatedNrItems,
@ -623,9 +645,10 @@
}; };
switch (node.type) { switch (node.type) {
case "SubqueryNode": case "SubqueryNode":
this.followQueryPath(json, node.subquery.nodes); json.relativeCost = json.estimatedCost - this.followQueryPath(json, node.subquery.nodes);
break; break;
default: default:
json.relativeCost = json.estimatedCost - parentCost|| json.estimatedCost;
} }
return json; return json;
@ -633,19 +656,19 @@
drawTree: function() { drawTree: function() {
var treeHeight = 0; var treeHeight = 0;
var heatmap = this.heatmap.bind(this);
if (!this.treeData) { if (!this.treeData) {
return; return;
} }
var treeData = this.treeData; var treeData = this.treeData;
// outputEditor.setValue(JSON.stringify(treeData, undefined, 2)); // outputEditor.setValue(JSON.stringify(treeData, undefined, 2));
console.log($("svg#explainOutput").parent().width());
var margin = {top: 20, right: 20, bottom: 20, left: 20}, var margin = {top: 20, right: 20, bottom: 20, left: 20},
width = $("svg#explainOutput").parent().width() - margin.right - margin.left, width = $("svg#explainOutput").parent().width() - margin.right - margin.left,
height = 500 - margin.top - margin.bottom; height = 500 - margin.top - margin.bottom;
var i = 0; var i = 0;
var maxCost = 0;
var tree = d3.layout.tree().size([width, height]); var tree = d3.layout.tree().size([width, height]);
@ -667,7 +690,7 @@
.projection(function(d) { return [d.x, d.y]; }); .projection(function(d) { return [d.x, d.y]; });
// Normalize for fixed-depth. // Normalize for fixed-depth.
nodes.forEach(function(d) { d.y = d.depth * 60 + margin.top; }); nodes.forEach(function(d) { d.y = d.depth * 80 + margin.top; });
// Declare the nodes¦ // Declare the nodes¦
var node = svg.selectAll("g.node") var node = svg.selectAll("g.node")
@ -678,11 +701,13 @@
if (treeHeight < d.y) { if (treeHeight < d.y) {
treeHeight = d.y; treeHeight = d.y;
} }
if (maxCost < d.relativeCost) {
maxCost = d.relativeCost;
}
return d.id; return d.id;
}); });
treeHeight += 60; treeHeight += 60;
console.log("height:", treeHeight);
$(".query-output").height(treeHeight); $(".query-output").height(treeHeight);
// Enter the nodes. // Enter the nodes.
@ -693,24 +718,20 @@
nodeEnter.append("circle") nodeEnter.append("circle")
.attr("r", 10) .attr("r", 10)
.style("fill", "#fff"); .style("fill", function(d) {return heatmap(d.relativeCost / maxCost);});
nodeEnter.append("text") nodeEnter.append("text")
.attr("x", function(d) { .attr("dx", "0")
return -20;}) // d.children || d._children ? -13 : 13; }) .attr("dy", "-15")
.attr("dy", "-20") .attr("text-anchor", function() {return "middle"; })
.attr("text-anchor", function(d) {
return "start"; }) // d.children || d._children ? "end" : "start"; })
.text(function(d) { return d.type.replace("Node",""); }) .text(function(d) { return d.type.replace("Node",""); })
.style("fill-opacity", 1); .style("fill-opacity", 1);
nodeEnter.append("text") nodeEnter.append("text")
.attr("x", function(d) { .attr("dx", "0")
return -20;}) // d.children || d._children ? -13 : 13; }) .attr("dy", "25")
.attr("dy", "20") .attr("text-anchor", function() { return "middle"; })
.attr("text-anchor", function(d) { .text(function(d) { return "Cost: " + d.relativeCost; })
return "start"; }) // d.children || d._children ? "end" : "start"; })
.text(function(d) { return "Cost: " + d.estimatedCost; })
.style("fill-opacity", 1); .style("fill-opacity", 1);
// Declare the links¦ // Declare the links¦

View File

@ -332,14 +332,8 @@
svg.explain-tree { svg.explain-tree {
width: 100%; width: 100%;
.node circle { .node text {
fill: #fff; font-size: 14px;
stroke: steelblue;
stroke-width: 1.5px;
}
.node {
font: 10px sans-serif;
} }
.link { .link {

View File

@ -5285,12 +5285,8 @@ pre.gv-object-view {
svg.explain-tree { svg.explain-tree {
width: 100%; } width: 100%; }
svg.explain-tree .node circle { svg.explain-tree .node text {
fill: #fff; font-size: 14px; }
stroke: steelblue;
stroke-width: 1.5px; }
svg.explain-tree .node {
font: 10px sans-serif; }
svg.explain-tree .link { svg.explain-tree .link {
fill: none; fill: none;
stroke: #ccc; stroke: #ccc;