Search in sources :

Example 6 with PlanResult

use of com.cubrid.common.core.queryplan.model.PlanResult 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 7 with PlanResult

use of com.cubrid.common.core.queryplan.model.PlanResult 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 8 with PlanResult

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

the class PlanParser method doParseEachPlan.

/**
	 * 
	 * Parse each query plan string
	 * 
	 * @param string the query plan string
	 * @return <code>true</code> if successfully;<code>false</code>otherwise
	 */
private boolean doParseEachPlan(String string) {
    Map<String, String> dic = getReplacementMap(string);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("<query plan raw>{}</query plan raw>", string);
    }
    int sp = string.indexOf("Query stmt:");
    if (sp == -1) {
        return false;
    }
    sp = string.indexOf('\n', sp);
    if (sp == -1) {
        return false;
    }
    String sql = string.substring(sp).trim();
    sp = string.indexOf("Query plan:");
    if (sp == -1) {
        return false;
    }
    sp = string.indexOf("\n\n", sp);
    if (sp == -1) {
        return false;
    }
    sp += 2;
    int ep = string.indexOf("\n\n", sp);
    if (ep == -1) {
        return false;
    }
    StringBuilder planString = new StringBuilder(string.substring(sp, ep));
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("<query plan string>{}</query plan string>", planString);
    }
    if (dic != null) {
        Iterator<Entry<String, String>> iter = dic.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<String, String> entry = iter.next();
            String key = entry.getKey();
            String val = entry.getValue();
            StringUtil.replace(planString, key, val);
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("<query plan binding>{}</query plan binding>", planString);
        }
    }
    String refinedRawPlan = refineRawPlanString(planString.toString());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("<refinedRawPlan>{}</refinedRawPlan>", refinedRawPlan);
    }
    boolean parsed = false;
    PlanNode planNode = new PlanNode();
    try {
        parseTree(planNode, refinedRawPlan, 0, refinedRawPlan.length());
        parsed = true;
    } catch (Exception e) {
        LOGGER.error("Error of plan parser", e);
        planNode = new PlanNode();
    }
    if (planTreeList == null) {
        planTreeList = new ArrayList<PlanResult>();
    }
    PlanResult planRoot = new PlanResult();
    planRoot.setPlanNode(planNode);
    planRoot.setSql(sql);
    planRoot.setRaw(string);
    planRoot.setParsedRaw(refinedRawPlan);
    planTreeList.add(planRoot);
    return parsed;
}
Also used : PlanResult(com.cubrid.common.core.queryplan.model.PlanResult) Entry(java.util.Map.Entry) PlanNode(com.cubrid.common.core.queryplan.model.PlanNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with PlanResult

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

the class PlanParserTest method testPlan1.

public void testPlan1() throws Exception {
    String filepath = this.getFilePathInPlugin("/com/cubrid/common/core/queryplan/plan1.txt");
    String rawPlan = Tool.getFileContent(filepath);
    StructQueryPlan plan1 = new StructQueryPlan("select * from db_auth", rawPlan, date);
    for (int i = 0; i < plan1.countSubPlan(); i++) {
        PlanResult planResult = plan1.getSubPlan(i);
        System.err.println(planResult.getParsedRaw());
        System.err.println(planResult.getPlanNode());
    }
    assertEquals(plan1.countSubPlan(), 4);
}
Also used : PlanResult(com.cubrid.common.core.queryplan.model.PlanResult)

Example 10 with PlanResult

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

the class StructQueryPlanTest method testStructQueryPlan.

public void testStructQueryPlan() {
    StructQueryPlan plan1 = new StructQueryPlan("select * from test_a1", "plan1", date);
    StructQueryPlan plan2 = new StructQueryPlan("select * from test_a2", "plan2", date);
    List<StructQueryPlan> planList = new ArrayList<StructQueryPlan>();
    planList.add(plan1);
    planList.add(plan2);
    plan1.countSubPlan();
    assertEquals(plan1.getCreated(), date);
    plan1.getCreatedDateString();
    plan1.getPlanRaw();
    assertEquals(plan1.getSql(), "select * from test_a1");
    plan1.getSubPlan(1);
    plan1.setPlanRaw("xx");
    plan1.setSql("select * from test_a1");
    plan1.toString();
    plan1.toXML();
    String xml = StructQueryPlan.serialize(planList);
    assertEquals(StructQueryPlan.unserialize(xml).size(), planList.size());
    assertNotNull(plan2.clone());
    String planString = loadPlanExmaple("plan02.txt");
    PlanParser parser = new PlanParser();
    boolean bool = parser.doParse(planString);
    assertTrue(bool);
    parser.getPlanTree(1);
    PlanResult planRoot = parser.getPlanTree(0);
    plan2.setPlanRaw(planRoot.getParsedRaw());
    assertTrue(plan2.calCost() >= 0);
}
Also used : PlanResult(com.cubrid.common.core.queryplan.model.PlanResult) ArrayList(java.util.ArrayList)

Aggregations

PlanResult (com.cubrid.common.core.queryplan.model.PlanResult)13 PlanNode (com.cubrid.common.core.queryplan.model.PlanNode)8 PlanParser (com.cubrid.common.core.queryplan.PlanParser)3 PlanCost (com.cubrid.common.core.queryplan.model.PlanCost)3 StructQueryPlan (com.cubrid.common.core.queryplan.StructQueryPlan)1 PlanTerm (com.cubrid.common.core.queryplan.model.PlanTerm)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TableItem (org.eclipse.swt.widgets.TableItem)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1