Search in sources :

Example 1 with TempTableHandler

use of com.actiontech.dble.backend.mysql.nio.handler.query.impl.TempTableHandler in project dble by actiontech.

the class JoinNodeHandlerBuilder method buildPre.

@Override
public List<DMLResponseHandler> buildPre() {
    List<DMLResponseHandler> pres = new ArrayList<>();
    PlanNode left = node.getLeftNode();
    PlanNode right = node.getRightNode();
    if (node.getStrategy() == JoinNode.Strategy.NESTLOOP) {
        final boolean isLeftSmall = left.getNestLoopFilters() == null;
        final PlanNode tnSmall = isLeftSmall ? left : right;
        final PlanNode tnBig = isLeftSmall ? right : left;
        // prepare the column for sending
        List<Item> keySources = isLeftSmall ? node.getLeftKeys() : node.getRightKeys();
        List<Item> keyToPasses = isLeftSmall ? node.getRightKeys() : node.getLeftKeys();
        // just find one key as filter later, try to choose a simple column(FIELD_ITEM) from toPasses
        int columnIndex = 0;
        for (int index = 0; index < keyToPasses.size(); index++) {
            Item keyToPass = keyToPasses.get(index);
            if (keyToPass.type().equals(ItemType.FIELD_ITEM)) {
                columnIndex = index;
                break;
            }
        }
        final Item keySource = keySources.get(columnIndex);
        final Item keyToPass = keyToPasses.get(columnIndex);
        DMLResponseHandler endHandler = buildJoinChild(tnSmall, isLeftSmall);
        final TempTableHandler tempHandler = new TempTableHandler(getSequenceId(), session, keySource);
        endHandler.setNextHandler(tempHandler);
        tempHandler.setLeft(isLeftSmall);
        pres.add(tempHandler);
        CallBackHandler tempDone = new CallBackHandler() {

            @Override
            public void call() throws Exception {
                Set<String> valueSet = tempHandler.getValueSet();
                buildNestFilters(tnBig, keyToPass, valueSet, tempHandler.getMaxPartSize());
                DMLResponseHandler bigLh = buildJoinChild(tnBig, !isLeftSmall);
                synchronized (tempHandler) {
                    bigLh.setNextHandler(tempHandler.getNextHandler());
                }
                tempHandler.setCreatedHandler(bigLh);
                HandlerBuilder.startHandler(bigLh);
            }
        };
        if (isExplain) {
            buildNestFiltersForExplain(tnBig, keyToPass);
            DMLResponseHandler bigLh = buildJoinChild(tnBig, !isLeftSmall);
            tempHandler.setCreatedHandler(bigLh);
        }
        tempHandler.setTempDoneCallBack(tempDone);
    } else if (node.getStrategy() == JoinNode.Strategy.SORTMERGE) {
        DMLResponseHandler lh = buildJoinChild(left, true);
        pres.add(lh);
        DMLResponseHandler rh = buildJoinChild(right, false);
        pres.add(rh);
    } else {
        throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "strategy [" + node.getStrategy() + "] not implement yet!");
    }
    return pres;
}
Also used : ArrayList(java.util.ArrayList) TempTableHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.TempTableHandler) ItemString(com.actiontech.dble.plan.common.item.ItemString) Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) CallBackHandler(com.actiontech.dble.backend.mysql.nio.handler.util.CallBackHandler) DMLResponseHandler(com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Aggregations

DMLResponseHandler (com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler)1 TempTableHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.TempTableHandler)1 CallBackHandler (com.actiontech.dble.backend.mysql.nio.handler.util.CallBackHandler)1 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)1 Item (com.actiontech.dble.plan.common.item.Item)1 ItemString (com.actiontech.dble.plan.common.item.ItemString)1 PlanNode (com.actiontech.dble.plan.node.PlanNode)1 ArrayList (java.util.ArrayList)1