Package org.apache.derby.iapi.sql.compile

Examples of org.apache.derby.iapi.sql.compile.CostEstimate


           */
          double rc[] = new double[numOptimizables];
          for (int i = 0; i < numOptimizables; i++)
          {
            firstLookOrder[i] = i;
            CostEstimate ce = optimizableList.getOptimizable(i).
                        getBestAccessPath().getCostEstimate();
            if (ce == null)
            {
              permuteState = READY_TO_JUMP;  //come again?
              break;
            }
            rc[i] = ce.singleScanRowCount();
          }
          if (permuteState == JUMPING)
          {
            boolean doIt = false;
            int temp;
View Full Code Here


      prevSingleScanRowCount = outermostCostEstimate.singleScanRowCount();
    }
    else
    {
      prevPosition = proposedJoinOrder[joinPosition - 1];
      CostEstimate localCE =
        optimizableList.
          getOptimizable(prevPosition).
            getBestAccessPath().
              getCostEstimate();
      prevRowCount = localCE.rowCount();
      prevSingleScanRowCount = localCE.singleScanRowCount();
    }

    /*
    ** If there is no feasible join order, the cost estimate
    ** in the best access path may never have been set.
    ** In this case, do not subtract anything from the
    ** current cost, since nothing was added to the current
    ** cost.
    */
    double newCost = currentCost.getEstimatedCost();
    double pullCost = 0.0;
    CostEstimate pullCostEstimate =
            pullMe.getBestAccessPath().getCostEstimate();
    if (pullCostEstimate != null)
    {
      pullCost = pullCostEstimate.getEstimatedCost();

      newCost -= pullCost;

      /*
      ** It's possible for newCost to go negative here due to
      ** loss of precision--but that should ONLY happen if the
      ** optimizable we just pulled was at position 0.  If we
      ** have a newCost that is <= 0 at any other time, then
      ** it's the result of a different kind of precision loss--
      ** namely, the estimated cost of pullMe was so large that
      ** we lost the precision of the accumulated cost as it
      ** existed prior to pullMe. Then when we subtracted
      ** pullMe's cost out, we ended up setting newCost to zero.
      ** That's an unfortunate side effect of optimizer cost
      ** estimates that grow too large. If that's what happened
      ** here,try to make some sense of things by adding up costs
      ** as they existed prior to pullMe...
      */
      if (newCost <= 0.0)
      {
        if (joinPosition == 0)
          newCost = 0.0;
        else
          newCost = recoverCostFromProposedJoinOrder(false);
      }
    }

    /* If we are choosing a new outer table, then
     * we rest the starting cost to the outermostCost.
     * (Thus avoiding any problems with floating point
     * accuracy and going negative.)
     */
    if (joinPosition == 0)
    {
      if (outermostCostEstimate != null)
      {
        newCost = outermostCostEstimate.getEstimatedCost();
      }
      else
      {
        newCost = 0.0;
      }
    }

    currentCost.setCost(
      newCost,
      prevRowCount,
      prevSingleScanRowCount);
       
    /*
    ** Subtract from the sort avoidance cost if there is a
    ** required row ordering.
    **
    ** NOTE: It is not necessary here to check whether the
    ** best cost was ever set for the sort avoidance path,
    ** because it considerSortAvoidancePath() would not be
    ** set if there cost were not set.
    */
    if (requiredRowOrdering != null)
    {
      if (pullMe.considerSortAvoidancePath())
      {
        AccessPath ap = pullMe.getBestSortAvoidancePath();
        double     prevEstimatedCost = 0.0d;

        /*
        ** Subtract the sort avoidance cost estimate of the
        ** optimizable being removed from the total sort
        ** avoidance cost estimate.
        **
        ** The total cost is the sum of all the costs, but the
        ** total number of rows is the number of rows returned
        ** by the innermost optimizable.
        */
        if (joinPosition == 0)
        {
          prevRowCount = outermostCostEstimate.rowCount();
          prevSingleScanRowCount =
            outermostCostEstimate.singleScanRowCount();

          /* If we are choosing a new outer table, then
           * we rest the starting cost to the outermostCost.
           * (Thus avoiding any problems with floating point
           * accuracy and going negative.)
           */
          prevEstimatedCost =
            outermostCostEstimate.getEstimatedCost();
        }
        else
        {
          CostEstimate localCE =
            optimizableList.
              getOptimizable(prevPosition).
                getBestSortAvoidancePath().
                  getCostEstimate();
          prevRowCount = localCE.rowCount();
          prevSingleScanRowCount = localCE.singleScanRowCount();
          prevEstimatedCost =
            currentSortAvoidanceCost.getEstimatedCost() -
            ap.getCostEstimate().getEstimatedCost();
        }

View Full Code Here

    ** When all the access paths have been looked at, we know what the
    ** cheapest one is, so remember it.  Only do this if a cost estimate
    ** has been set for the best access path - one will not have been
    ** set if no feasible plan has been found.
    */
    CostEstimate ce = curOpt.getBestAccessPath().getCostEstimate();
    if ( ( ! retval ) && (ce != null))
    {
      /*
      ** Add the cost of the current optimizable to the total cost.
      ** The total cost is the sum of all the costs, but the total
      ** number of rows is the number of rows returned by the innermost
      ** optimizable.
      */
      currentCost.setCost(
        currentCost.getEstimatedCost() + ce.getEstimatedCost(),
        ce.rowCount(),
        ce.singleScanRowCount());

      if (curOpt.considerSortAvoidancePath() &&
        requiredRowOrdering != null)
      {
        /* Add the cost for the sort avoidance path, if there is one */
        ce = curOpt.getBestSortAvoidancePath().getCostEstimate();

        currentSortAvoidanceCost.setCost(
          currentSortAvoidanceCost.getEstimatedCost() +
            ce.getEstimatedCost(),
          ce.rowCount(),
          ce.singleScanRowCount());
      }

      if (optimizerTrace)
      {
        trace(TOTAL_COST_NON_SA_PLAN, 0, 0, 0.0, null);
View Full Code Here

  {
    /*
    ** Get the cost of the outer plan so far.  This gives us the current
    ** estimated rows, ordering, etc.
    */
    CostEstimate outerCost;
    if (joinPosition == 0)
    {
      outerCost = outermostCostEstimate;
    }
    else
View Full Code Here

                      ConglomerateDescriptor cd,
                      OptimizablePredicateList predList,
                      CostEstimate outerCost)
        throws StandardException
  {
    CostEstimate estimatedCost = estimateTotalCost(predList,
                            cd,
                            outerCost,
                            optimizable);

    // Before considering the cost, make sure we set the optimizable's
    // "current" cost to be the one that we found.  Doing this allows
    // us to compare "current" with "best" later on to find out if
    // the "current" plan is also the "best" one this round--if it's
    // not then we'll have to revert back to whatever the best plan is.
    // That check is performed in getNextDecoratedPermutation() of
    // this class.
    optimizable.getCurrentAccessPath().setCostEstimate(estimatedCost);

    /*
    ** Skip this access path if it takes too much memory.
    **
    ** NOTE: The default assumption here is that the number of rows in
    ** a single scan is the total number of rows divided by the number
    ** of outer rows.  The optimizable may over-ride this assumption.
    */
    // RESOLVE: The following call to memoryUsageOK does not behave
    // correctly if outerCost.rowCount() is POSITIVE_INFINITY; see
    // DERBY-1259.
    if( ! optimizable.memoryUsageOK( estimatedCost.rowCount() / outerCost.rowCount(), maxMemoryPerTable))
    {
      if (optimizerTrace)
      {
        trace(SKIPPING_DUE_TO_EXCESS_MEMORY, 0, 0, 0.0, null);
      }
      return;
    }

    /* Pick the cheapest cost for this particular optimizable. */
    AccessPath ap = optimizable.getBestAccessPath();
    CostEstimate bestCostEstimate = ap.getCostEstimate();

    if ((bestCostEstimate == null) ||
      bestCostEstimate.isUninitialized() ||
      (estimatedCost.compare(bestCostEstimate) < 0))
    {
      ap.setConglomerateDescriptor(cd);
      ap.setCostEstimate(estimatedCost);
      ap.setCoveringIndexScan(optimizable.isCoveringIndex(cd));

      /*
      ** It's a non-matching index scan either if there is no
      ** predicate list, or nothing in the predicate list is useful
      ** for limiting the scan.
      */
      ap.setNonMatchingIndexScan(
                  (predList == null) ||
                  ( ! ( predList.useful(optimizable, cd) ) )
                  );
      ap.setLockMode(optimizable.getCurrentAccessPath().getLockMode());
      optimizable.rememberJoinStrategyAsBest(ap);
    }

    /*
    ** Keep track of the best sort-avoidance path if there is a
    ** required row ordering.
    */
    if (requiredRowOrdering != null)
    {
      /*
      ** The current optimizable can avoid a sort only if the
      ** outer one does, also (if there is an outer one).
      */
      if (joinPosition == 0 ||
        optimizableList.getOptimizable(
                    proposedJoinOrder[joinPosition - 1]).
                        considerSortAvoidancePath())
      {
        /*
        ** There is a required row ordering - does the proposed access
        ** path avoid a sort?
        */
        if (requiredRowOrdering.sortRequired(currentRowOrdering,
                            assignedTableMap,
                            optimizableList)
                    ==RequiredRowOrdering.NOTHING_REQUIRED)
        {
          ap = optimizable.getBestSortAvoidancePath();
          bestCostEstimate = ap.getCostEstimate();

          /* Is this the cheapest sort-avoidance path? */
          if ((bestCostEstimate == null) ||
            bestCostEstimate.isUninitialized() ||
            (estimatedCost.compare(bestCostEstimate) < 0))
          {
            ap.setConglomerateDescriptor(cd);
            ap.setCostEstimate(estimatedCost);
            ap.setCoveringIndexScan(
View Full Code Here

     * associated with it in that case.  So, we now choose the new
     * access path if it is the same cost or cheaper than the current
     * access path.
     */
    AccessPath ap = optimizable.getBestAccessPath();
    CostEstimate bestCostEstimate = ap.getCostEstimate();

    if ((bestCostEstimate == null) ||
      bestCostEstimate.isUninitialized() ||
      (estimatedCost.compare(bestCostEstimate) <= 0))
    {
      ap.setCostEstimate(estimatedCost);
      optimizable.rememberJoinStrategyAsBest(ap);
    }

    /*
    ** Keep track of the best sort-avoidance path if there is a
    ** required row ordering.
    */
    if (requiredRowOrdering != null)
    {
      /*
      ** The current optimizable can avoid a sort only if the
      ** outer one does, also (if there is an outer one).
      */
      if (joinPosition == 0 ||
        optimizableList.getOptimizable(
                    proposedJoinOrder[joinPosition - 1]).
                        considerSortAvoidancePath())
      {
        /*
        ** There is a required row ordering - does the proposed access
        ** path avoid a sort?
        */
        if (requiredRowOrdering.sortRequired(currentRowOrdering,
                            assignedTableMap,
                            optimizableList)
                    == RequiredRowOrdering.NOTHING_REQUIRED)
        {
          ap = optimizable.getBestSortAvoidancePath();
          bestCostEstimate = ap.getCostEstimate();

          /* Is this the cheapest sort-avoidance path? */
          if ((bestCostEstimate == null) ||
            bestCostEstimate.isUninitialized() ||
            (estimatedCost.compare(bestCostEstimate) < 0))
          {
            ap.setCostEstimate(estimatedCost);
            optimizable.rememberJoinStrategyAsBest(ap);
            optimizable.rememberSortAvoidancePath();
View Full Code Here

    // The total cost is the sum of all the costs, but the total
    // number of rows is the number of rows returned by the innermost
    // optimizable.
    finalCostEstimate = getNewCostEstimate(0.0d, 0.0d, 0.0d);
    CostEstimate ce = null;
    for (int i = 0; i < bestJoinOrder.length; i++)
    {
      ce = optimizableList.getOptimizable(bestJoinOrder[i])
          .getTrulyTheBestAccessPath().getCostEstimate();

      finalCostEstimate.setCost(
        finalCostEstimate.getEstimatedCost() + ce.getEstimatedCost(),
        ce.rowCount(),
        ce.singleScanRowCount());
    }

    return finalCostEstimate;
  }
View Full Code Here

                      CostEstimate outerCost,
                      Optimizable optimizable)
    throws StandardException
  {
    /* Get the cost of a single scan */
    CostEstimate resultCost =
      optimizable.estimateCost(predList,
                  cd,
                  outerCost,
                  this,
                  currentRowOrdering);
View Full Code Here

    mb.push(resultSetNumber);

    // Get the cost estimate for the child
    // RESOLVE - we will eventually include the cost of the sort
    CostEstimate costEstimate = child.getFinalCostEstimate();

    mb.push(costEstimate.rowCount());
    mb.push(costEstimate.getEstimatedCost());

    mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getSortResultSet",
              ClassName.NoPutResultSet, 9);

  }
View Full Code Here

              CostEstimate outerCost,
              RowOrdering rowOrdering)
      throws StandardException
  {
    // RESOLVE: NEED TO FACTOR IN THE COST OF GROUPING (SORTING) HERE
    CostEstimate childCost = ((Optimizable) childResult).optimizeIt(
                          optimizer,
                          predList,
                          outerCost,
                          rowOrdering);

    CostEstimate retval = super.optimizeIt(
                        optimizer,
                        predList,
                        outerCost,
                        rowOrdering
                        );
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.compile.CostEstimate

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.