use of com.cubrid.common.core.queryplan.model.PlanCost in project cubrid-manager by CUBRID.
the class PlanParser method parseCost.
/**
* Returns the cost while a query execution.
*
* @param raw A raw text with a query execution cost informations.
*
* @return PlanCost object
*/
private PlanCost parseCost(String raw) {
// the style before CUBRID 9.0 : fixed 0(0.0/0.0) var 281(16.7/264.0) card 6677
PlanCost planCost = null;
String pattenString = "fixed[ ]+([0-9]+)\\(([0-9\\.]+)/([0-9\\.]+)\\)[ ]+var[ ]+([0-9]+)\\(([0-9\\.]+)/([0-9\\.]+)\\)[ ]+card[ ]+([0-9]+)";
Matcher matcher = Pattern.compile(pattenString).matcher(raw.trim());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("<groupCount>" + matcher.groupCount() + "</groupCount>");
LOGGER.debug("<parseCost-str>" + raw + "</parseCost-str>");
}
if (matcher.matches() && matcher.groupCount() == 7) {
planCost = new PlanCost();
planCost.setFixedTotal(StringUtil.intValue(matcher.group(1)));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("<parseCost-match-group1>" + matcher.group(1) + "</parseCost-match-group1>");
}
planCost.setFixedCpu(StringUtil.floatValue(matcher.group(2)));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("<parseCost-match-group2>" + matcher.group(2) + "</parseCost-match-group2>");
}
planCost.setFixedDisk(StringUtil.floatValue(matcher.group(3)));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("<parseCost-match-group3>" + matcher.group(3) + "</parseCost-match-group3>");
}
planCost.setVarTotal(StringUtil.intValue(matcher.group(4)));
planCost.setVarCpu(StringUtil.floatValue(matcher.group(5)));
planCost.setVarDisk(StringUtil.floatValue(matcher.group(6)));
planCost.setCard(StringUtil.intValue(matcher.group(7)));
planCost.setTotal((int) (planCost.getFixedTotal() + planCost.getVarTotal()));
return planCost;
}
// the style after CUBRID 9.0 : 230 card 6677
pattenString = "([0-9]+)[ ]+card[ ]+([0-9]+)";
matcher = Pattern.compile(pattenString).matcher(raw.trim());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("<groupCount>" + matcher.groupCount() + "</groupCount>");
LOGGER.debug("<parseCost-str>" + raw + "</parseCost-str>");
}
if (matcher.matches() && matcher.groupCount() == 2) {
planCost = new PlanCost();
planCost.setCard(StringUtil.intValue(matcher.group(2)));
planCost.setTotal(StringUtil.intValue(matcher.group(1)));
}
return planCost;
}
use of com.cubrid.common.core.queryplan.model.PlanCost in project cubrid-manager by CUBRID.
the class QueryPlanComposite method printSubPlan.
/**
* print the sub plan.
*
* @param tabItem PlanTabItem
* @param treeItem TreeItem
* @param node PlanNode
* @param sql String
*/
private TreeItem printSubPlan(TreeItem treeItem, PlanNode node, String sql) {
boolean isRoot = treeItem == null;
boolean existChildren = node.getChildren() != null && node.getChildren().size() > 0;
TreeItem item = null;
if (isRoot) {
item = new TreeItem(planTree, SWT.NONE);
item.setData(sql);
} else {
item = new TreeItem(treeItem, SWT.NONE);
item.setData(sql);
}
String icon = null;
boolean isIndex = node.getIndex() != null;
boolean isTable = node.getTable() != null && node.getTable().getPartitions() != null;
if ("idx-join".equals(node.getMethod())) {
icon = "icons/queryeditor/qe_explain_index_join.png";
} else if (existChildren) {
icon = "icons/queryeditor/qe_explain_folder.png";
} else if (isIndex) {
icon = "icons/queryeditor/qe_explain_index.png";
} else if (isTable) {
icon = "icons/queryeditor/qe_explain_partition.png";
} else {
icon = "icons/queryeditor/qe_explain_table.png";
}
// Type
int i = 0;
item.setImage(i, CommonUIPlugin.getImage(icon));
if (node.getMethod() != null) {
item.setText(i++, node.getMethodTitle());
if (node.getMethod().startsWith("temp") || node.getMethod().startsWith("sscan")) {
item.setBackground(BG_SSCAN);
} else if (node.getMethod().startsWith("iscan")) {
item.setBackground(BG_ISCAN);
}
}
// Table
if (node.getTable() == null) {
item.setText(i++, "");
} else {
item.setForeground(i, FG_TABLE);
item.setText(i++, node.getTable().getName());
}
// Index
if (node.getIndex() == null) {
item.setText(i++, "");
} else {
item.setForeground(i, FG_INDEX);
PlanTerm index = node.getIndex();
item.setText(i++, index.getName());
}
// Terms
if (node.getTable() == null || node.getTable().getPartitions() == null) {
item.setText(i++, "");
} else {
item.setText(i++, node.getTable().getTextPartitions());
}
// Cost
if (node.getCost() == null) {
item.setText(i++, "");
item.setText(i++, "");
} else {
PlanCost cost = node.getCost();
item.setText(i++, String.valueOf(cost.getTotal()));
if (node.getCost().getCard() < 0) {
item.setText(i++, "-");
} else {
item.setText(i++, String.valueOf(cost.getCard()));
}
}
// Row/Page
if (node.getTable() == null) {
item.setText(i++, "");
} else {
item.setText(i++, node.getTable().getCard() + "/" + node.getTable().getPage());
}
// Extra information
if (node.getSort() == null) {
item.setText(i++, "");
} else {
item.setText(i++, "(sort " + node.getSort() + ")");
}
boolean isOddRow = false;
if (node.getIndex() != null) {
PlanTerm subTerm = node.getIndex();
// It do not make a child node if it is iscan and it has only 1 child.
if ("iscan".equals(node.getMethod()) && subTerm.hasSingleTerm()) {
overwritePlanTreeItem(item, subTerm);
} else {
printSubPlanTerm(item, subTerm, subTerm.getTypeString(), (isOddRow = !isOddRow));
}
}
if (node.getEdge() != null) {
PlanTerm subTerm = node.getEdge();
// It do not make a child node if it is iscan and it has only 1 child.
if (("follow".equals(node.getMethod()) || node.getMethod().startsWith("nl-join")) && subTerm.hasSingleTerm()) /*&& "join".equals(subTerm.getName())*/
{
overwritePlanTreeItem(item, subTerm);
} else {
printSubPlanTerm(item, subTerm, subTerm.getTypeString(), (isOddRow = !isOddRow));
}
}
if (node.getSargs() != null) {
PlanTerm subTerm = node.getSargs();
// It do not make a child node if it is iscan and it has only 1 child.
if ("sscan".equals(node.getMethod()) && subTerm.hasSingleTerm()) {
overwritePlanTreeItem(item, subTerm);
} else {
printSubPlanTerm(item, subTerm, subTerm.getTypeString(), (isOddRow = !isOddRow));
}
}
if (node.getFilter() != null) {
printSubPlanTerm(item, node.getFilter(), node.getFilter().getTypeString(), (isOddRow = !isOddRow));
}
item.setExpanded(true);
if (!isRoot) {
treeItem.setExpanded(true);
}
if (existChildren) {
for (PlanNode childNode : node.getChildren()) {
printSubPlan(item, childNode, null);
}
}
return item;
}
use of com.cubrid.common.core.queryplan.model.PlanCost in project cubrid-manager by CUBRID.
the class GraphPlanStyleProvider method selfStyleNode.
public void selfStyleNode(Object element, GraphNode node) {
if (element instanceof PlanNode) {
PlanNode planNode = (PlanNode) element;
CompartmentFigure figure = (CompartmentFigure) node.getNodeFigure();
String title = planNode.getMethod();
if (planNode.getTable() != null) {
title += "(" + planNode.getTable().getName() + ")";
}
figure.setTitle(title);
GraphPlanTooltipFigure tooltip = new GraphPlanTooltipFigure();
figure.setToolTip(tooltip);
Dimension dim = tooltip.getPreferredSize();
tooltip.setTitle(planNode.getMethod());
if (planNode.getDepth() == 0) {
figure.setImage(GraphPlanImageSupport.getDefaultImage());
} else {
figure.setImage(GraphPlanImageSupport.getImage(planNode));
}
PlanCost cost = planNode.getCost();
if (cost != null) {
String costAndCardinality = "";
costAndCardinality += "cost: " + cost.getTotal();
tooltip.addKeyValueItem("cost", wrapText(dim.width, String.valueOf(cost.getTotal())));
if (cost.getCard() > 0) {
costAndCardinality += ", card: " + cost.getCard();
tooltip.addKeyValueItem("cardinality", wrapText(dim.width, String.valueOf(cost.getCard())));
}
figure.setInfo(costAndCardinality);
}
if (planNode.getTable() != null && planNode.getTable().getName() != null) {
tooltip.addKeyValueItem("table", wrapText(dim.width, planNode.getTable().getName()));
}
if (planNode.getEdge() != null && planNode.getEdge().getTermString() != null) {
tooltip.addKeyValueItem("edge", wrapText(dim.width, planNode.getEdge().getTermString()));
}
if (planNode.getSargs() != null && planNode.getSargs().getTermString() != null) {
tooltip.addKeyValueItem("sargs", wrapText(dim.width, planNode.getSargs().getTermString()));
}
if (planNode.getIndex() != null && planNode.getIndex().getTermString() != null) {
tooltip.addKeyValueItem("index", wrapText(dim.width, planNode.getIndex().getTermString()));
}
if (planNode.getOrder() != null) {
tooltip.addKeyValueItem("sort", wrapText(dim.width, planNode.getOrder()));
}
figure.show();
}
}
use of com.cubrid.common.core.queryplan.model.PlanCost in project cubrid-manager by CUBRID.
the class QueryPlanCompositeWithHistory method printHistory.
/**
* print a plan history
*
* @param uid int
* @param sq StructQueryPlan
*/
private void printHistory(int uid, StructQueryPlan sq) {
String created = sq.getCreatedDateString();
float costValue = 0.0f;
PlanResult planRoot = sq.getSubPlan(0);
if (planRoot == null) {
return;
}
for (int i = 0, len = sq.countSubPlan(); i < len; i++) {
planRoot = sq.getSubPlan(i);
PlanNode node = planRoot.getPlanNode();
if (node != null && node.getCost() != null) {
PlanCost cost = node.getCost();
costValue += cost.getTotal();
}
}
TableItem item = new TableItem(planHistoryTable, SWT.LEFT);
item.setText(0, String.valueOf(uid));
item.setText(1, created);
item.setText(2, String.valueOf(costValue));
String sql = planRoot.getPlainSql();
if (sql.length() > 100) {
sql = sql.substring(0, 96);
sql += "...";
}
item.setText(3, sql);
for (int i = 0, len = planHistoryTblCols.length; i < len; i++) {
if (planHistoryTblCols[i] != null && !planHistoryTblCols[i].isDisposed()) {
planHistoryTblCols[i].pack();
}
}
}
use of com.cubrid.common.core.queryplan.model.PlanCost in project cubrid-manager by CUBRID.
the class QueryPlanComposite method makeRootPlanNode.
/**
* Make the root node if there have many root nodes.
*
* @param sq
* @param makeNestedNodes
* @return
*/
private PlanNode makeRootPlanNode(StructQueryPlan sq, boolean makeNestedNodes) {
PlanNode planRoot = new PlanNode();
planRoot.setMethod(Messages.lblPlanQuery);
planRoot.setDepth(0);
planRoot.setCost(new PlanCost());
int costVal = 0;
for (int i = 0, len = sq.countSubPlan(); i < len; i++) {
PlanResult result = sq.getSubPlan(i);
if (result == null) {
continue;
}
PlanNode node = result.getPlanNode();
if (node != null) {
if (makeNestedNodes) {
planRoot.addChild(node);
}
costVal += node.getCost().getTotal();
}
}
planRoot.getCost().setTotal(costVal);
planRoot.getCost().setCard(-1);
return planRoot;
}
Aggregations