use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class SubQueryPreProcessor method addSubQuery.
private static void addSubQuery(PlanNode node, ItemSubQuery subQuery, BoolPtr childTransform) {
node.getSubQueries().add(subQuery);
PlanNode subNode = findComparisonsSubQueryToJoinNode(subQuery.getPlanNode(), childTransform);
subQuery.setPlanNode(subNode);
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class SubQueryPreProcessor method findComparisonsSubQueryToJoinNode.
/**
* http://dev.mysql.com/doc/refman/5.0/en/comparisons-using-subqueries.html
*/
private static PlanNode findComparisonsSubQueryToJoinNode(PlanNode qtn, BoolPtr childTransform) {
for (int i = 0; i < qtn.getChildren().size(); i++) {
PlanNode child = qtn.getChildren().get(i);
qtn.getChildren().set(i, findComparisonsSubQueryToJoinNode(child, childTransform));
}
for (Item itemSelect : qtn.getColumnsSelected()) {
if (itemSelect instanceof ItemScalarSubQuery) {
ItemScalarSubQuery scalarSubQuery = (ItemScalarSubQuery) itemSelect;
findComparisonsSubQueryToJoinNode(scalarSubQuery.getPlanNode(), childTransform);
}
}
// having contains sub query
buildSubQuery(qtn, new SubQueryFilter(), qtn.getHavingFilter(), false, childTransform);
SubQueryFilter find = new SubQueryFilter();
find.query = qtn;
find.filter = null;
Item where = qtn.getWhereFilter();
SubQueryFilter result = buildSubQuery(qtn, find, where, false, childTransform);
if (result != find) {
// that means where filter only contains sub query,just replace it
result.query.query(result.filter);
qtn.query(null);
// change result.filter and rebuild
result.query.setUpFields();
childTransform.set(true);
return result.query;
} else {
if (childTransform.get()) {
qtn.setUpFields();
}
return qtn;
}
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class SubQueryProcessor method tryTransformerQuery.
/**
* find query node in qtn ,change to other 3 type node
*/
private static PlanNode tryTransformerQuery(PlanNode qtn, BoolPtr boolptr) {
boolean childMerged = false;
for (int index = 0; index < qtn.getChildren().size(); index++) {
PlanNode child = qtn.getChildren().get(index);
BoolPtr boolPtr = new BoolPtr(false);
PlanNode newChild = tryTransformerQuery(child, boolPtr);
if (boolPtr.get())
childMerged = true;
qtn.getChildren().set(index, newChild);
}
if (childMerged)
qtn.setUpFields();
if (qtn.type() == PlanNodeType.QUERY) {
qtn = transformerQuery((QueryNode) qtn, boolptr);
}
return qtn;
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class SubQueryProcessor method transformerQuery.
/**
* transformerQuery
*/
private static PlanNode transformerQuery(QueryNode query, BoolPtr boolptr) {
boolean canBeMerged = canBeMerged(query.getChild());
if (canBeMerged) {
// merge view node's property to view's child
PlanNode newNode = mergeNode(query, query.getChild());
boolptr.set(true);
return newNode;
} else {
return query;
}
}
use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.
the class PlanUtil method findColumnInTableLeaf.
/**
* check obj is the column of an real tablenode ,if obj is not Column Type return null
* <the column to be found must be table's parent's column>
*
* @param column column
* @param node node
* @return the target table node and the column
*/
public static Pair<TableNode, ItemField> findColumnInTableLeaf(ItemField column, PlanNode node) {
// union return
if (node.type() == PlanNodeType.MERGE)
return null;
NamedField tmpField = new NamedField(column.getTableName(), column.getItemName(), null);
NamedField coutField = node.getInnerFields().get(tmpField);
if (coutField == null)
return null;
else if (node.type() == PlanNodeType.TABLE) {
return new Pair<>((TableNode) node, column);
} else {
PlanNode referNode = column.getReferTables().iterator().next();
Item cSel = referNode.getOuterFields().get(coutField);
if (cSel instanceof ItemField) {
return findColumnInTableLeaf((ItemField) cSel, referNode);
} else {
return null;
}
}
}
Aggregations