Package org.apache.derby.iapi.util

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


   */

  public ResultSetNode extractSubquery(int numTables)
    throws StandardException
  {
    JBitSet      newJBS;
    ResultSetNode newPRN;

    newPRN = (ResultSetNode) getNodeFactory().getNode(
                C_NodeTypes.PROJECT_RESTRICT_NODE,
                subquery,    /* Child ResultSet */
                resultColumns,  /* Projection */
                null,      /* Restriction */
                null,      /* Restriction as PredicateList */
                null,      /* Subquerys in Projection */
                null,      /* Subquerys in Restriction */
                tableProperties,
                getContextManager()   );

    /* Set up the PRN's referencedTableMap */
    newJBS = new JBitSet(numTables);
    newJBS.set(tableNumber);
    newPRN.setReferencedTableMap(newJBS);
    ((FromTable) newPRN).setTableNumber(tableNumber);

    return newPRN;
  }
View Full Code Here


    {
      /*
      ** The operand is a column reference.
      ** Is it the correct column?
      */
      JBitSet cRefTables = new JBitSet(refSetSize);
      JBitSet crTables = new JBitSet(refSetSize);
      BaseTableNumbersVisitor btnVis =
        new BaseTableNumbersVisitor(crTables);

      cr = (ColumnReference) operand;
      try {
        cr.accept(btnVis);
        btnVis.setTableMap(cRefTables);
        cRef.accept(btnVis);
      } catch (StandardException se) {
              if (SanityManager.DEBUG)
              {
                  SanityManager.THROWASSERT("Failed when trying to " +
                      "find base table number for column reference check:\n" +
                      se.getMessage());
              }
      }
      crTables.and(cRefTables);
      if (crTables.getFirstSetBit() != -1)
      {
        /*
        ** The table is correct, how about the column position?
        */
        if (cr.getSource().getColumnPosition() ==
View Full Code Here

  /** @see RelationalOperator#selfComparison */
  public boolean selfComparison(ColumnReference cr)
  {
    ValueNode  otherSide;
    JBitSet    tablesReferenced;

    if (SanityManager.DEBUG)
    {
      SanityManager.ASSERT(cr == operand,
        "ColumnReference not found in IsNullNode.");
View Full Code Here

    }

    // Build the data structure for testing/doing LOJ reordering.
    // Fill in the table references on row-preserving and null-producing sides.
    // It may be possible that either operand is a complex view.
    JBitSet        NPReferencedTableMap; // Null-producing
    JBitSet        RPReferencedTableMap; // Row-preserving

    RPReferencedTableMap = logicalLeftResultSet.LOJgetReferencedTables(numTables);
    NPReferencedTableMap = logicalRightResultSet.LOJgetReferencedTables(numTables);

    if ((RPReferencedTableMap == null || NPReferencedTableMap == null) &&
      anyChange)
    {
      return LOJ_bindResultColumns(anyChange);
    }
     
    // Check if the predicate is equality predicate in CNF (i.e., AND only)
    // and left/right column references must come from either operand.
    // That is, we don't allow:
    // 1. A=A
    // 2. 1=1
    // 3. B=C where both B and C are either from left or right operand.

    // we probably need to make the joinClause "left-deep" so that we can
    // walk it easier.
    BinaryRelationalOperatorNode equals;
    ValueNode leftCol;
    ValueNode rightCol;
    AndNode   and;
    ValueNode left;
    ValueNode vn = joinClause;
    while (vn instanceof AndNode)
    {
      and = (AndNode) vn;
      left = and.getLeftOperand();

      // Make sure that this is an equijoin of the form "C = D" where C
      // and D references tables from both left and right operands.
      if (left instanceof RelationalOperator &&
        ((ValueNode)left).isBinaryEqualsOperatorNode())
      {
        equals = (BinaryRelationalOperatorNode) left;
        leftCol = equals.getLeftOperand();
        rightCol = equals.getRightOperand();

        if (!( leftCol instanceof ColumnReference && rightCol instanceof ColumnReference))
          return LOJ_bindResultColumns(anyChange);

        boolean refCheck = false;
        boolean leftOperandCheck = false;

        if (RPReferencedTableMap.get(((ColumnReference)leftCol).getTableNumber()))
        {
          refCheck = true;
          leftOperandCheck = true;
        }
        else if (NPReferencedTableMap.get(((ColumnReference)leftCol).getTableNumber()))
        {
          refCheck = true;
        }

        if (refCheck == false)
          return LOJ_bindResultColumns(anyChange);

        refCheck = false;
        if (leftOperandCheck == false && RPReferencedTableMap.get(((ColumnReference)rightCol).getTableNumber()))
        {
          refCheck = true;
        }
        else if (leftOperandCheck == true && NPReferencedTableMap.get(((ColumnReference)rightCol).getTableNumber()))
        {
          refCheck = true;
        }

        if (refCheck == false)
          return LOJ_bindResultColumns(anyChange);
      }
      else return LOJ_bindResultColumns(anyChange); //  get out of here

      vn = and.getRightOperand();
    }

    // Check if the logical right resultset is a composite inner and as such
    // that this current LOJ can be pushed through it.
    boolean       push = false;
    // logical right operand is another LOJ... so we may be able to push the
    // join
    if (logicalRightResultSet instanceof HalfOuterJoinNode)
    {
      // get the Null-producing operand of the child
      JBitSet  logicalNPRefTableMap = ((HalfOuterJoinNode)logicalRightResultSet).LOJgetNPReferencedTables(numTables);

      // does the current LOJ join predicate reference
      // logicalNPRefTableMap?  If not, we can push the current
      // join.
      vn = joinClause;
      push = true;
      while (vn instanceof AndNode)
      {
        and = (AndNode) vn;
        left = and.getLeftOperand();
        equals = (BinaryRelationalOperatorNode) left;
        leftCol = equals.getLeftOperand();
        rightCol = equals.getRightOperand();

        if (logicalNPRefTableMap.get(((ColumnReference)leftCol).getTableNumber()) ||
          logicalNPRefTableMap.get(((ColumnReference)rightCol).getTableNumber()))
        {
          push = false;
          break;
        }
View Full Code Here

      return this;
    }

    super.transformOuterJoins(predicateTree, numTables);

    JBitSet innerMap = new JBitSet(numTables);
    if (rightOuterJoin)
    {
      if (SanityManager.DEBUG)
      {
        SanityManager.ASSERT(! transformed,
          "right OJ not expected to be transformed into left OJ yet");
      }
      innerRS = leftResultSet;
    }
    else
    {
      innerRS = rightResultSet;
    }

    innerRS.fillInReferencedTableMap(innerMap);

    /* Walk predicates looking for
     * a null intolerant predicate on the inner table.
     */
    ValueNode vn = predicateTree;
    while (vn instanceof AndNode)
    {
      AndNode and = (AndNode) vn;
      ValueNode left = and.getLeftOperand();

      /* Skip IS NULL predicates as they are not null intolerant */
      if (left.isInstanceOf(C_NodeTypes.IS_NULL_NODE))
      {
        vn = and.getRightOperand();
        continue;
      }

      /* Only consider predicates that are relops */
      if (left instanceof RelationalOperator)
      {
        JBitSet refMap = new JBitSet(numTables);
        /* Do not consider method calls,
         * conditionals, field references, etc. */
        if (! (left.categorize(refMap, true)))
        {
          vn = and.getRightOperand();
          continue;
        }

        /* If the predicate is a null intolerant predicate
         * on the right side then we can flatten to an
         * inner join.  We do the xform here, flattening
         * will happen later.
         */
        for (int bit = 0; bit < numTables; bit++)
        {
          if (refMap.get(bit) && innerMap.get(bit))
          {
            // OJ -> IJ
            JoinNode ij =  (JoinNode)
                      getNodeFactory().getNode(
                        C_NodeTypes.JOIN_NODE,
View Full Code Here

    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

    **
    ** 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

    // always a safe option; further investigation required.

    BinaryRelationalOperatorNode opNode =
      (BinaryRelationalOperatorNode)getAndNode().getLeftOperand();

    JBitSet tNums = new JBitSet(getReferencedSet().size());
    BaseTableNumbersVisitor btnVis = new BaseTableNumbersVisitor(tNums);
    opNode.getLeftOperand().accept(btnVis);
    if (tNums.getFirstSetBit() == -1)
      return false;

    tNums.clearAll();
    opNode.getRightOperand().accept(btnVis);
    if (tNums.getFirstSetBit() == -1)
      return false;

    return true;
  }
View Full Code Here

    // Categorize the new AND node; among other things, this
    // call sets up the new operators's referenced table map,
    // which is important for correct pushing of the new
    // predicate.
    JBitSet tableMap = new JBitSet(
      childRSN.getReferencedTableMap().size());
    newAnd.categorize(tableMap, false);

    // Now put the pieces together to get a new predicate.
    Predicate newPred = (Predicate) getNodeFactory().getNode(
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.