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);
bean.setSql(null);
bean.getPlainSql();
}
use of com.cubrid.common.core.queryplan.model.PlanNode in project cubrid-manager by CUBRID.
the class PlanParser method parseTree.
/**
* Parse the tree
*
* @param parent the parent PlanNode
* @param string the string
* @param sp the position
* @param ep the position
*/
private void parseTree(PlanNode parent, String string, int sp, int ep) {
int newSp = string.indexOf('\n', sp);
if (newSp == -1) {
return;
}
parent.setMethod(string.substring(sp, newSp).trim());
int anotherSp = newSp + 1;
for (; ; ) {
int eol = string.indexOf("\n", anotherSp);
if (eol == -1) {
eol = ep;
}
String row = string.substring(anotherSp, eol);
int nvSplitPos = row.indexOf(':');
if (nvSplitPos == -1) {
break;
}
String name = row.substring(0, nvSplitPos).trim();
if ("outer".equals(name) || "inner".equals(name) || "subplan".equals(name) || "follow".equals(name) || "head".equals(name)) {
PlanNode child = parent.newChild();
child.setPosition(name);
int childSp = string.indexOf(':', anotherSp) + 1;
int childEp = getEndPositionOfChildNodeString(string, childSp, ep);
if (childEp == -1) {
break;
}
String area = string.substring(childSp, childEp).trim();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("<area>" + area + "</area>");
}
parseTree(child, string, childSp, childEp);
eol = childEp;
} else if ("cost".equals(name)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("cost");
}
String partString = row.substring(nvSplitPos + 1).trim();
parent.setCost(parseCost(partString));
} else if ("class".equals(name)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("class");
}
String partString = row.substring(nvSplitPos + 1).trim();
parent.setTable(parseClass(partString));
} else if ("index".equals(name)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("index");
}
String partString = row.substring(nvSplitPos + 1).trim();
PlanTerm planTerm = parseIndex(partString);
if (planTerm != null) {
LOGGER.warn("Can't parse a partString = {}", partString);
planTerm.setType(PlanTermType.INDEX);
parent.setIndex(planTerm);
}
} else if ("edge".equals(name)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("edge");
}
String partString = row.substring(nvSplitPos + 1).trim();
PlanTerm planTerm = parseTerm(partString);
planTerm.setType(PlanTermType.EDGE);
parent.setEdge(planTerm);
} else if ("sargs".equals(name)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("sargs");
}
String partString = row.substring(nvSplitPos + 1).trim();
PlanTerm planTerm = parseTerm(partString);
planTerm.setType(PlanTermType.SARGS);
parent.setSargs(planTerm);
} else if ("filtr".equals(name)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("filtr");
}
String partString = row.substring(nvSplitPos + 1).trim();
PlanTerm planTerm = parseTerm(partString);
planTerm.setType(PlanTermType.FILTER);
parent.setFilter(planTerm);
// filtr: x.c<>'a' (sel 0.999)(sargterm)(not-joineligible)(loc0)
} else if ("order".equals(name)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("order");
}
String partString = row.substring(nvSplitPos + 1).trim();
parent.setOrder(partString);
} else if ("others".equals(name)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("others");
}
} else if ("sort".equals(name)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("sort");
}
String partString = row.substring(nvSplitPos + 1).trim();
parent.setSort(partString);
}
// subplan: m-join(inner join)
anotherSp = eol + 1;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("anotherSp=" + anotherSp);
}
if (anotherSp >= ep) {
break;
}
}
}
use of com.cubrid.common.core.queryplan.model.PlanNode 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;
}
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();
}
use of com.cubrid.common.core.queryplan.model.PlanNode in project cubrid-manager by CUBRID.
the class PlanParserTest method testExam01.
/**
* simple plan
*
* @throws Exception
*/
public void testExam01() throws Exception {
String planString = loadPlanExmaple("plan01.txt");
PlanParser parser = new PlanParser();
boolean bool = parser.doParse(planString);
assertTrue(bool);
parser.getPlanTree(1);
PlanResult planRoot = parser.getPlanTree(0);
assertNotNull(planRoot);
PlanNode planNode = planRoot.getPlanNode();
assertEquals(planNode.getMethod(), "idx-join (inner join)");
assertEquals(planNode.getDepth(), 1);
PlanCost planCost = planNode.getCost();
assertNotNull(planCost);
assertEquals(planCost.getCard(), 40);
assertEquals(String.valueOf(planCost.getFixedCpu()), "0.0");
assertEquals(String.valueOf(planCost.getFixedDisk()), "2.0");
assertEquals(String.valueOf(planCost.getFixedTotal()), "2.0");
assertEquals(String.valueOf(planCost.getVarCpu()), "100.3");
assertEquals(String.valueOf(planCost.getVarDisk()), "275.0");
assertEquals(String.valueOf(planCost.getVarTotal()), "375.0");
assertNull(planNode.getTable());
assertNull(planNode.getIndex());
assertNull(planNode.getEdge());
assertNull(planNode.getFilter());
assertNull(planNode.getSort());
assertNull(planNode.getOrder());
PlanTerm sargs = planNode.getSargs();
assertNotNull(sargs);
assertNotNull(planNode.getChildren());
assertEquals(planNode.getChildren().size(), 2);
PlanParser parser2 = new PlanParser();
parser2.getPlanTree(0);
parser2.countPlanTree();
parser2.doParse(null);
parser2.doParse("aaa");
}
Aggregations