Search in sources :

Example 6 with ItemFuncEqual

use of com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual in project dble by actiontech.

the class ERJoinChooser method visitJoinOns.

/**
 * visitJoinOns
 *
 * @param joinNode
 */
private void visitJoinOns(JoinNode joinNode) {
    for (PlanNode unit : joinUnits) {
        // is unit
        if (unit == joinNode) {
            return;
        }
    }
    for (ItemFuncEqual filter : joinNode.getJoinFilter()) {
        addJoinFilter(filter);
    }
    for (PlanNode child : joinNode.getChildren()) {
        if ((!isUnit(child)) && (child.type().equals(PlanNode.PlanNodeType.JOIN))) {
            // a join b on a.id=b.id and a.id+b.id=10 join c on
            // a.id=c.id,push up a.id+b.id
            JoinNode jnChild = (JoinNode) child;
            if (jnChild.getOtherJoinOnFilter() != null)
                otherJoinOns.add(jnChild.getOtherJoinOnFilter());
            visitJoinOns((JoinNode) child);
        }
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) JoinNode(com.actiontech.dble.plan.node.JoinNode) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)

Example 7 with ItemFuncEqual

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

Example 8 with ItemFuncEqual

use of com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual in project dble by actiontech.

the class MySQLPlanNodeVisitor method addJoinOnColumns.

private void addJoinOnColumns(Item ifilter, JoinNode joinNode) {
    if (ifilter instanceof ItemFuncEqual) {
        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) {
            joinNode.addJoinFilter(filter);
        } else {
            joinNode.setOtherJoinOnFilter(filter);
        }
    } else if (ifilter instanceof ItemCondAnd) {
        ItemCondAnd ilfand = (ItemCondAnd) ifilter;
        List<Item> subFilter = ilfand.arguments();
        if (subFilter != null) {
            for (Item arg : subFilter) {
                Item orgOtherJoin = joinNode.getOtherJoinOnFilter();
                addJoinOnColumns(arg, joinNode);
                joinNode.setOtherJoinOnFilter(FilterUtils.and(orgOtherJoin, joinNode.getOtherJoinOnFilter()));
            }
        } else {
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "and has no other columns , " + ifilter);
        }
    } else {
        joinNode.setOtherJoinOnFilter(ifilter);
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemCondAnd(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual) ItemField(com.actiontech.dble.plan.common.item.ItemField) ArrayList(java.util.ArrayList) List(java.util.List) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 9 with ItemFuncEqual

use of com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual in project dble by actiontech.

the class JoinNode method copy.

@Override
public JoinNode copy() {
    JoinNode newJoinNode = new JoinNode();
    this.copySelfTo(newJoinNode);
    newJoinNode.setJoinFilter(new ArrayList<ItemFuncEqual>());
    for (Item bf : joinFilter) {
        newJoinNode.addJoinFilter((ItemFuncEqual) bf.cloneStruct());
    }
    newJoinNode.setLeftNode(this.getLeftNode().copy());
    newJoinNode.setRightNode(this.getRightNode().copy());
    newJoinNode.setNeedOptimizeJoinOrder(this.isNeedOptimizeJoinOrder());
    newJoinNode.leftOuter = this.leftOuter;
    newJoinNode.rightOuter = this.rightOuter;
    newJoinNode.isNotIn = this.isNotIn;
    newJoinNode.otherJoinOnFilter = this.otherJoinOnFilter == null ? null : this.otherJoinOnFilter.cloneItem();
    return newJoinNode;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)

Example 10 with ItemFuncEqual

use of com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual in project dble by actiontech.

the class JoinNode method buildJoinKeys.

/**
 * setupJoinfilters
 *
 * @param clearName if true:clear filter's itemname,else keep
 */
private void buildJoinKeys(boolean clearName) {
    Iterator<ItemFuncEqual> iterator = joinFilter.iterator();
    while (iterator.hasNext()) {
        ItemFuncEqual bf = iterator.next();
        if (clearName)
            bf.setItemName(null);
        boolean isJoinKey = PlanUtil.isJoinKey(bf, this);
        if (!isJoinKey) {
            otherJoinOnFilter = FilterUtils.and(otherJoinOnFilter, bf);
            iterator.remove();
        }
    }
}
Also used : ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)

Aggregations

ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)14 Item (com.actiontech.dble.plan.common.item.Item)6 PlanNode (com.actiontech.dble.plan.node.PlanNode)6 JoinNode (com.actiontech.dble.plan.node.JoinNode)5 ItemField (com.actiontech.dble.plan.common.item.ItemField)4 ArrayList (java.util.ArrayList)4 Order (com.actiontech.dble.plan.Order)2 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)2 ERTable (com.actiontech.dble.config.model.ERTable)1 ItemCondAnd (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd)1 QueryNode (com.actiontech.dble.plan.node.QueryNode)1 TableNode (com.actiontech.dble.plan.node.TableNode)1 SQLOrderingSpecification (com.alibaba.druid.sql.ast.SQLOrderingSpecification)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1