use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class PlanNode method copySelfTo.
protected final void copySelfTo(PlanNode to) {
to.setAlias(this.alias);
to.setDistinct(this.isDistinct);
for (Item selected : this.getColumnsSelected()) {
Item copySel = selected.cloneItem();
copySel.setItemName(selected.getItemName());
to.columnsSelected.add(copySel);
}
for (Order groupBy : this.getGroupBys()) {
to.groups.add(groupBy.copy());
}
for (Order orderBy : this.getOrderBys()) {
to.orderBys.add(orderBy.copy());
}
to.whereFilter = this.whereFilter == null ? null : this.whereFilter.cloneItem();
to.havingFilter = this.havingFilter == null ? null : havingFilter.cloneItem();
to.setLimitFrom(this.limitFrom);
to.setLimitTo(this.limitTo);
to.setSql(this.getSql());
to.setSubQuery(subQuery);
to.setCorrelatedSubQuery(correlatedSubQuery);
to.setUnGlobalTableCount(unGlobalTableCount);
to.setNoshardNode(noshardNode);
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ERJoinChooser method innerJoinOptimizer.
/* ------------------- left join optimizer end -------------------- */
/**
* inner join's ER, rebuild inner joi's unit
*
* @return
*/
private JoinNode innerJoinOptimizer() {
initInnerJoinUnits(jn);
if (joinUnits.size() == 1) {
return jn;
}
visitJoinOns(jn);
initJoinKeyInfo();
while (trySelListIndex < selLists.size()) {
List<JoinKeyInfo> selList = selLists.get(trySelListIndex);
JoinNode erJoinNode = tryMakeERJoin(selList);
if (erJoinNode == null) {
trySelListIndex++;
} else {
// re scanning
this.makedERJnList.add(erJoinNode);
}
}
if (makedERJnList.isEmpty())
// no er join
return jn;
List<PlanNode> others = new ArrayList<>();
// make makedErJnList at the beginning,join with ER
others.addAll(makedERJnList);
others.addAll(joinUnits);
for (int i = 0; i < others.size(); i++) {
// make up the unit which cna;t optimized and global table
PlanNode tnewOther = others.get(i);
PlanNode newT0 = joinWithGlobal(tnewOther, globals);
others.set(i, newT0);
}
// only others and globals may have node and have been tried to ER JOIN
if (globals.size() > 0) {
PlanNode globalJoin = makeJoinNode(globals);
others.add(globalJoin);
}
// others' node is the join units which can not optimize, just merge them
JoinNode ret = (JoinNode) makeJoinNode(others);
ret.setOrderBys(jn.getOrderBys());
ret.setGroupBys(jn.getGroupBys());
ret.select(jn.getColumnsSelected());
ret.setLimitFrom(jn.getLimitFrom());
ret.setLimitTo(jn.getLimitTo());
ret.setOtherJoinOnFilter(FilterUtils.and(jn.getOtherJoinOnFilter(), FilterUtils.and(otherJoinOns)));
Item unFoundSelFilter = makeRestFilter();
if (unFoundSelFilter != null)
ret.setOtherJoinOnFilter(FilterUtils.and(ret.getOtherJoinOnFilter(), unFoundSelFilter));
// and the origin where and the remain condition in selLists
ret.having(jn.getHavingFilter());
ret.setWhereFilter(jn.getWhereFilter());
ret.setAlias(jn.getAlias());
ret.setSubQuery(jn.isSubQuery());
ret.setSql(jn.getSql());
ret.setUpFields();
return ret;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ERJoinChooser method makeRestFilter.
/**
* the origin filter is join on filter
* ,now join is changed ,and the filter is not join filter any more ,add it to other join on
*
* @return
*/
private Item makeRestFilter() {
Item filter = null;
for (List<JoinKeyInfo> selList : selLists) {
if (selList.size() > 2) {
Item sel0 = selList.get(0).key;
for (int index = 1; index < selList.size(); index++) {
ItemFuncEqual bf = FilterUtils.equal(sel0, selList.get(index).key);
filter = FilterUtils.and(filter, bf);
}
}
}
return filter;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class FilterPreProcessor method convertOrToIn.
/**
* change single Logicalfilter(or) into in
*
* @param filter
*/
private static Item convertOrToIn(Item filter) {
if (filter == null)
return null;
if (filter.type().equals(Item.ItemType.COND_ITEM)) {
if (filter instanceof ItemCondAnd) {
ItemCondAnd andFilter = (ItemCondAnd) filter;
for (int index = 0; index < andFilter.getArgCount(); index++) {
andFilter.arguments().set(index, convertOrToIn(andFilter.arguments().get(index)));
}
andFilter.setItemName(null);
PlanUtil.refreshReferTables(andFilter);
return andFilter;
} else {
// or
ItemCondOr orFilter = (ItemCondOr) filter;
HashMap<Item, Set<Item>> inMap = new HashMap<>();
List<Item> newSubFilterList = new ArrayList<>();
for (int index = 0; index < orFilter.getArgCount(); index++) {
Item subFilter = orFilter.arguments().get(index);
if (subFilter == null)
continue;
if (subFilter instanceof ItemFuncEqual) {
Item a = subFilter.arguments().get(0);
Item b = subFilter.arguments().get(1);
if (!a.canValued() && b.canValued()) {
if (!inMap.containsKey(a))
inMap.put(a, new HashSet<Item>());
inMap.get(a).add(b);
} else {
// stop convert
return filter;
}
} else {
Item subNew = convertOrToIn(subFilter);
newSubFilterList.add(subNew);
}
}
for (Map.Entry<Item, Set<Item>> entry : inMap.entrySet()) {
List<Item> args = new ArrayList<>();
args.add(entry.getKey());
args.addAll(entry.getValue());
ItemFuncIn inItem = new ItemFuncIn(args, false);
PlanUtil.refreshReferTables(inItem);
newSubFilterList.add(inItem);
}
return FilterUtils.or(newSubFilterList);
}
}
return filter;
}
use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.
the class ItemSumMax method toExpression.
@Override
public SQLExpr toExpression() {
Item arg0 = args.get(0);
SQLAggregateExpr aggregate = new SQLAggregateExpr(funcName());
aggregate.addArgument(arg0.toExpression());
return aggregate;
}
Aggregations