Examples of PlanNode


Examples of org.teiid.query.optimizer.relational.plantree.PlanNode

    JoinType joinType = (JoinType)joinNode.getProperty(Info.JOIN_TYPE);
    if (joinType != JoinType.JOIN_INNER) {
      return root;
    }

    PlanNode left = joinNode.getFirstChild();
    if (left.getType() != NodeConstants.Types.SOURCE) {
      return root;
    }
   
    Map<ElementSymbol, List<Set<Constant>>> partitionInfo = (Map<ElementSymbol, List<Set<Constant>>>)left.getProperty(Info.PARTITION_INFO);
   
    if (partitionInfo == null) {
      return root;
    }

    PlanNode unionNode = left.getFirstChild();
    if (unionNode.getType() != NodeConstants.Types.SET_OP) {
      return root;
    }
   
    PlanNode right = joinNode.getLastChild();
   
    if (right.getType() != NodeConstants.Types.SOURCE) {
      return root;
    }
   
    Map<ElementSymbol, List<Set<Constant>>> rightPartionInfo = (Map<ElementSymbol, List<Set<Constant>>>)right.getProperty(Info.PARTITION_INFO);
   
    if (rightPartionInfo == null) {
      return root;
    }
   
    List<Criteria> criteria = (List<Criteria>)joinNode.getProperty(Info.JOIN_CRITERIA);
   
    List<Expression> expr = new ArrayList<Expression>();
    List<Expression> exprOther = new ArrayList<Expression>();
    RuleChooseJoinStrategy.separateCriteria(unionNode.getParent().getGroups(), right.getGroups(), expr, exprOther, criteria, new LinkedList<Criteria>());
   
    if (expr.isEmpty()) {
      return root; //no equi-join
    }
   
    List<int[]> matches = findMatches(partitionInfo, rightPartionInfo, expr, exprOther);
   
    if (matches == null) {
      return root; //no non-overlapping partitions
    }

    int branchSize = partitionInfo.values().iterator().next().size();
    int otherBranchSize = rightPartionInfo.values().iterator().next().size();
   
    if (matches.isEmpty()) {
      //no matches mean that we can just insert a null node (false criteria) and be done with it
      PlanNode critNode = NodeFactory.getNewNode(NodeConstants.Types.SELECT);
      critNode.setProperty(Info.SELECT_CRITERIA, QueryRewriter.FALSE_CRITERIA);
      unionNode.addAsParent(critNode);
      return root;
    }
   
    List<PlanNode> branches = new ArrayList<PlanNode>();
    //TODO: find union children from RulePushAggregates
    RulePushSelectCriteria.collectUnionChildren(unionNode, branches);
   
    if (branches.size() != branchSize) {
      return root; //sanity check
    }
   
    List<PlanNode> otherBranches = new ArrayList<PlanNode>();
    RulePushSelectCriteria.collectUnionChildren(right.getFirstChild(), otherBranches);
   
    if (otherBranches.size() != otherBranchSize) {
      return root; //sanity check
    }

    PlanNode newUnion = buildUnion(unionNode, right, criteria, matches, branches, otherBranches);
    PlanNode view = rebuild(left.getGroups().iterator().next(), joinNode, newUnion, metadata, context, left, right);

    SymbolMap symbolmap = (SymbolMap)view.getProperty(Info.SYMBOL_MAP);
    HashMap<ElementSymbol, List<Set<Constant>>> newPartitionInfo = new LinkedHashMap<ElementSymbol, List<Set<Constant>>>();
    for (int[] match : matches) {
      updatePartitionInfo(partitionInfo, matches, symbolmap, newPartitionInfo, 0, match[0]);
      updatePartitionInfo(rightPartionInfo, matches, symbolmap, newPartitionInfo, partitionInfo.size(), match[1]);
    }
    view.setProperty(Info.PARTITION_INFO, newPartitionInfo);
 
    //since we've created a new union node, there's a chance we can decompose again
    return decomposeJoin(newUnion, root, metadata, context);
  }
View Full Code Here

Examples of org.teiid.query.optimizer.relational.plantree.PlanNode

          context.setGroups(groups);
        }
   
    group = RulePlaceAccess.recontextSymbol(group, groups);
   
    PlanNode projectNode = NodeEditor.findNodePreOrder(newUnion, NodeConstants.Types.PROJECT);
    List<? extends SingleElementSymbol> projectedSymbols = (List<? extends SingleElementSymbol>)projectNode.getProperty(Info.PROJECT_COLS);

    PlanNode view = RulePushAggregates.createView(group, projectedSymbols, newUnion, metadata);
   
    SymbolMap newSymbolMap = (SymbolMap)view.getProperty(Info.SYMBOL_MAP);
   
    Map<Expression, ElementSymbol> inverseMap = newSymbolMap.inserseMapping();
    toReplace.getParent().replaceChild(toReplace, view);
    Set<GroupSymbol> newGroups = Collections.singleton(group);
    for (PlanNode node : toMap) {
View Full Code Here

Examples of org.teiid.query.optimizer.relational.plantree.PlanNode

    SymbolMap otherSymbolMap = (SymbolMap)otherSide.getProperty(Info.SYMBOL_MAP);

    List<PlanNode> joins = new LinkedList<PlanNode>();
    for (int i = 0; i < matches.size(); i++) {
      int[] is = matches.get(i);
      PlanNode branch = branches.get(is[0]);
      PlanNode branchSource = createSource(unionNode.getParent().getGroups().iterator().next(), branch, symbolMap);
     
      PlanNode otherBranch = otherBranches.get(is[1]);
      PlanNode otherBranchSource = createSource(otherSide.getGroups().iterator().next(), otherBranch, otherSymbolMap);
     
      PlanNode newJoinNode = NodeFactory.getNewNode(NodeConstants.Types.JOIN);
      newJoinNode.addLastChild(branchSource);
      newJoinNode.addLastChild(otherBranchSource);
     
      newJoinNode.setProperty(Info.JOIN_STRATEGY, JoinStrategyType.NESTED_LOOP);
      newJoinNode.setProperty(Info.JOIN_TYPE, JoinType.JOIN_INNER);
      newJoinNode.setProperty(Info.JOIN_CRITERIA, LanguageObject.Util.deepClone(criteria, Criteria.class));
      newJoinNode.addGroups(branchSource.getGroups());
      newJoinNode.addGroups(otherBranchSource.getGroups());
     
      PlanNode projectPlanNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
      newJoinNode.addAsParent(projectPlanNode);
     
      Select allSymbols = new Select(symbolMap.getKeys());
      allSymbols.addSymbols(otherSymbolMap.getKeys());
      if (i == 0) {
        QueryRewriter.makeSelectUnique(allSymbols, false);
      }
      projectPlanNode.setProperty(NodeConstants.Info.PROJECT_COLS, allSymbols.getSymbols());
          projectPlanNode.addGroups(newJoinNode.getGroups());
     
      joins.add(projectPlanNode);
    }
   
    PlanNode newUnion = RulePlanUnions.buildUnionTree(unionNode, joins);
    return newUnion;
  }
View Full Code Here

Examples of org.teiid.query.optimizer.relational.plantree.PlanNode

    PlanNode newUnion = RulePlanUnions.buildUnionTree(unionNode, joins);
    return newUnion;
  }

  static PlanNode createSource(GroupSymbol group, PlanNode unionNode, SymbolMap symbolMap) {
    PlanNode branchSource = NodeFactory.getNewNode(NodeConstants.Types.SOURCE);
    branchSource.addGroup(group);
    PlanNode projectNode = NodeEditor.findNodePreOrder(unionNode, NodeConstants.Types.PROJECT);
    branchSource.setProperty(Info.SYMBOL_MAP, SymbolMap.createSymbolMap(symbolMap.getKeys(), (List<? extends SingleElementSymbol>)projectNode.getProperty(Info.PROJECT_COLS)));
    unionNode.addAsParent(branchSource);
    return branchSource;
  }
View Full Code Here

Examples of org.teiid.query.optimizer.relational.plantree.PlanNode

                continue;
            }
           
            for (int i = accessNodes.size() - 1; i >= 0; i--) {
               
                PlanNode accessNode1 = accessNodes.get(i);
               
                for (int k = accessNodes.size() - 1; k >= 0; k--) {
                    if (k == i) {
                        continue;
                    }
                   
                    PlanNode accessNode2 = accessNodes.get(k);
                   
                    List<PlanNode> criteriaNodes = joinRegion.getCriteriaNodes();
                   
                    List<PlanNode> joinCriteriaNodes = new LinkedList<PlanNode>();
                   
                    /* hasJoinCriteria will be true if
                     *  1. there is criteria between accessNode1 and accessNode2 exclusively
                     *  2. there is criteria between some other source (not the same logical connector) and accessNode1 or accessNode2
                     * 
                     *  Ideally we should be a little smarter in case 2
                     *    - pushing down a same source cross join can be done if we know that a dependent join will be performed
                     */
                    boolean hasJoinCriteria = false;
                    LinkedList<Criteria> joinCriteria = new LinkedList<Criteria>();
                    Object modelId = RuleRaiseAccess.getModelIDFromAccess(accessNode1, metadata);
                    SupportedJoinCriteria sjc = CapabilitiesUtil.getSupportedJoinCriteria(modelId, metadata, capFinder);
                    for (PlanNode critNode : criteriaNodes) {
                        Set<PlanNode> sources = joinRegion.getCritieriaToSourceMap().get(critNode);

                        if (sources == null) {
                            continue;
                        }
                       
                        if (sources.contains(accessNode1)) {
                            if (sources.contains(accessNode2) && sources.size() == 2) {
                                Criteria crit = (Criteria)critNode.getProperty(NodeConstants.Info.SELECT_CRITERIA);
                if (RuleRaiseAccess.isSupportedJoinCriteria(sjc, crit, modelId, metadata, capFinder, null)) {
                                  joinCriteriaNodes.add(critNode);
                                  joinCriteria.add(crit);
                                }
                            } else if (!accessNodes.containsAll(sources)) {
                                hasJoinCriteria = true;
                            }
                        } else if (sources.contains(accessNode2) && !accessNodes.containsAll(sources)) {
                           hasJoinCriteria = true;
                        }
                    }
                   
                    /*
                     * If we failed to find direct criteria, a cross join may still be acceptable
                     */
                    if (joinCriteriaNodes.isEmpty() && (hasJoinCriteria || !canPushCrossJoin(metadata, context, accessNode1, accessNode2))) {
                      continue;
                    }                   
                   
                    List<PlanNode> toTest = Arrays.asList(accessNode1, accessNode2);
                   
                    JoinType joinType = joinCriteria.isEmpty()?JoinType.JOIN_CROSS:JoinType.JOIN_INNER;
                   
                    //try to push to the source
                    if (RuleRaiseAccess.canRaiseOverJoin(toTest, metadata, capFinder, joinCriteria, joinType, null) == null) {
                        continue;
                    }
                   
                    structureChanged = true;
                   
                    //remove the information that is no longer relevant to the join region
                    joinRegion.getCritieriaToSourceMap().keySet().removeAll(joinCriteriaNodes);
                    joinRegion.getCriteriaNodes().removeAll(joinCriteriaNodes);
                    joinRegion.getJoinSourceNodes().remove(accessNode1);
                    joinRegion.getJoinSourceNodes().remove(accessNode2);
                    accessNodes.remove(i);
                    accessNodes.remove(k < i ? k : k - 1);

                    //build a new join node
                    PlanNode joinNode = createJoinNode();
                    joinNode.getGroups().addAll(accessNode1.getGroups());
                    joinNode.getGroups().addAll(accessNode2.getGroups());
                    joinNode.addFirstChild(accessNode2);
                    joinNode.addLastChild(accessNode1);
                    joinNode.setProperty(NodeConstants.Info.JOIN_TYPE, joinType);
                    joinNode.setProperty(NodeConstants.Info.JOIN_CRITERIA, joinCriteria);

                    PlanNode newAccess = RuleRaiseAccess.raiseAccessOverJoin(joinNode, entry.getKey(), false);
                    for (PlanNode critNode : joinCriteriaNodes) {
                        critNode.removeFromParent();
                        critNode.removeAllChildren();
                    }
                                   
View Full Code Here

Examples of org.teiid.query.optimizer.relational.plantree.PlanNode

           
            satisfiedAP = false;
       
            for (Iterator<Map.Entry<PlanNode, PlanNode>> joinSources = dependentNodes.entrySet().iterator(); joinSources.hasNext();) {
              Map.Entry<PlanNode, PlanNode> entry = joinSources.next();
                PlanNode joinSource = entry.getKey();
               
                Collection accessPatterns = (Collection)joinSource.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
                for (Iterator i = accessPatterns.iterator(); i.hasNext();) {
                    AccessPattern ap = (AccessPattern)i.next();
                   
                    boolean foundGroups = true;
                    HashSet<GroupSymbol> allRequiredGroups = new HashSet<GroupSymbol>();
                    for (ElementSymbol symbol : ap.getUnsatisfied()) {
                        Set<Collection<GroupSymbol>> requiredGroupsSet = joinRegion.getDependentCriteriaElements().get(symbol);
                        boolean elementSatisfied = false;
                        if (requiredGroupsSet != null) {
                            for (Collection<GroupSymbol> requiredGroups : requiredGroupsSet) {
                                if (currentGroups.containsAll(requiredGroups)) {
                                    elementSatisfied = true;
                                    allRequiredGroups.addAll(requiredGroups);
                                    break;
                                }
                            }
                        }
                        if (!elementSatisfied) {
                            foundGroups = false;
                            break;
                        }
                    }
                   
                    if (!foundGroups) {
                        continue;
                    }
                   
                    joinSources.remove();
                    satisfiedAP = true;
                    joinSource.setProperty(NodeConstants.Info.ACCESS_PATTERN_USED, ap.clone());
                    joinSource.setProperty(NodeConstants.Info.REQUIRED_ACCESS_PATTERN_GROUPS, allRequiredGroups);
                    break;
                }
            }
        }
       
View Full Code Here

Examples of org.teiid.query.optimizer.relational.plantree.PlanNode

        }
       
    }

    static PlanNode createJoinNode() {
        PlanNode joinNode = NodeFactory.getNewNode(NodeConstants.Types.JOIN);
        joinNode.setProperty(NodeConstants.Info.JOIN_TYPE, JoinType.JOIN_CROSS);
        joinNode.setProperty(NodeConstants.Info.JOIN_STRATEGY, JoinStrategyType.NESTED_LOOP);
        return joinNode;
    }
View Full Code Here

Examples of org.teiid.query.optimizer.relational.plantree.PlanNode

        SymbolMap references = (SymbolMap)frame.getProperty(NodeConstants.Info.CORRELATED_REFERENCES);
        if (references != null) {
          return root; //correlated nested table commands should not be merged
        }

        PlanNode parentProject = NodeEditor.findParent(frame, NodeConstants.Types.PROJECT);

        // Check whether the upper frame is a SELECT INTO
        if (parentProject.getProperty(NodeConstants.Info.INTO_GROUP) != null) {
            return root;
        }

        if (!FrameUtil.canConvertAccessPatterns(frame)) {
            return root;
        }

        PlanNode projectNode = frame.getFirstChild();

        // Check if lower frame has only a stored procedure execution - this cannot be merged to parent frame
        if (FrameUtil.isProcedure(projectNode)) {
            return root;
        }
       
        SymbolMap symbolMap = (SymbolMap)frame.getProperty(NodeConstants.Info.SYMBOL_MAP);
       
        PlanNode sortNode = NodeEditor.findParent(parentProject, NodeConstants.Types.SORT, NodeConstants.Types.SOURCE);
       
        if (sortNode != null && sortNode.hasBooleanProperty(NodeConstants.Info.UNRELATED_SORT)) {
          OrderBy sortOrder = (OrderBy)sortNode.getProperty(NodeConstants.Info.SORT_ORDER);
          boolean unrelated = false;
          for (OrderByItem item : sortOrder.getOrderByItems()) {
            if (!item.isUnrelated()) {
              continue;
            }
            Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(item.getSymbol(), true);
            for (ElementSymbol elementSymbol : elements) {
          if (virtualGroup.equals(elementSymbol.getGroupSymbol())) {
            unrelated = true;
            if (!(symbolMap.getMappedExpression(elementSymbol) instanceof ElementSymbol)) {
              return root;
            }
          }
        }
      }
          // the lower frame cannot contain DUP_REMOVE, GROUP, UNION if unrelated
          if (unrelated && NodeEditor.findNodePreOrder(frame, NodeConstants.Types.DUP_REMOVE, NodeConstants.Types.PROJECT) != null
              || NodeEditor.findNodePreOrder(frame, NodeConstants.Types.SET_OP, NodeConstants.Types.SOURCE) != null
              || NodeEditor.findNodePreOrder(frame, NodeConstants.Types.GROUP, NodeConstants.Types.SOURCE) != null) {
            return root;
          }
        }

        //try to remove the virtual layer if we are only doing a simple projection in the following cases:
        // 1. if the frame root is something other than a project (SET_OP, SORT, LIMIT, etc.)
        // 2. if the frame has a grouping node
        // 3. if the frame has no sources
        if (projectNode.getType() != NodeConstants.Types.PROJECT
            || NodeEditor.findNodePreOrder(frame.getFirstChild(), NodeConstants.Types.GROUP, NodeConstants.Types.SOURCE
                                                                                             | NodeConstants.Types.JOIN) != null
            || NodeEditor.findAllNodes(frame.getFirstChild(), NodeConstants.Types.SOURCE, NodeConstants.Types.SOURCE).isEmpty()) {
         
            PlanNode parentSource = NodeEditor.findParent(parentProject, NodeConstants.Types.SOURCE);
            if (beforeDecomposeJoin && parentSource != null && parentSource.hasProperty(Info.PARTITION_INFO)
                && !NodeEditor.findAllNodes(frame.getFirstChild(), NodeConstants.Types.SET_OP, NodeConstants.Types.SOURCE).isEmpty()) {
              return root; //don't bother to merge until after
            }

            return checkForSimpleProjection(frame, root, parentProject, metadata);
        }

        PlanNode parentJoin = NodeEditor.findParent(frame, NodeConstants.Types.JOIN, NodeConstants.Types.SOURCE);

        if (!checkJoinCriteria(frame, virtualGroup, parentJoin)) {
            return root;
        }
       
        PlanNode parentGroup = NodeEditor.findParent(frame, NodeConstants.Types.GROUP, NodeConstants.Types.SOURCE);
        List<SingleElementSymbol> groupCols = null;
        if (parentGroup != null) {
          groupCols = (List<SingleElementSymbol>)parentGroup.getProperty(NodeConstants.Info.GROUP_COLS);
        }

        if (!checkProjectedSymbols(projectNode, virtualGroup, parentJoin, groupCols, symbolMap, metadata)) {
            return root;
        }

        // Otherwise merge should work

        // Convert parent frame before merge
        FrameUtil.convertFrame(frame, virtualGroup, FrameUtil.findJoinSourceNode(projectNode).getGroups(), symbolMap.asMap(), metadata);

        PlanNode parentBottom = frame.getParent();
        prepareFrame(frame);

        // Remove top 2 nodes (SOURCE, PROJECT) of virtual group - they're no longer needed
        NodeEditor.removeChildNode(parentBottom, frame);
        NodeEditor.removeChildNode(parentBottom, projectNode);
View Full Code Here

Examples of org.teiid.query.optimizer.relational.plantree.PlanNode

        select.addSymbol(new AllSymbol());
        query.setSelect(select);

        group.setMetadataID(METADATA.getGroupID("pm4.g2")); //$NON-NLS-1$
               
        PlanNode n1 = NodeFactory.getNewNode(NodeConstants.Types.ACCESS);
        n1.setProperty(NodeConstants.Info.ATOMIC_REQUEST, query);
        n1.addGroup(group);
       
        RulePlaceAccess.addAccessPatternsProperty(n1, METADATA);

        Collection accessPatterns = (Collection)n1.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
        assertNotNull(accessPatterns);
        assertTrue("Expected two access patterns, got " + accessPatterns.size(), accessPatterns.size() == 2); //$NON-NLS-1$
    }  
View Full Code Here

Examples of org.teiid.query.optimizer.relational.plantree.PlanNode

        return root;
    }

    private static void prepareFrame(PlanNode frame) {
        // find the new root of the frame so that access patterns can be propagated
        PlanNode newRoot = FrameUtil.findJoinSourceNode(frame.getFirstChild());
        if (newRoot != null) {
            Collection ap = (Collection)frame.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
            if (ap != null) {
                Collection newAp = (Collection)newRoot.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
                if (newAp == null) {
                    newRoot.setProperty(NodeConstants.Info.ACCESS_PATTERNS, ap);
                } else {
                    newAp.addAll(ap);
                }
            }
            RulePlaceAccess.copyDependentHints(frame, newRoot);
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.