Search in sources :

Example 66 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class MySQLPlanNodeVisitor method handleWhereCondition.

private void handleWhereCondition(SQLExpr whereExpr) {
    MySQLItemVisitor mev = new MySQLItemVisitor(this.currentDb, this.charsetIndex, this.metaManager);
    whereExpr.accept(mev);
    if (this.tableNode != null) {
        Item whereFilter = mev.getItem();
        tableNode.query(whereFilter);
        if (whereFilter.isWithSubQuery()) {
            tableNode.setSubQuery(true);
            tableNode.setCorrelatedSubQuery(whereFilter.isCorrelatedSubQuery());
        }
    } else {
        throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "from expression is null,check the sql!");
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 67 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class MySQLPlanNodeVisitor method handleSelectItems.

private List<Item> handleSelectItems(List<SQLSelectItem> items) {
    List<Item> selectItems = new ArrayList<>();
    for (SQLSelectItem item : items) {
        SQLExpr expr = item.getExpr();
        MySQLItemVisitor ev = new MySQLItemVisitor(currentDb, this.charsetIndex, this.metaManager);
        expr.accept(ev);
        Item selItem = ev.getItem();
        if (selItem.isWithSubQuery()) {
            setSubQueryNode(selItem);
        }
        selItem.setAlias(item.getAlias());
        if (isSubQuery && selItem.getAlias() == null) {
            selItem.setAlias("autoalias_scalar");
        }
        selectItems.add(selItem);
    }
    return selectItems;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ArrayList(java.util.ArrayList)

Example 68 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class FilterPusher method refreshPdFilters.

private static void refreshPdFilters(PlanNode qtn, List<Item> filters) {
    for (int index = 0; index < filters.size(); index++) {
        Item toPsFilter = filters.get(index);
        Item pdFilter = PlanUtil.pushDownItem(qtn, toPsFilter);
        filters.set(index, pdFilter);
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item)

Example 69 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class FilterPusher method mergeJoinOnFilter.

/**
 * merge inner joi's otheron to where if we can
 *
 * @param qtn
 * @return
 */
private static void mergeJoinOnFilter(PlanNode qtn) {
    if (PlanUtil.isGlobalOrER(qtn))
        return;
    if (qtn.type().equals(PlanNodeType.JOIN) && ((JoinNode) qtn).isInnerJoin()) {
        JoinNode jn = (JoinNode) qtn;
        Item otherJoinOn = jn.getOtherJoinOnFilter();
        jn.setOtherJoinOnFilter(null);
        jn.query(FilterUtils.and(otherJoinOn, jn.getWhereFilter()));
    }
    for (PlanNode child : qtn.getChildren()) {
        mergeJoinOnFilter(child);
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) JoinNode(com.actiontech.dble.plan.node.JoinNode)

Example 70 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class FilterPusher method getMergeNode.

private static PlanNode getMergeNode(PlanNode qtn, List<Item> dnfNodeToPush) {
    // union's where can be pushed down ,but it must be replace to child's condition
    Item node = FilterUtils.and(dnfNodeToPush);
    if (node != null) {
        qtn.query(FilterUtils.and(qtn.getWhereFilter(), node));
    }
    Item mergeWhere = qtn.getWhereFilter();
    // push down merge's condition
    qtn.query(null);
    List<Item> pushFilters = PlanUtil.getPushItemsToUnionChild((MergeNode) qtn, mergeWhere, ((MergeNode) qtn).getColIndexs());
    List<PlanNode> childs = qtn.getChildren();
    for (int index = 0; index < childs.size(); index++) {
        PlanNode child = childs.get(index);
        if (pushFilters != null) {
            Item pushFilter = pushFilters.get(index);
            child.query(FilterUtils.and(child.getWhereFilter(), pushFilter));
        }
        FilterPusher.optimize(child);
    }
    return qtn;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode)

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