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

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


    ** strategies like materialization (hash join can work only on
    ** base tables).  The join strategy for a base table under a
    ** ProjectRestrict is set in the base table itself.
    */

    CostEstimate childCost;

    costEstimate = getCostEstimate(optimizer);

    /*
    ** Don't re-optimize a child result set that has already been fully
    ** optimized.  For example, if the child result set is a SelectNode,
    ** it will be changed to a ProjectRestrictNode, which we don't want
    ** to re-optimized.
    */
    // NOTE: TO GET THE RIGHT COST, THE CHILD RESULT MAY HAVE TO BE
    // OPTIMIZED MORE THAN ONCE, BECAUSE THE NUMBER OF OUTER ROWS
    // MAY BE DIFFERENT EACH TIME.
    // if (childResultOptimized)
    //   return costEstimate;

    // It's possible that a call to optimize the left/right will cause
    // a new "truly the best" plan to be stored in the underlying base
    // tables.  If that happens and then we decide to skip that plan
    // (which we might do if the call to "considerCost()" below decides
    // the current path is infeasible or not the best) we need to be
    // able to revert back to the "truly the best" plans that we had
    // saved before we got here.  So with this next call we save the
    // current plans using "this" node as the key.  If needed, we'll
    // then make the call to revert the plans in OptimizerImpl's
    // getNextDecoratedPermutation() method.
    updateBestPlanMap(ADD_PLAN, this);

    /* If the childResult is instanceof Optimizable, then we optimizeIt.
     * Otherwise, we are going into a new query block.  If the new query
     * block has already had its access path modified, then there is
     * nothing to do.  Otherwise, we must begin the optimization process
     * anew on the new query block.
     */
    if (childResult instanceof Optimizable)
    {
      childCost = ((Optimizable) childResult).optimizeIt(
                              optimizer,
                              restrictionList,
                              outerCost,
                              rowOrdering);
      /* Copy child cost to this node's cost */
      costEstimate.setCost(
              childCost.getEstimatedCost(),
              childCost.rowCount(),
              childCost.singleScanRowCount());


      // Note: we don't call "optimizer.considerCost()" here because
      // a) the child will make that call as part of its own
      // "optimizeIt()" work above, and b) the child might have
      // different criteria for "considering" (i.e. rejecting or
      // accepting) a plan's cost than this ProjectRestrictNode does--
      // and we don't want to override the child's decision.  So as
      // with most operations in this class, if the child is an
      // Optimizable, we just let it do its own work and make its
      // own decisions.
    }
    else if ( ! accessPathModified)
    {
      if (SanityManager.DEBUG)
      {
        if (! ((childResult instanceof SelectNode) ||
                 (childResult instanceof RowResultSetNode)))
        {
          SanityManager.THROWASSERT(
            "childResult is expected to be instanceof " +
            "SelectNode or RowResultSetNode - it is a " +
            childResult.getClass().getName());
        }
      }
      childResult = childResult.optimize(optimizer.getDataDictionary(),
                         restrictionList,
                         outerCost.rowCount());

      /* Copy child cost to this node's cost */
      childCost = childResult.costEstimate;

      costEstimate.setCost(
              childCost.getEstimatedCost(),
              childCost.rowCount(),
              childCost.singleScanRowCount());

      /* Note: Prior to the fix for DERBY-781 we had calls here
       * to set the cost estimate for BestAccessPath and
       * BestSortAvoidancePath to equal costEstimate.  That used
       * to be okay because prior to DERBY-781 we would only
View Full Code Here


    ExpressionClassBuilder  acb,
    MethodBuilder mb
  ) throws StandardException
  {
    ConglomerateDescriptor cd = getTrulyTheBestAccessPath().getConglomerateDescriptor();
    CostEstimate costEstimate = getFinalCostEstimate();
    int colRefItem = (referencedCols == null) ?
            -1 :
            acb.addItem(referencedCols);
    boolean tableLockGranularity = tableDescriptor.getLockGranularity() == TableDescriptor.TABLE_LOCK_GRANULARITY;
 
    /*
    ** getLastIndexKeyResultSet
    ** (
    **    activation,     
    **    resultSetNumber,     
    **    resultRowAllocator,     
    **    conglomereNumber,     
    **    tableName,
    **    optimizeroverride     
    **    indexName,     
    **    colRefItem,     
    **    lockMode,     
    **    tableLocked,
    **    isolationLevel,
    **    optimizerEstimatedRowCount,
    **    optimizerEstimatedRowCost,
    **  );
    */

    acb.pushGetResultSetFactoryExpression(mb);

    acb.pushThisAsActivation(mb);
    mb.push(getResultSetNumber());
    resultColumns.generateHolder(acb, mb, referencedCols, (FormatableBitSet) null);
    mb.push(cd.getConglomerateNumber());
    mb.push(tableDescriptor.getName());
    //User may have supplied optimizer overrides in the sql
    //Pass them onto execute phase so it can be shown in
    //run time statistics.
    if (tableProperties != null)
      mb.push(org.apache.derby.iapi.util.PropertyUtil.sortProperties(tableProperties));
    else
      mb.pushNull("java.lang.String");
                pushIndexName(cd, mb);
    mb.push(colRefItem);
    mb.push(getTrulyTheBestAccessPath().getLockMode());
    mb.push(tableLockGranularity);
    mb.push(getCompilerContext().getScanIsolationLevel());
    mb.push(costEstimate.singleScanRowCount());
    mb.push(costEstimate.getEstimatedCost());

    mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getLastIndexKeyResultSet",
          ClassName.NoPutResultSet, 13);


View Full Code Here

    ExpressionClassBuilder  acb,
    MethodBuilder mb
  ) throws StandardException
  {
    ConglomerateDescriptor cd = getTrulyTheBestAccessPath().getConglomerateDescriptor();
    CostEstimate costEstimate = getFinalCostEstimate();
    int colRefItem = (referencedCols == null) ?
            -1 :
            acb.addItem(referencedCols);
    boolean tableLockGranularity = tableDescriptor.getLockGranularity() == TableDescriptor.TABLE_LOCK_GRANULARITY;
 
    /*
    ** getDistinctScanResultSet
    ** (
    **    activation,     
    **    resultSetNumber,     
    **    resultRowAllocator,     
    **    conglomereNumber,     
    **    tableName,
    **    optimizeroverride     
    **    indexName,     
    **    colRefItem,     
    **    lockMode,     
    **    tableLocked,
    **    isolationLevel,
    **    optimizerEstimatedRowCount,
    **    optimizerEstimatedRowCost,
    **    closeCleanupMethod
    **  );
    */

    /* Get the hash key columns and wrap them in a formattable */
    int[] hashKeyColumns;

    hashKeyColumns = new int[resultColumns.size()];
    if (referencedCols == null)
    {
      for (int index = 0; index < hashKeyColumns.length; index++)
      {
        hashKeyColumns[index] = index;
      }
    }
    else
    {
      int index = 0;
      for (int colNum = referencedCols.anySetBit();
          colNum != -1;
          colNum = referencedCols.anySetBit(colNum))
      {
        hashKeyColumns[index++] = colNum;
      }
    }

    FormatableIntHolder[] fihArray =
        FormatableIntHolder.getFormatableIntHolders(hashKeyColumns);
    FormatableArrayHolder hashKeyHolder = new FormatableArrayHolder(fihArray);
    int hashKeyItem = acb.addItem(hashKeyHolder);
    long conglomNumber = cd.getConglomerateNumber();
    StaticCompiledOpenConglomInfo scoci = getLanguageConnectionContext().
                        getTransactionCompile().
                          getStaticCompiledConglomInfo(conglomNumber);

    acb.pushGetResultSetFactoryExpression(mb);

       acb.pushThisAsActivation(mb);
    mb.push(conglomNumber);
    mb.push(acb.addItem(scoci));
     resultColumns.generateHolder(acb, mb, referencedCols, (FormatableBitSet) null);
    mb.push(getResultSetNumber());
    mb.push(hashKeyItem);
    mb.push(tableDescriptor.getName());
    //User may have supplied optimizer overrides in the sql
    //Pass them onto execute phase so it can be shown in
    //run time statistics.
    if (tableProperties != null)
      mb.push(org.apache.derby.iapi.util.PropertyUtil.sortProperties(tableProperties));
    else
      mb.pushNull("java.lang.String");
    pushIndexName(cd, mb);
    mb.push(cd.isConstraint());
    mb.push(colRefItem);
    mb.push(getTrulyTheBestAccessPath().getLockMode());
    mb.push(tableLockGranularity);
    mb.push(getCompilerContext().getScanIsolationLevel());
    mb.push(costEstimate.singleScanRowCount());
    mb.push(costEstimate.getEstimatedCost());
   
    mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getDistinctScanResultSet",
              ClassName.NoPutResultSet, 16);
  }
View Full Code Here

              optimizer,
              rightResultSet,
              getRightOptPredicateList(),
              outerCost);

    CostEstimate costEstimate = getCostEstimate(optimizer);

    /* The cost is the sum of the two child costs */
    costEstimate.setCost(leftResultSet.getCostEstimate().getEstimatedCost(),
               leftResultSet.getCostEstimate().rowCount(),
               leftResultSet.getCostEstimate().singleScanRowCount() +
               rightResultSet.getCostEstimate().singleScanRowCount());

    costEstimate.add(rightResultSet.costEstimate, costEstimate);

    /*
    ** Get the cost of this result set in the context of the whole plan.
    */
    getCurrentAccessPath().
 
View Full Code Here

  {
    // If we already found it, just return it.
    if (finalCostEstimate != null)
      return finalCostEstimate;

    CostEstimate leftCE = leftResultSet.getFinalCostEstimate();
    CostEstimate rightCE = rightResultSet.getFinalCostEstimate();

    finalCostEstimate = getNewCostEstimate();
    finalCostEstimate.setCost(leftCE.getEstimatedCost(),
               leftCE.rowCount(),
               leftCE.singleScanRowCount() +
               rightCE.singleScanRowCount());

    finalCostEstimate.add(rightCE, finalCostEstimate);
    return finalCostEstimate;
  }
View Full Code Here

  {
    // If we already found it, just return it.
    if (finalCostEstimate != null)
      return finalCostEstimate;

    CostEstimate leftCE = leftResultSet.getFinalCostEstimate();
    CostEstimate rightCE = rightResultSet.getFinalCostEstimate();

    finalCostEstimate = getNewCostEstimate();
    finalCostEstimate.setCost(
      leftCE.getEstimatedCost() + rightCE.getEstimatedCost(),
      rightCE.rowCount(),
      rightCE.rowCount());

    return finalCostEstimate;
  }
View Full Code Here

              optimizer,
              rightResultSet,
              (PredicateList) null,
              outerCost);

    CostEstimate costEstimate = getCostEstimate(optimizer);
        CostEstimate leftCostEstimate = leftResultSet.getCostEstimate();
        CostEstimate rightCostEstimate = rightResultSet.getCostEstimate();
        // The cost is the sum of the two child costs plus the cost of sorting the union.
        costEstimate.setCost( leftCostEstimate.getEstimatedCost() + rightCostEstimate.getEstimatedCost(),
                              getRowCountEstimate( leftCostEstimate.rowCount(),
                                                   rightCostEstimate.rowCount()),
                              getSingleScanRowCountEstimate( leftCostEstimate.singleScanRowCount(),
                                                             rightCostEstimate.singleScanRowCount()));

        return costEstimate;
    } // End of estimateCost
View Full Code Here

    throws StandardException
  {
    if (finalCostEstimate != null)
      return finalCostEstimate;

    CostEstimate leftCE = leftResultSet.getFinalCostEstimate();
    CostEstimate rightCE = rightResultSet.getFinalCostEstimate();

    finalCostEstimate = getNewCostEstimate();
    finalCostEstimate.setCost(
      leftCE.getEstimatedCost() + rightCE.getEstimatedCost(),
      getRowCountEstimate(leftCE.rowCount(), rightCE.rowCount()),
      getSingleScanRowCountEstimate(leftCE.singleScanRowCount(),
        rightCE.singleScanRowCount()));

    return finalCostEstimate;
  }
View Full Code Here

    /*
    ** An outer join returns at least as many rows as in the outer
    ** table. Even if this started as a right outer join, it will
    ** have been transformed to a left outer join by this point.
    */
    CostEstimate outerCost = getLeftResultSet().getCostEstimate();

    if (costEstimate.rowCount() < outerCost.rowCount())
    {
      costEstimate.setCost(costEstimate.getEstimatedCost(),
                 outerCost.rowCount(),
                 outerCost.rowCount());
    }
  }
View Full Code Here

    // current plans using "this" node as the key.  If needed, we'll
    // then make the call to revert the plans in OptimizerImpl's
    // getNextDecoratedPermutation() method.
    updateBestPlanMap(ADD_PLAN, this);

    CostEstimate singleScanCost = estimateCost(predList,
                        (ConglomerateDescriptor) null,
                        outerCost,
                        optimizer,
                        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.