Search in sources :

Example 51 with Item

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

Example 52 with Item

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

Example 53 with Item

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

Example 54 with Item

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;
    }
}
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 55 with Item

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

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