Package org.apache.derby.iapi.util

Examples of org.apache.derby.iapi.util.JBitSet


    this.tableLockThreshold = tableLockThreshold;
    this.requiredRowOrdering = requiredRowOrdering;
    this.useStatistics = useStatistics;

    /* initialize variables for tracking permutations */
    assignedTableMap = new JBitSet(numTablesInQuery);

    /*
    ** Make a map of the non-correlated tables, which are the tables
    ** in the list of Optimizables we're optimizing.  An reference
    ** to a table that is not defined in the list of Optimizables
    ** is presumed to be correlated.
    */
    nonCorrelatedTableMap = new JBitSet(numTablesInQuery);
    for (int tabCtr = 0; tabCtr < numOptimizables; tabCtr++)
    {
      Optimizable  curTable = optimizableList.getOptimizable(tabCtr);
      nonCorrelatedTableMap.or(curTable.getReferencedTableMap());
    }
View Full Code Here


       * maps.  The XOR itself occurs as part of optimizable "PULL"
       * processing.
       */
      if (SanityManager.DEBUG)
      {
        JBitSet optMap =
          (JBitSet)nextOpt.getReferencedTableMap().clone();

        optMap.and(assignedTableMap);
        if (optMap.getFirstSetBit() != -1)
        {
          SanityManager.THROWASSERT(
            "Found multiple optimizables that share one or " +
            "more referenced table numbers (esp: '" +
            optMap + "'), but that should not be the case.");
View Full Code Here

    **
    ** RESOLVE - We do not push predicates with subqueries not materializable.
    */

    int                    numPreds        = predicateList.size();
    JBitSet                  predMap         = new JBitSet(numTablesInQuery);
    JBitSet                 curTableNums    = null;
    BaseTableNumbersVisitor btnVis          = null;
    boolean                 pushPredNow     = false;
    int                     tNum;
    Predicate               pred;

    /* Walk the OptimizablePredicateList.  For each OptimizablePredicate,
     * see if it can be assigned to the Optimizable at the current join
     * position.
     *
     * NOTE - We walk the OPL backwards since we will hopefully be deleted
     * entries as we walk it.
     */
    for (int predCtr = numPreds - 1; predCtr >= 0; predCtr--)
    {
      pred = (Predicate)predicateList.getOptPredicate(predCtr);

      /* Skip over non-pushable predicates */
      if (! isPushable(pred))
      {
        continue;
      }
       
      /* Make copy of referenced map so that we can do destructive
       * manipulation on the copy.
       */
      predMap.setTo(pred.getReferencedMap());

      /* Clear bits representing those tables that have already been
       * assigned, except for the current table.  The outer table map
       * includes the current table, so if the predicate is ready to
       * be pushed, predMap will end up with no bits set.
       */
      for (int index = 0; index < predMap.size(); index++)
      {
        if (outerTables.get(index))
        {
          predMap.clear(index);
        }
      }

      /*
      ** Only consider non-correlated variables when deciding where
      ** to push predicates down to.
      */
      predMap.and(nonCorrelatedTableMap);

      /* At this point what we've done is figure out what FromTables
       * the predicate references (using the predicate's "referenced
       * map") and then: 1) unset the table numbers for any FromTables
       * that have already been optimized, 2) unset the table number
       * for curTable, which we are about to optimize, and 3) cleared
       * out any remaining table numbers which do NOT directly
       * correspond to UN-optimized FromTables in this OptimizerImpl's
       * optimizableList.
       *
       * Note: the optimizables in this OptImpl's optimizableList are
       * called "non-correlated".
       *
       * So at this point predMap holds a list of tableNumbers which
       * correspond to "non-correlated" FromTables that are referenced
       * by the predicate but that have NOT yet been optimized.  If any
       * such FromTable exists then we canNOT push the predicate yet. 
       * We can only push the predicate if every FromTable that it
       * references either 1) has already been optimized, or 2) is
       * about to be optimized (i.e. the FromTable is curTable itself).
       * We can check for this condition by seeing if predMap is empty,
       * which is what the following line does.
       */
      pushPredNow = (predMap.getFirstSetBit() == -1);

      /* If the predicate is scoped, there's more work to do. A
       * scoped predicate's "referenced map" may not be in sync
       * with its actual column references.  Or put another way,
       * the predicate's referenced map may not actually represent
       * the tables that are referenced by the predicate.  For
       * example, assume the query tree is something like:
       *
       *      SelectNode0
       *     (PRN0, PRN1)
       *       |     |
       *       T1 UnionNode
       *           /   |
       *         PRN2  PRN3
       *          |     |
       *  SelectNode1   SelectNode2
       *   (PRN4, PRN5)    (PRN6)
       *     |     |         |
       *     T2    T3        T4
       *
       * Assume further that we have an equijoin predicate between
       * T1 and the Union node, and that the column reference that
       * points to the Union ultimately maps to T3.  The predicate
       * will then be scoped to PRN2 and PRN3 and the newly-scoped
       * predicates will get passed to the optimizers for SelectNode1
       * and SelectNode2--which brings us here.  Assume for this
       * example that we're here for SelectNode1 and that "curTable"
       * is PRN4.  Since the predicate has been scoped to SelectNode1,
       * its referenced map will hold the table numbers for T1 and
       * PRN2--it will NOT hold the table number for PRN5, even
       * though PRN5 (T3) is the actual target for the predicate.
       * Given that, the above logic will determine that the predicate
       * should be pushed to curTable (PRN4)--but that's not correct.
       * We said at the start that the predicate ultimately maps to
       * T3--so we should NOT be pushing it to T2.  And hence the
       * need for some additional logic.  DERBY-1866.
       */
      if (pushPredNow && pred.isScopedForPush() && (numOptimizables > 1))
      {
        if (btnVis == null)
        {
          curTableNums = new JBitSet(numTablesInQuery);
          btnVis       = new BaseTableNumbersVisitor(curTableNums);
        }

        /* What we want to do is find out if the scoped predicate
         * is really supposed to be pushed to curTable.  We do
         * that by getting the base table numbers referenced by
         * curTable along with curTable's own table number.  Then
         * we get the base table numbers referenced by the scoped
         * predicate. If the two sets have at least one table
         * number in common, then we know that the predicate
         * should be pushed to curTable.  In the above example
         * predMap will end up holding the base table number
         * for T3, and thus this check will fail when curTable
         * is PRN4 but will pass when it is PRN5, which is what
         * we want.
         */
        tNum = ((FromTable)curTable).getTableNumber();
        curTableNums.clearAll();
        btnVis.setTableMap(curTableNums);
        ((FromTable)curTable).accept(btnVis);
        if (tNum >= 0)
          curTableNums.set(tNum);

        btnVis.setTableMap(predMap);
        pred.accept(btnVis);

        predMap.and(curTableNums);
View Full Code Here

    /* Change the join order of the list of optimizables */
    optimizableList.reOrder(bestJoinOrder);

    /* Form a bit map of the tables as they are put into the join order */
    JBitSet outerTables = new JBitSet(numOptimizables);

    /* Modify the access path of each table, as necessary */
    for (int ictr = 0; ictr < numOptimizables; ictr++)
    {
      Optimizable optimizable = optimizableList.getOptimizable(ictr);

      /* Current table is treated as an outer table */
      outerTables.or(optimizable.getReferencedTableMap());

      /*
      ** Push any appropriate predicates from this optimizer's list
      ** to the optimizable, as appropriate.
      */
 
View Full Code Here

    int size = size();

    /* Start by getting the table number and column position for
     * the table to which the ColumnReference points.
     */
    JBitSet tNum = new JBitSet(numOptimizables);
    BaseTableNumbersVisitor btnVis = new BaseTableNumbersVisitor(tNum);

    cRef.accept(btnVis);
    int crTableNumber = tNum.getFirstSetBit();
    int crColPosition = btnVis.getColumnNumber();

    if (SanityManager.DEBUG)
    {
      /* We assume that we only ever get here if the column
       * reference points to a specific column in a specific
       * table...
       */
      if ((crTableNumber < 0) || (crColPosition < 0))
      {
        SanityManager.THROWASSERT(
          "Failed to find table/column number for column '" +
          cRef.getColumnName() + "' when checking for an " +
          "ORDER BY requirement.");
      }

      /* Since we started with a single ColumnReference there
       * should be exactly one table number.
       */
      if (!tNum.hasSingleBitSet())
      {
        SanityManager.THROWASSERT(
          "Expected ColumnReference '" + cRef.getColumnName() +
          "' to reference exactly one table, but tables found " +
          "were: " + tNum);
      }
    }

    /* Walk through the various ORDER BY elements to see if
     * any of them point to the same table and column that
     * we found above.
     */
    for (int loc = 0; loc < size; loc++)
    {
      OrderByColumn obc = getOrderByColumn(loc);
      ResultColumn rcOrderBy = obc.getResultColumn();

      btnVis.reset();
      rcOrderBy.accept(btnVis);
      int obTableNumber = tNum.getFirstSetBit();
      int obColPosition = btnVis.getColumnNumber();

      /* ORDER BY target should always have a table number and
       * a column position.  It may not necessarily be a base
       * table, but there should be some FromTable for which
       * we have a ResultColumnList, and the ORDER BY should
       * reference one of the columns in that list (otherwise
       * we shouldn't have made it this far).
       */
      if (SanityManager.DEBUG)
      {
        /* Since we started with a single ResultColumn there
         * should exactly one table number.
         */
        if (!tNum.hasSingleBitSet())
        {
          SanityManager.THROWASSERT("Expected ResultColumn '" +
            rcOrderBy.getColumnName() + "' to reference " +
            "exactly one table, but found: " + tNum);
        }
View Full Code Here

  }

  public JBitSet LOJgetReferencedTables(int numTables)
        throws StandardException
  {
    JBitSet map = new JBitSet(numTables);
    fillInReferencedTableMap(map);
    return map;
  }
View Full Code Here

    // correlation column, to fill in eqOuterCols properly. We don't care
    // about eqOuterCols, so just create a zero-length array, pretending
    // that all columns are correlation columns.
    int[] tableNumbers = new int[0];
    JBitSet[] tableColMap = new JBitSet[1];
    tableColMap[0] = new JBitSet(numColumns + 1);

    pl.checkTopPredicatesForEqualsConditions(tableNumber,
                        null,
                        tableNumbers,
                        tableColMap,
View Full Code Here

                  GroupByList gbl,
                  FromList fromList)
                throws StandardException
  {
    /* Generate the referenced table map */
    referencedTableMap = new JBitSet(numTables);
    referencedTableMap.set(tableNumber);

    return genProjectRestrict(numTables);
  }
View Full Code Here

        continue;
      }

      int[] keyColumns = id.baseColumnPositions();
      int numBits = tableColMap[0].size();
      JBitSet keyMap = new JBitSet(numBits);
      JBitSet resMap = new JBitSet(numBits);

      int inner = 0;
      for ( ; inner < keyColumns.length; inner++)
      {
        keyMap.set(keyColumns[inner]);
      }
      int table = 0;
      for ( ; table < tableColMap.length; table++)
      {
        resMap.setTo(tableColMap[table]);
        resMap.and(keyMap);
        if (keyMap.equals(resMap))
        {
          tableColMap[table].set(0);
          return true;
        }
View Full Code Here

  }

  /** @see OptimizableList#legalJoinOrder */
  public boolean legalJoinOrder(int numTablesInQuery)
  {
    JBitSet      assignedTableMap = new JBitSet(numTablesInQuery);

    int size = size();
    for (int index = 0; index < size; index++)
    {
      FromTable ft = (FromTable) elementAt(index);
      assignedTableMap.or(ft.getReferencedTableMap());
      if ( ! ft.legalJoinOrder(assignedTableMap))
      {
        return false;
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.util.JBitSet

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.