Search in sources :

Example 76 with Item

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);
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item)

Example 77 with Item

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;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) JoinNode(com.actiontech.dble.plan.node.JoinNode) ArrayList(java.util.ArrayList)

Example 78 with Item

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;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)

Example 79 with Item

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;
}
Also used : ItemCondAnd(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd) ItemCondOr(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondOr) Item(com.actiontech.dble.plan.common.item.Item)

Example 80 with Item

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;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) SQLAggregateExpr(com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)

Aggregations

Item (com.actiontech.dble.plan.common.item.Item)122 ArrayList (java.util.ArrayList)26 Order (com.actiontech.dble.plan.Order)16 PlanNode (com.actiontech.dble.plan.node.PlanNode)14 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)10 ItemField (com.actiontech.dble.plan.common.item.ItemField)10 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)7 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)7 Test (org.junit.Test)7 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)6 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)6 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)6 JoinNode (com.actiontech.dble.plan.node.JoinNode)6 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)6 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)5 ItemInt (com.actiontech.dble.plan.common.item.ItemInt)4 ItemString (com.actiontech.dble.plan.common.item.ItemString)4 BigDecimal (java.math.BigDecimal)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)3 NamedField (com.actiontech.dble.plan.NamedField)3