Search in sources :

Example 6 with PlanNode

use of com.cubrid.common.core.queryplan.model.PlanNode 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();
    }
}
Also used : PlanNode(com.cubrid.common.core.queryplan.model.PlanNode) PlanCost(com.cubrid.common.core.queryplan.model.PlanCost) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 7 with PlanNode

use of com.cubrid.common.core.queryplan.model.PlanNode 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();
        }
    }
}
Also used : PlanResult(com.cubrid.common.core.queryplan.model.PlanResult) PlanNode(com.cubrid.common.core.queryplan.model.PlanNode) PlanCost(com.cubrid.common.core.queryplan.model.PlanCost) TableItem(org.eclipse.swt.widgets.TableItem)

Example 8 with PlanNode

use of com.cubrid.common.core.queryplan.model.PlanNode 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;
}
Also used : PlanResult(com.cubrid.common.core.queryplan.model.PlanResult) PlanNode(com.cubrid.common.core.queryplan.model.PlanNode) PlanCost(com.cubrid.common.core.queryplan.model.PlanCost)

Example 9 with PlanNode

use of com.cubrid.common.core.queryplan.model.PlanNode in project cubrid-manager by CUBRID.

the class QueryPlanComposite method printTreePlan.

/**
	 * Print the tree style of the query execution plan on the tab
	 *
	 * @param tabItem
	 * @param sq
	 */
private void printTreePlan() {
    // clear tab item contents
    while (planTree.getItemCount() > 0) {
        planTree.getItem(0).dispose();
    }
    if (queryPlan != null) {
        PlanNode planRoot = makeRootPlanNode(queryPlan, false);
        TreeItem treeItem = printSubPlan(null, planRoot, "");
        for (int i = 0, len = queryPlan.countSubPlan(); i < len; i++) {
            PlanResult plan = queryPlan.getSubPlan(i);
            if (plan == null) {
                continue;
            }
            // print a raw plan
            if (i == 0) {
                String log = "Query:" + StringUtil.NEWLINE + plan.getSql() + StringUtil.NEWLINE + StringUtil.NEWLINE + "Execution Plan:" + StringUtil.NEWLINE + plan.getParsedRaw();
                if (planSql != null && !planSql.isDisposed()) {
                    planSql.setText(log);
                }
                decorateSqlText();
            }
            PlanNode node = plan.getPlanNode();
            if (node != null) {
                String log = "Query:" + StringUtil.NEWLINE + plan.getSql() + StringUtil.NEWLINE + StringUtil.NEWLINE + "Execution Plan:" + StringUtil.NEWLINE + plan.getParsedRaw();
                printSubPlan(treeItem, node, log);
            }
        }
    }
    packPlanTree();
}
Also used : PlanResult(com.cubrid.common.core.queryplan.model.PlanResult) PlanNode(com.cubrid.common.core.queryplan.model.PlanNode) TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 10 with PlanNode

use of com.cubrid.common.core.queryplan.model.PlanNode in project cubrid-manager by CUBRID.

the class QueryPlanTest method testModelPlanNode.

public void testModelPlanNode() {
    PlanNode bean = new PlanNode();
    bean.setDepth(5);
    assertEquals(bean.getDepth(), 5);
    bean.setMethod("method");
    assertEquals(bean.getMethod(), "method");
    bean.setPosition("position");
    assertEquals(bean.getPosition(), "position");
    bean.setCost(new PlanCost());
    assertEquals(bean.getCost().getClass(), PlanCost.class);
    bean.setTable(new PlanTable());
    assertEquals(bean.getTable().getClass(), PlanTable.class);
    bean.setIndex(new PlanTerm());
    assertEquals(bean.getIndex().getClass(), PlanTerm.class);
    bean.setEdge(new PlanTerm());
    assertEquals(bean.getEdge().getClass(), PlanTerm.class);
    bean.setSargs(new PlanTerm());
    assertEquals(bean.getSargs().getClass(), PlanTerm.class);
    bean.setFilter(new PlanTerm());
    assertEquals(bean.getFilter().getClass(), PlanTerm.class);
    bean.setSort("sort");
    assertEquals(bean.getSort(), "sort");
    bean.setOrder("order");
    assertEquals(bean.getOrder(), "order");
    assertEquals(bean.toString() == null, false);
    bean.getChildren();
    bean.newChild();
    bean.addChild(new PlanNode());
    assertNotNull(bean.toString());
    assertNotNull(bean.getDebugString());
}
Also used : PlanNode(com.cubrid.common.core.queryplan.model.PlanNode) PlanCost(com.cubrid.common.core.queryplan.model.PlanCost) PlanTable(com.cubrid.common.core.queryplan.model.PlanTable) PlanTerm(com.cubrid.common.core.queryplan.model.PlanTerm)

Aggregations

PlanNode (com.cubrid.common.core.queryplan.model.PlanNode)15 PlanResult (com.cubrid.common.core.queryplan.model.PlanResult)8 PlanCost (com.cubrid.common.core.queryplan.model.PlanCost)7 PlanTerm (com.cubrid.common.core.queryplan.model.PlanTerm)5 PlanTable (com.cubrid.common.core.queryplan.model.PlanTable)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 PlanParser (com.cubrid.common.core.queryplan.PlanParser)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 TableItem (org.eclipse.swt.widgets.TableItem)1