Package org.teiid.query.optimizer.relational.plantree

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


      LinkedList<PlanNode> targets = determineTargets(dependentNode,
          metadata, capFinder, rpsc, depExpr, depExpressions);
     
      Iterator<Expression> exprIter = depExpressions.iterator();
      for (Iterator<PlanNode> targetIter = targets.iterator(); targetIter.hasNext();) {
        PlanNode target = targetIter.next();
        Expression targerDepExpr = exprIter.next();
        PlanNode accessNode = NodeEditor.findParent(target, NodeConstants.Types.ACCESS);

            float setCriteriaBatchSize = indSymbolNDV;
               
            if (accessNode != null) {
                setCriteriaBatchSize = CapabilitiesUtil.getMaxInCriteriaSize(RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder);
                if (setCriteriaBatchSize < 1) {
                    setCriteriaBatchSize = indSymbolNDV;
                } else {
                  int numberOfSets = CapabilitiesUtil.getMaxDependentPredicates(RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder);
                  if (numberOfSets > 0) {
                    setCriteriaBatchSize *= Math.max(1, numberOfSets /dependentExpressions.size()); //scale down to be conservative
                  }
                }
            } else if (indSymbolNDV > processorBatchSize) {
                //don't bother making a virtual join dependent if they are likely to be large
              //TODO: what operations are performed between origNode and dependentNode
              //TODO: we should be using a tree structure rather than just a value iterator
              continue;
            }
            if (target.hasBooleanProperty(Info.MAKE_NOT_DEP)) {
              continue;
            }
            Collection<ElementSymbol> depElems = ElementCollectorVisitor.getElements(targerDepExpr, true);
            while (target.getParent().getType() == NodeConstants.Types.SELECT) {
              target = target.getParent();
            }
            float depTargetCardinality = computeCostForTree(target, metadata);
            if (depTargetCardinality == UNKNOWN_VALUE) {
              continue;
            }
            float depSymbolNDV = getStat(Stat.NDV, depElems, target, depTargetCardinality, metadata);
            boolean usesKey = usesKey(dependentNode, depElems, metadata);
        if (depSymbolNDV == UNKNOWN_VALUE) {
          if (!usesKey) {
            //make an educated guess that this is a fk
            float indSymbolOrigNDV = indSymbolNDV;
            float indCardinalityOrig = independentCardinality;
            //TODO: we should probably dig deeper than this
            PlanNode indOrigNode = FrameUtil.findOriginatingNode(independentNode, GroupsUsedByElementsVisitor.getGroups(indElements));
            if (indOrigNode != null) {
              indCardinalityOrig = computeCostForTree(indOrigNode, metadata);
              indSymbolOrigNDV = getStat(Stat.NDV, indElements, indOrigNode, indCardinalityOrig, metadata);
              if (indSymbolOrigNDV == UNKNOWN_VALUE) {
                indSymbolOrigNDV = indCardinalityOrig * indSymbolNDV / independentCardinality;
View Full Code Here


    LinkedList<PlanNode> critNodes = new LinkedList<PlanNode>();
    critNodes.add(RelationalPlanner.createSelectNode(new DependentSetCriteria(depExpr, null), false));
    LinkedList<PlanNode> initialTargets = new LinkedList<PlanNode>();
    initialTargets.add(dependentNode);
    while (!critNodes.isEmpty()) {
      PlanNode critNode = critNodes.remove();
      PlanNode initial = initialTargets.remove();
      if (critNode.getGroups().isEmpty()) {
        //TODO: we need to project constants up through a plan to avoid this case
        continue;
      }
      PlanNode sourceNode = FrameUtil.findOriginatingNode(initial, critNode.getGroups());
      PlanNode target = sourceNode;
      if (initial != sourceNode) {
        target = rpsc.examinePath(initial, sourceNode, metadata, capFinder);         
      }
      if (target != sourceNode || (sourceNode.getType() == NodeConstants.Types.SOURCE && sourceNode.getChildCount() == 0)) {
        targets.add(target);
        DependentSetCriteria dsc = (DependentSetCriteria)critNode.getProperty(Info.SELECT_CRITERIA);
        depExpressions.add(dsc.getExpression());
        continue;
      }
      if (sourceNode.getType() == NodeConstants.Types.SOURCE) {
        PlanNode child = sourceNode.getFirstChild();
            child = FrameUtil.findOriginatingNode(child, child.getGroups());
            if (child != null && child.getType() == NodeConstants.Types.SET_OP) {
              targets.add(target);
          DependentSetCriteria dsc = (DependentSetCriteria)critNode.getProperty(Info.SELECT_CRITERIA);
          depExpressions.add(dsc.getExpression());
          //TODO: we need better handling for set op situations
          continue;
View Full Code Here

       
        boolean pushCriteria = false;

        // Handle all cases where both siblings are possible matches
        for (CandidateJoin entry : matches) {
            PlanNode joinNode = entry.joinNode;
           
            PlanNode sourceNode = entry.leftCandidate?joinNode.getFirstChild():joinNode.getLastChild();
           
            PlanNode siblingNode = entry.leftCandidate?joinNode.getLastChild():joinNode.getFirstChild();
           
            boolean bothCandidates = entry.leftCandidate&&entry.rightCandidate;
           
            PlanNode chosenNode = chooseDepWithoutCosting(sourceNode, bothCandidates?siblingNode:null, analysisRecord);
            if(chosenNode != null) {
                pushCriteria |= markDependent(chosenNode, joinNode, metadata, null);
                continue;
            }  
           
            DependentCostAnalysis dca = NewCalculateCostUtil.computeCostForDepJoin(joinNode, !entry.leftCandidate, metadata, capFinder, context);
            PlanNode dependentNode = sourceNode;
           
            if (bothCandidates && dca.expectedCardinality == null) {
                dca = NewCalculateCostUtil.computeCostForDepJoin(joinNode, true, metadata, capFinder, context);
                if (dca.expectedCardinality != null) {
                    dependentNode = siblingNode;
View Full Code Here

       
        for (PlanNode joinNode : NodeEditor.findAllNodes(root, NodeConstants.Types.JOIN, NodeConstants.Types.ACCESS)) {
            CandidateJoin candidate = null;
           
            for (Iterator<PlanNode> j = joinNode.getChildren().iterator(); j.hasNext();) {
                PlanNode child = j.next();
                child = FrameUtil.findJoinSourceNode(child);
               
                if(child.hasBooleanProperty(NodeConstants.Info.MAKE_NOT_DEP) || !isValidJoin(joinNode, child, analysisRecord)) {
                  continue;
                }
                if (candidate == null) {
                    candidate = new CandidateJoin();
                    candidate.joinNode = joinNode;
View Full Code Here

        return true;       
    }
   
    PlanNode chooseDepWithoutCosting(PlanNode rootNode1, PlanNode rootNode2, AnalysisRecord analysisRecord)  {
      PlanNode sourceNode1 = FrameUtil.findJoinSourceNode(rootNode1);
        PlanNode sourceNode2 = null;
       
        if (rootNode2 != null) {
            sourceNode2 = FrameUtil.findJoinSourceNode(rootNode2);
        }
        if(sourceNode1.hasCollectionProperty(NodeConstants.Info.ACCESS_PATTERNS) ) {
            if (sourceNode2 != null && sourceNode2.hasCollectionProperty(NodeConstants.Info.ACCESS_PATTERNS) ) {
                //Return null - query planning should fail because both access nodes
                //have unsatisfied access patterns
              if (analysisRecord.recordDebug()) {
                analysisRecord.println("Neither access node can be made dependent because both have unsatisfied access patterns: " + sourceNode1.nodeToString() + "\n" + sourceNode2.toString()); //$NON-NLS-1$ //$NON-NLS-2$
              }
                return null;
           
            return rootNode1;
        } else if (sourceNode2 != null && sourceNode2.hasCollectionProperty(NodeConstants.Info.ACCESS_PATTERNS) ) {
            //Access node 2 has unsatisfied access pattern,
            //so try to make node 2 dependent
          if (analysisRecord.recordDebug()) {
            analysisRecord.println("Making access node dependent to satisfy access pattern: "+ sourceNode2.nodeToString()); //$NON-NLS-1$
          }
            return rootNode2;
        }
       
        // Check for hints, which over-rule heuristics
        if(sourceNode1.hasBooleanProperty(NodeConstants.Info.MAKE_DEP)) {
          if (analysisRecord.recordDebug()) {
            analysisRecord.println("Making access node dependent due to hint: "+ sourceNode1.nodeToString());                     //$NON-NLS-1$
          }
            return rootNode1;
        } else if(sourceNode2 != null && sourceNode2.hasBooleanProperty(NodeConstants.Info.MAKE_DEP)) {
          if (analysisRecord.recordDebug()) {
            analysisRecord.println("Making access node dependent due to hint: "+ sourceNode2.nodeToString());                     //$NON-NLS-1$
          }
            return rootNode2;
        }
       
        return null;
View Full Code Here

        // Create DependentValueSource and set on the independent side as this will feed the values
        joinNode.setProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE, id);

        List<PlanNode> crits = getDependentCriteriaNodes(id, independentExpressions, dependentExpressions, isLeft?joinNode.getLastChild():joinNode.getFirstChild(), metadata, dca);
       
        PlanNode newRoot = sourceNode;
       
        for (PlanNode crit : crits) {
            newRoot.addAsParent(crit);
            newRoot = crit;
        }
             
        if (isLeft) {
            JoinUtil.swapJoinChildren(joinNode);
View Full Code Here

              ndv = NewCalculateCostUtil.getNDVEstimate(indNode, metadata, cardinality, elems, true);
            }
            crit.setNdv(ndv);
            crit.setValueExpression(indepExpr);
           
            PlanNode selectNode = RelationalPlanner.createSelectNode(crit, false);
           
            selectNode.setProperty(NodeConstants.Info.IS_DEPENDENT_SET, Boolean.TRUE);
            result.add(selectNode);
        }
       
        return result;
    }
View Full Code Here

                List<PlanNode> sources = entry.getValue();
               
                sourceUnions.add(buildUnionTree(unionNode, sources));
            }
           
            PlanNode tempRoot = buildUnionTree(unionNode, sourceUnions);
           
            unionNode.removeAllChildren();
            unionNode.addChildren(tempRoot.removeAllChildren());
        }
    }
View Full Code Here

    }

    static PlanNode buildUnionTree(PlanNode rootUnionNode,
                                List<PlanNode> sources) {
       
        PlanNode root = null;
       
        for (PlanNode source : sources) {
            if (root == null) {
                root = source;
            } else {
                PlanNode union = NodeFactory.getNewNode(NodeConstants.Types.SET_OP);
                union.setProperty(NodeConstants.Info.SET_OPERATION, rootUnionNode.getProperty(NodeConstants.Info.SET_OPERATION));
                union.setProperty(NodeConstants.Info.USE_ALL, rootUnionNode.getProperty(NodeConstants.Info.USE_ALL));
                union.addLastChild(root);
                union.addLastChild(source);
                root = union;
            }
        }
       
        return root;
View Full Code Here

        if (!joinType.isOuter()) {
            return null;
        }
       
        PlanNode left = joinNode.getFirstChild();
        left = FrameUtil.findJoinSourceNode(left);
        PlanNode right = joinNode.getLastChild();
        right = FrameUtil.findJoinSourceNode(right);
       
        Collection<GroupSymbol> outerGroups = left.getGroups();
        Collection<GroupSymbol> innerGroups = right.getGroups();
        if (joinType == JoinType.JOIN_RIGHT_OUTER) {
            outerGroups = innerGroups;
            innerGroups = left.getGroups();
        }
       
View Full Code Here

TOP

Related Classes of org.teiid.query.optimizer.relational.plantree.PlanNode

Copyright © 2018 www.massapicom. 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.