Search in sources :

Example 1 with PlanNode

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

the class StructQueryPlan method calCost.

/**
	 * Calculate the cost
	 * 
	 * @return
	 */
public int calCost() {
    int costVal = 0;
    for (int i = 0, len = countSubPlan(); i < len; i++) {
        PlanResult result = getSubPlan(i);
        if (result == null) {
            continue;
        }
        PlanNode node = result.getPlanNode();
        if (node != null) {
            costVal += node.getCost().getTotal();
        }
    }
    return costVal;
}
Also used : PlanResult(com.cubrid.common.core.queryplan.model.PlanResult) PlanNode(com.cubrid.common.core.queryplan.model.PlanNode)

Example 2 with PlanNode

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

the class QueryPlanTest method testModelPlanRoot.

public void testModelPlanRoot() {
    PlanResult bean = new PlanResult();
    bean.setSql("sql");
    assertEquals(bean.getSql(), "sql");
    bean.setRaw("raw");
    assertEquals(bean.getRaw(), "raw");
    bean.setPlanNode(new PlanNode());
    assertEquals(bean.getPlanNode().getClass(), PlanNode.class);
    bean.getPlainSql();
    assertEquals(bean.toString() == null, false);
}
Also used : PlanResult(com.cubrid.common.core.queryplan.model.PlanResult) PlanNode(com.cubrid.common.core.queryplan.model.PlanNode)

Example 3 with PlanNode

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

Example 4 with PlanNode

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

the class QueryPlanComposite method printGraphicPlan.

/**
	 * Print the graphic style of the query execution plan on the tab
	 *
	 * @param tabItem
	 * @param sq
	 */
private void printGraphicPlan() {
    if (queryPlan != null) {
        PlanNode planRoot = makeRootPlanNode(queryPlan, true);
        planGraphic.setInput(planRoot);
    } else {
        planGraphic.setInput(null);
    }
}
Also used : PlanNode(com.cubrid.common.core.queryplan.model.PlanNode)

Example 5 with PlanNode

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

the class GraphPlanContentProvider method makeList.

private void makeList(List<GraphPlanNodePair> list, PlanNode parentNode, PlanNode planNode) {
    if (planNode == null) {
        return;
    }
    if (parentNode != null) {
        GraphPlanNodePair pair = new GraphPlanNodePair();
        list.add(pair);
        // if you need to change directions, you should change following both.
        pair.setSource(parentNode);
        pair.setDest(planNode);
    }
    List<PlanNode> children = planNode.getChildren();
    if (children == null) {
        return;
    }
    for (PlanNode child : children) {
        makeList(list, planNode, child);
    }
}
Also used : PlanNode(com.cubrid.common.core.queryplan.model.PlanNode)

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