Examples of TableGroupJoinNode


Examples of com.foundationdb.sql.optimizer.plan.TableGroupJoinTree.TableGroupJoinNode

    // We have done out best with the inner joins to make this possible,
    // but some outer joins may require that a TableGroup be broken up into
    // multiple TableJoins.
    protected void isolateGroups(List<JoinIsland> islands) {
        for (JoinIsland island : islands) {
            TableGroupJoinNode tree = isolateGroupJoins(island.root);
            if (tree != null) {
                Joinable nroot = groupJoinTree(tree, island.root);
                island.output.replaceInput(island.root, nroot);
                island.root = nroot;
            }
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.TableGroupJoinTree.TableGroupJoinNode

    protected TableGroupJoinNode isolateGroupJoins(Joinable joinable) {
        if (joinable.isTable()) {
            TableSource table = (TableSource)joinable;
            assert (table.getGroup() != null);
            return new TableGroupJoinNode(table);
        }
        if (!joinable.isJoin())
            return null;
        JoinNode join = (JoinNode)joinable;
        Joinable left = join.getLeft();
        Joinable right = join.getRight();
        TableGroupJoinNode leftTree = isolateGroupJoins(left);
        TableGroupJoinNode rightTree = isolateGroupJoins(right);
        if ((leftTree != null) && (rightTree != null) &&
            // All tables below the two sides must be from the same group.
            (leftTree.getTable().getGroup() == rightTree.getTable().getGroup())) {
            // An outer join condition must be one that can be
            // done before flattening because after that it's too
            // late to get back the outer side if the test never
            // succeeds.
            boolean joinOK;
            switch (join.getJoinType()) {
            case INNER:
                joinOK = true;
                break;
            case LEFT:
                joinOK = checkJoinConditions(join.getJoinConditions(), leftTree, rightTree);
                break;
            case RIGHT:
                // Cannot allow any non-group conditions, since even
                // one only on parent would kill the child because
                // that's how Select_HKeyOrdered works.
                joinOK = checkJoinConditions(join.getJoinConditions(), null, leftTree);
                break;
            default:
                joinOK = false;
            }
            if (joinOK) {
                // Still need to be able to splice them together.
                TableGroupJoinNode tree;
                int leftDepth = leftTree.getTable().getTable().getDepth();
                int rightDepth = rightTree.getTable().getTable().getDepth();
                if (leftDepth < rightDepth)
                    tree = spliceGroupJoins(leftTree, rightTree, join.getJoinType());
                else if (rightDepth < leftDepth)
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.TableGroupJoinTree.TableGroupJoinNode

    // Combine trees at the proper branch point.
    protected TableGroupJoinNode spliceGroupJoins(TableGroupJoinNode parent,
                                                  TableGroupJoinNode child,
                                                  JoinType joinType) {
        TableGroupJoinNode branch = parent.findTable(child.getTable().getParentTable());
        if (branch == null)
            return null;
        child.setParent(branch);
        child.setParentJoinType(joinType);
        TableGroupJoinNode prev = null;
        while (true) {
            TableGroupJoinNode next = (prev == null) ? branch.getFirstChild() : prev.getNextSibling();
            if ((next == null) ||
                (next.getTable().getTable().getOrdinal() > child.getTable().getTable().getOrdinal())) {
                child.setNextSibling(next);
                if (prev == null)
                    branch.setFirstChild(child);
                else
                    prev.setNextSibling(child);
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.TableGroupJoinTree.TableGroupJoinNode

     * fetching the given tables, then joining them with Flatten and
     * Product. */
    public CostEstimate costFlatten(TableGroupJoinTree tableGroup,
                                    TableSource indexTable,
                                    Set<TableSource> requiredTables) {
        TableGroupJoinNode startNode = tableGroup.getRoot().findTable(indexTable);
        coverBranches(tableGroup, startNode, requiredTables);
        long rowCount = 1;
        double cost = 0.0;
        List<TableRowType> ancestorTypes = new ArrayList<>();
        for (TableGroupJoinNode ancestorNode = startNode;
             ancestorNode != null;
             ancestorNode = ancestorNode.getParent()) {
            if (isRequired(ancestorNode)) {
                if ((ancestorNode == startNode) &&
                    (getSideBranches(ancestorNode) != 0)) {
                    continue;   // Branch, not ancestor.
                }
                ancestorTypes.add(schema.tableRowType(ancestorNode.getTable().getTable().getTable()));
            }
        }
        // Cost to get main branch.
        cost += model.ancestorLookup(ancestorTypes);
        for (TableGroupJoinNode branchNode : tableGroup) {
            if (isSideBranchLeaf(branchNode)) {
                int branch = Long.numberOfTrailingZeros(getBranches(branchNode));
                TableGroupJoinNode branchRoot = branchNode, nextToRoot = null;
                while (true) {
                    TableGroupJoinNode parent = branchRoot.getParent();
                    if (parent == startNode) {
                        // Different kind of BranchLookup.
                        nextToRoot = branchRoot = parent;
                        break;
                    }
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.TableGroupJoinTree.TableGroupJoinNode

    /** Estimate the cost of starting from a group scan and joining
     * with Flatten and Product. */
    public CostEstimate costFlattenGroup(TableGroupJoinTree tableGroup,
                                         Set<TableSource> requiredTables) {
        TableGroupJoinNode rootNode = tableGroup.getRoot();
        coverBranches(tableGroup, rootNode, requiredTables);
        int branchCount = 0;
        long rowCount = 1;
        double cost = 0.0;
        for (TableGroupJoinNode node : tableGroup) {
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.TableGroupJoinTree.TableGroupJoinNode

     * rows from a group scan. This combined costing of the partial
     * scan itself and the flatten, since they are tied together. */
    public CostEstimate costPartialGroupScanAndFlatten(TableGroupJoinTree tableGroup,
                                                       Set<TableSource> requiredTables,
                                                       Map<Table,Long> tableCounts) {
        TableGroupJoinNode rootNode = tableGroup.getRoot();
        coverBranches(tableGroup, rootNode, requiredTables);
        int branchCount = 0;
        long rowCount = 1;
        double cost = 0.0;
        for (Map.Entry<Table,Long> entry : tableCounts.entrySet()) {
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.TableGroupJoinTree.TableGroupJoinNode

    public CostEstimate costFlattenNested(TableGroupJoinTree tableGroup,
                                          TableSource outsideTable,
                                          TableSource insideTable,
                                          boolean insideIsParent,
                                          Set<TableSource> requiredTables) {
        TableGroupJoinNode startNode = tableGroup.getRoot().findTable(insideTable);
        coverBranches(tableGroup, startNode, requiredTables);
        int branchCount = 0;
        long rowCount = 1;
        double cost = 0.0;
        if (insideIsParent) {
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.TableGroupJoinTree.TableGroupJoinNode

    /** Number of rows of given table, total per index row. */
    protected long tableCardinality(TableGroupJoinNode table) {
        if (isAncestor(table))
            return 1;
        TableGroupJoinNode parent = table;
        while (true) {
            parent = parent.getParent();
            if (isAncestor(parent))
                return descendantCardinality(table, parent);
        }
    }
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.TableGroupJoinTree.TableGroupJoinNode

    private boolean mightFlattenOrSort(TableSource table) {
        if (!(table.getOutput() instanceof TableGroupJoinTree))
            return true;        // Don't know; be conservative.
        TableGroupJoinTree tree = (TableGroupJoinTree)table.getOutput();
        TableGroupJoinNode root = tree.getRoot();
        if (root.getTable() != table)
            return true;
        if (root.getFirstChild() != null)
            return true;
        // Only table in this join tree, shouldn't flatten.
        PlanNode output = tree;
        do {
            output = output.getOutput();
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.TableGroupJoinTree.TableGroupJoinNode

            tableGroup.getOutput().replaceInput(tableGroup, joins);
        }
    }

    protected PlanNode joinBranches(TableGroupJoinTree tableGroup) {
        TableGroupJoinNode rootTable = tableGroup.getRoot();
        PlanNode scan = tableGroup.getScan();
        if (scan instanceof IndexScan) {
            IndexScan indexScan = (IndexScan)scan;
            if (indexScan.isCovering())
                return indexScan;
        }
        Set<TableSource> requiredTables = null;
        if (scan instanceof BaseScan) {
            requiredTables = ((BaseScan)scan).getRequiredTables();
        }
        markBranches(tableGroup, requiredTables);
        top:
        if (scan instanceof JoinTreeScan) {
            TableSource indexTable = ((JoinTreeScan)scan).getLeafMostTable();
            TableGroupJoinNode leafTable = rootTable.findTable(indexTable);
            assert (leafTable != null) : scan;
            List<TableSource> ancestors = new ArrayList<>();
            pendingTableSources(leafTable, rootTable, ancestors);
            if (isParent(leafTable)) {
                if (ancestors.remove(indexTable))
                    setPending(leafTable); // Changed from ancestor to branch.
                List<TableSource> tables = new ArrayList<>();
                scan = new BranchLookup(scan, indexTable.getTable(), tables);
                leafTable = singleBranchPending(leafTable, tables);
            }
            else if (!isRequired(leafTable)) {
                // Don't need the table that the index points to or
                // anything beneath it; might be able to jump to a
                // side branch.
                PlanNode sideScan = trySideBranch(scan, leafTable, rootTable,
                                                  indexTable, ancestors);
                if (sideScan != null) {
                    scan = sideScan;
                    break top;
                }
            }
            if (!ancestors.isEmpty())
                scan = new AncestorLookup(scan, indexTable, ancestors);
            scan = flatten(scan, leafTable, rootTable);
            scan = fillSideBranches(scan, leafTable, rootTable);
        }
        else if (scan instanceof GroupScan) {
            GroupScan groupScan = (GroupScan)scan;
            List<TableSource> tables = new ArrayList<>();
            groupScan.setTables(tables);
            scan = fillBranch(scan, tables, rootTable, rootTable, rootTable);
        }
        else if (scan instanceof GroupLoopScan) {
            GroupLoopScan groupLoop = (GroupLoopScan)scan;
            TableSource outsideTable = groupLoop.getOutsideTable();
            TableSource insideTable = groupLoop.getInsideTable();
            if (groupLoop.isInsideParent()) {
                TableGroupJoinNode parent = rootTable.findTable(groupLoop.getInsideTable());
                assert (parent != null) : groupLoop;
                List<TableSource> ancestors = new ArrayList<>();
                pendingTableSources(parent, rootTable, ancestors);
                scan = new AncestorLookup(scan, outsideTable, ancestors);
                scan = flatten(scan, parent, rootTable);
                scan = fillGroupLoopBranches(scan, parent, rootTable);
            }
            else {
                assert (groupLoop.getInsideTable() == rootTable.getTable());
                List<TableSource> tables = new ArrayList<>();
                scan = new BranchLookup(scan, outsideTable.getTable(), insideTable.getTable(), tables);
                scan = fillBranch(scan, tables, rootTable, rootTable, rootTable);
            }
        }
        else if (scan instanceof FullTextScan) {
            FullTextScan textScan = (FullTextScan)scan;
            TableSource indexSource = textScan.getIndexTable();
            TableGroupJoinNode indexTable = rootTable.findTable(indexSource);
            assert (indexTable != null) : textScan;
            List<TableSource> ancestors = new ArrayList<>();
            pendingTableSources(indexTable, rootTable, ancestors);
            if (isParent(indexTable)) {
                if (ancestors.remove(indexSource))
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.