use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ERJoinChooser method initJoinKeyInfo.
/**
* init sellis's JoinKeyInfo,JoinKeyInfo only has key selList when just build ,
* set values for them
*/
private void initJoinKeyInfo() {
for (List<JoinKeyInfo> selList : selLists) {
for (JoinKeyInfo jki : selList) {
for (PlanNode tn : joinUnits) {
Item tmpSel = nodeHasSelectable(tn, jki.key);
if (tmpSel != null) {
jki.tn = tn;
jki.cm = getERKey(tn, tmpSel);
break;
}
}
}
}
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ERJoinChooser method nodeHasSelectable.
private Item nodeHasSelectable(PlanNode child, Item sel) {
if (sel instanceof ItemField) {
return nodeHasColumn(child, (ItemField) sel);
} else if (sel.canValued()) {
return sel;
} else if (sel.type().equals(Item.ItemType.SUM_FUNC_ITEM)) {
return null;
} else {
ItemFunc fcopy = (ItemFunc) sel.cloneStruct();
for (int index = 0; index < fcopy.getArgCount(); index++) {
Item arg = fcopy.arguments().get(index);
Item argSel = nodeHasSelectable(child, arg);
if (argSel == null)
return null;
else
fcopy.arguments().set(index, argSel);
}
PlanUtil.refreshReferTables(fcopy);
fcopy.setPushDownName(null);
return fcopy;
}
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ERJoinChooser method addJoinFilter.
/**
* parser joinfilter ,add key to selLists
*
* @param filter
*/
private void addJoinFilter(ItemFuncEqual filter) {
Item left = filter.arguments().get(0);
Item right = filter.arguments().get(1);
JoinKeyInfo jiLeft = new JoinKeyInfo(left);
JoinKeyInfo jiRight = new JoinKeyInfo(right);
for (int i = 0; i < selLists.size(); i++) {
List<JoinKeyInfo> equalSelectables = selLists.get(i);
if (equalSelectables.contains(jiLeft)) {
addANewKey(jiRight, i);
return;
} else if (equalSelectables.contains(jiRight)) {
addANewKey(jiLeft, i);
return;
}
}
ArrayList<JoinKeyInfo> equalSelectables = new ArrayList<>();
equalSelectables.add(jiLeft);
equalSelectables.add(jiRight);
selLists.add(equalSelectables);
for (int i = selLists.size() - 1; i > -1; i--) {
List<JoinKeyInfo> list = selLists.get(i);
if (list.size() == 0)
selLists.remove(i);
}
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class FilterJoinColumnPusher method isPossibleERJoinColumnFilter.
/**
* is ER Filter: 1.Filter must be equal(=) 2.Filter must be Column = Column
* 3.Filter's key and value must be belong different table ex:a.id=b.id true a.id=b.id+1 false
*/
private static boolean isPossibleERJoinColumnFilter(PlanNode node, Item ifilter) {
if (!(ifilter instanceof ItemFuncEqual))
return false;
ItemFuncEqual filter = (ItemFuncEqual) ifilter;
Item column = filter.arguments().get(0);
Item value = filter.arguments().get(1);
if (column != null && column instanceof ItemField && value != null && value instanceof ItemField) {
Pair<TableNode, ItemField> foundColumn = PlanUtil.findColumnInTableLeaf((ItemField) column, node);
Pair<TableNode, ItemField> foundValue = PlanUtil.findColumnInTableLeaf((ItemField) value, node);
if (foundColumn != null && foundValue != null) {
String columnTable = foundColumn.getValue().getTableName();
String valueTable = foundValue.getValue().getTableName();
// the table must be different
return !StringUtils.equals(columnTable, valueTable);
} else {
return false;
}
} else {
return false;
}
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class FilterJoinColumnPusher method pushFilter.
private static PlanNode pushFilter(PlanNode qtn, List<Item> dnfNodeToPush) {
// the leaf node receive filter as where , or merge the current where and push down
if (qtn.getChildren().isEmpty()) {
Item node = FilterUtils.and(dnfNodeToPush);
if (node != null) {
qtn.query(FilterUtils.and(qtn.getWhereFilter(), node));
}
return qtn;
}
Item filterInWhere = qtn.getWhereFilter();
// left/right join: where filter can't be push to child
if (filterInWhere != null && (!(qtn.type() == PlanNode.PlanNodeType.JOIN) || ((JoinNode) qtn).isInnerJoin())) {
List<Item> splits = FilterUtils.splitFilter(filterInWhere);
List<Item> nonJoinFilter = new ArrayList<>();
for (Item filter : splits) {
if (!isPossibleERJoinColumnFilter(qtn, filter)) {
nonJoinFilter.add(filter);
} else {
dnfNodeToPush.add(filter);
}
}
if (nonJoinFilter.size() != splits.size()) {
// rollbakc nonJoinFilter
qtn.query(FilterUtils.and(nonJoinFilter));
}
}
PlanNode.PlanNodeType i = qtn.type();
if (i == PlanNode.PlanNodeType.QUERY) {
return pushQueryNodeFilter(qtn, dnfNodeToPush);
} else if (i == PlanNode.PlanNodeType.JOIN) {
return pushJoinNodeFilter(qtn, dnfNodeToPush);
} else if (i == PlanNode.PlanNodeType.MERGE) {
return pushMergeNodeFilter(qtn);
}
return qtn;
}
Aggregations