use of com.cubrid.common.core.queryplan.model.PlanTerm 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.PlanTerm in project cubrid-manager by CUBRID.
the class PlanParser method parseTerm.
/**
* Parse term
*
* @param raw the raw string
* @return the PlanTerm Object
*/
private PlanTerm parseTerm(String raw) {
// sargs: rownum range (min inf_lt 10) (sel 0.1) (rank 3) (instnum term) (not-join eligible) (loc 0)
// sargs: (rownum range (1 ge_le 100)) (sel 0.1) (rank 3) (instnum term) (not-join eligible) (loc 0)
// sargs: A.gender=B.s_name (sel 0.001) (join term) (mergeable) (inner-join) (loc 0)
// sargs: y.j range (min inf_lt10) (sel 1) (rank 2) (sargterm) (not-join eligible) (loc 0)
// sargs: x.i range ((select max(z.i) from z zwhere z.c=x.c) gt_inf max) (sel 0.1) (rank 10) (sarg term) (not-join eligible) (loc 0)
// sargs: x.vc range ('b' gt_inf max) (sel 0.1) (rank 2) (sarg term) (not-join eligible) (loc 0)
// edge: A.gender=B.s_name (sel 0.001) (join term) (mergeable) (inner-join) (loc 0)
// sargs: table(0) -> t t(5/1)
PlanTerm term = new PlanTerm();
term.setName("");
Pattern patternTable = Pattern.compile("table\\([0-9]+\\) \\-\\> ");
int sp = 0;
String[] arr = raw.split(" AND ");
for (int i = 0, len = arr.length; i < len; i++) {
String eachTerm = arr[i].trim();
String condition = "";
String attribute = "";
boolean passed = false;
// (sel #.#)
if (!passed) {
sp = eachTerm.indexOf("(sel ");
if (sp != -1) {
condition = eachTerm.substring(0, sp).trim();
attribute = eachTerm.substring(sp).trim();
passed = true;
}
}
// sargs: table(0) -> t node[1]
if (!passed) {
Matcher m = patternTable.matcher(eachTerm);
if (m.find()) {
condition = eachTerm;
passed = true;
}
}
if (!passed) {
attribute = eachTerm;
}
PlanTermItem item = new PlanTermItem();
item.setCondition(condition);
item.setAttribute(attribute);
term.addTermItem(item);
}
return term;
}
use of com.cubrid.common.core.queryplan.model.PlanTerm 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.PlanTerm in project cubrid-manager by CUBRID.
the class PlanParser method parseIndex.
/**
* Parse the index
*
* @param indexRaw the raw index string
* @return the PlanTerm Object
*/
private PlanTerm parseIndex(String indexRaw) {
if (StringUtil.isEmpty(indexRaw)) {
return null;
}
String indexName = indexRaw.trim();
String indexCond = indexName;
int sp = indexRaw.indexOf(' ');
if (sp != -1) {
indexName = indexRaw.substring(0, sp++).trim();
indexCond = indexRaw.substring(sp, indexRaw.length()).trim();
}
PlanTerm planIndex = parseTerm(indexCond);
if (planIndex == null) {
planIndex = new PlanTerm();
}
planIndex.setName(indexName);
return planIndex;
}
use of com.cubrid.common.core.queryplan.model.PlanTerm 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();
}
Aggregations