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;
}
Aggregations