當前位置: 首頁>>代碼示例>>Java>>正文


Java JoinNode.getJoinStrategy方法代碼示例

本文整理匯總了Java中com.taobao.tddl.optimizer.core.ast.query.JoinNode.getJoinStrategy方法的典型用法代碼示例。如果您正苦於以下問題:Java JoinNode.getJoinStrategy方法的具體用法?Java JoinNode.getJoinStrategy怎麽用?Java JoinNode.getJoinStrategy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.taobao.tddl.optimizer.core.ast.query.JoinNode的用法示例。


在下文中一共展示了JoinNode.getJoinStrategy方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: estimate

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的package包/類
public Cost estimate(QueryTreeNode query) {
    JoinNode join = (JoinNode) query;

    Cost leftCost = CostEsitimaterFactory.estimate(join.getLeftNode());
    Cost rightCost = CostEsitimaterFactory.estimate(join.getRightNode());
    Cost cost = new Cost();
    cost.setIsOnFly(true);
    long rowCount = 0;
    long networkCost = 0;
    long scanRowCount = 0;
    boolean isOnFly = true;

    // 估算IO開銷
    if (rightCost.isOnFly()) {
        cost.setDiskIO(leftCost.getDiskIO() + rightCost.getDiskIO());
    } else {
        cost.setDiskIO(leftCost.getDiskIO() + leftCost.getRowCount());
    }
    // 估算行數
    // 現在假定join後的行數為較小表的行數,這個假設對於大多數場景都是成立的
    if (leftCost.getRowCount() < rightCost.getRowCount()) {
        rowCount = (leftCost.getRowCount());
    } else {
        rowCount = (rightCost.getRowCount());
    }

    // 估算網絡開銷
    if (join.getDataNode() != null) {
        if (!join.getDataNode().equals(join.getLeftNode().getDataNode())) {
            networkCost += leftCost.getRowCount();
        }
        if (!join.getDataNode().equals(join.getRightNode().getDataNode())) {
            networkCost += rightCost.getRowCount();
        }
    }

    // 如果是IndexNestLoop,則數據還在磁盤上
    if (join.getJoinStrategy() == JoinStrategy.INDEX_NEST_LOOP) {
        cost.setDiskIO(leftCost.getRowCount());
        isOnFly = false;
        scanRowCount = leftCost.getScanCount() + rightCost.getScanCount();
    } else {
        // sort merge
        // 右邊的先要拿出數據
        // 再要將符合的數據插到臨時表
        // 所以等於是兩次
        scanRowCount = leftCost.getScanCount() + rightCost.getScanCount() * 2 + rightCost.getRowCount();
    }

    if (query.getLimitFrom() != null && query.getLimitTo() != null) {
        Object from = query.getLimitFrom();
        if (from instanceof IBindVal) {
            from = ((IBindVal) from).getValue();
        }
        Object to = query.getLimitTo();
        if (to instanceof IBindVal) {
            to = ((IBindVal) from).getValue();
        }
        if (from instanceof Long && to instanceof Long) {
            rowCount = ((Long) query.getLimitTo() - (Long) query.getLimitFrom());
        }
    } else if (query.getLimitFrom() != null || query.getLimitTo() != null) {
        rowCount = rowCount / 2;
    }

    cost.setNetworkCost(networkCost);
    cost.setRowCount(rowCount);
    cost.setIsOnFly(isOnFly);
    cost.setScanCount(scanRowCount);
    return cost;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:72,代碼來源:JoinNodeCostEstimater.java

示例2: estimate

import com.taobao.tddl.optimizer.core.ast.query.JoinNode; //導入方法依賴的package包/類
public Cost estimate(QueryTreeNode query) throws StatisticsUnavailableException {
    JoinNode join = (JoinNode) query;

    Cost leftCost = CostEsitimaterFactory.estimate(join.getLeftNode());
    Cost rightCost = CostEsitimaterFactory.estimate(join.getRightNode());
    Cost cost = new Cost();
    cost.setIsOnFly(true);
    long rowCount = 0;
    long networkCost = 0;
    long scanRowCount = 0;
    boolean isOnFly = true;

    // 估算IO開銷
    if (rightCost.isOnFly()) {
        cost.setDiskIO(leftCost.getDiskIO() + rightCost.getDiskIO());
    } else {
        cost.setDiskIO(leftCost.getDiskIO() + leftCost.getRowCount());
    }
    // 估算行數
    // 現在假定join後的行數為較小表的行數,這個假設對於大多數場景都是成立的
    if (leftCost.getRowCount() < rightCost.getRowCount()) {
        rowCount = (leftCost.getRowCount());
    } else {
        rowCount = (rightCost.getRowCount());
    }

    // 估算網絡開銷
    if (join.getDataNode() != null) {
        if (!join.getDataNode().equals(join.getLeftNode().getDataNode())) {
            networkCost += leftCost.getRowCount();
        }
        if (!join.getDataNode().equals(join.getRightNode().getDataNode())) {
            networkCost += rightCost.getRowCount();
        }
    }

    // 如果是IndexNestLoop,則數據還在磁盤上
    if (join.getJoinStrategy() == JoinStrategy.INDEX_NEST_LOOP) {
        cost.setDiskIO(leftCost.getRowCount());
        isOnFly = false;
        scanRowCount = leftCost.getScanCount() + rightCost.getScanCount();
    } else {
        // sort merge
        // 右邊的先要拿出數據
        // 再要將符合的數據插到臨時表
        // 所以等於是兩次
        scanRowCount = leftCost.getScanCount() + rightCost.getScanCount() * 2 + rightCost.getRowCount();
    }

    if (query.getLimitFrom() != null
        && (query.getLimitFrom() instanceof Long || query.getLimitFrom() instanceof Long)
        && (Long) query.getLimitFrom() != 0 && query.getLimitTo() != null
        && (query.getLimitTo() instanceof Long || query.getLimitTo() instanceof Long)
        && (Long) query.getLimitTo() != 0) {
        rowCount = ((Long) query.getLimitTo() - (Long) query.getLimitFrom());
    } else if (query.getLimitFrom() != null || query.getLimitTo() != null) {
        rowCount = rowCount / 2;
    }

    cost.setNetworkCost(networkCost);
    cost.setRowCount(rowCount);
    cost.setIsOnFly(isOnFly);
    cost.setScanCount(scanRowCount);
    return cost;
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:66,代碼來源:JoinNodeCostEstimater.java


注:本文中的com.taobao.tddl.optimizer.core.ast.query.JoinNode.getJoinStrategy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。