Package org.apache.derby.iapi.util

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


    throws StandardException
  {
    FromTable    leftFromTable = (FromTable) leftResultSet;
    FromTable    rightFromTable = (FromTable) rightResultSet;

    JBitSet    leftReferencedTableMap = leftFromTable.getReferencedTableMap();
    JBitSet    rightReferencedTableMap = rightFromTable.getReferencedTableMap();

    /* Build a list of the join predicates that we can push down */
    // Walk outerPredicateList backwards due to possible deletes
    for (int index = outerPredicateList.size() - 1; index >= 0; index --)
    {
      JBitSet    curBitSet;
      Predicate predicate;

      predicate = (Predicate) outerPredicateList.elementAt(index);
      if (! predicate.getPushable())
      {
        continue;
      }

      curBitSet = predicate.getReferencedSet();
     
      /* Do we have a match? */
      JBitSet innerBitSet = (JBitSet) rightReferencedTableMap.clone();
      innerBitSet.or(leftReferencedTableMap);
      if (innerBitSet.contains(curBitSet))
      {
        /* Add the matching predicate to the push list */
        joinPredicates.addPredicate(predicate);

        /* Remap all of the ColumnReferences to point to the
View Full Code Here


    // The top most LOJ may be a join betw T and X and thus we can reorder the
  // LOJs.  However, as of 10/2002, we don't reorder LOJ mixed with join.
  public JBitSet LOJgetReferencedTables(int numTables)
        throws StandardException
  {
    JBitSet map = new JBitSet(numTables);

    map = (JBitSet) leftResultSet.LOJgetReferencedTables(numTables);
    if (map == null) return null;
    else map.or((JBitSet) rightResultSet.LOJgetReferencedTables(numTables));

    return map;
  }
View Full Code Here

    /* In order to tell if this is a legal join order, we
     * need to see if the assignedTableMap, ORed with the
     * outer tables that we are correlated with, contains
     * our dependency map.
     */
    JBitSet tempBitSet = (JBitSet) assignedTableMap;
    tempBitSet.or(correlationMap);

    /* Have all of our dependencies been satisified? */
    return tempBitSet.contains(dependencyMap);
  }
View Full Code Here

                          getContextManager()),
                 (PredicateList) getNodeFactory().getNode(
                           C_NodeTypes.PREDICATE_LIST,
                          getContextManager()));
    /* Generate the referenced table map */
    referencedTableMap = new JBitSet(numTables);
    referencedTableMap.set(tableNumber);

    /* Create the dependency map.  This FromVTI depends on any
     * tables which are referenced by the method call.  Note,
     * though, that such tables should NOT appear in this node's
     * referencedTableMap, since that field is really meant to
     * hold the table numbers for any FromTables which appear
     * AT OR UNDER the subtree whose root is this FromVTI.  That
     * said, the tables referenced by newInvocation do not appear
     * "under" this FromVTI--on the contrary, they must appear
     * "above" this FromVTI within the query tree in order to
     * be referenced by the newInvocation.  So newInvocation table
     * references do _not_ belong in this.referencedTableMap.
     * (DERBY-3288)
     */
    dependencyMap = new JBitSet(numTables);
    newInvocation.categorize(dependencyMap, false);

    // Make sure this FromVTI does not "depend" on itself.
    dependencyMap.clear(tableNumber);

    // Get a JBitSet of the outer tables represented in the parameter list
    correlationMap = new JBitSet(numTables);
    newInvocation.getCorrelationTables(correlationMap);

    return genProjectRestrict(numTables);
  }
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:",
            se);
              }
      }
      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

  }

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

              RelationalOperator.EQUALS_RELOP))
            {
              continue;
            }

            JBitSet referencedTables = and.getLeftOperand().getTablesReferenced();
            if (referencedTables.get(existsTableNumber))
            {
              predicatesTemp.removeElementAt(predicatesTempIndex);
              break;
            }
          }
        }
      }
    }

    /* Build an array of tableNumbers from this query block.
     * We will use that array to find out if we have at least
     * one table with a uniqueness condition based only on
     * constants, parameters and correlation columns.
     */
    tableNumbers = getTableNumbers();
    JBitSet[][] tableColMap = new JBitSet[size][size];
    boolean[] oneRow = new boolean[size];
    boolean oneRowResult = false;

    /* See if each table has a uniqueness condition */
    for (int index = 0; index < size; index++)
    {
      ProjectRestrictNode prn = (ProjectRestrictNode) elementAt(index);
      FromBaseTable fbt = (FromBaseTable) prn.getChildResult();

      // Skip over EXISTS FBT since they cannot introduce duplicates
      if (fbt.getExistsBaseTable())
      {
        oneRow[index] = true;
        continue;
      }

      int numColumns = fbt.getTableDescriptor().getNumberOfColumns();
      boolean[] eqOuterCols = new boolean[numColumns + 1];
      int tableNumber = fbt.getTableNumber();
      boolean resultColTable = false;
      for (int i = 0; i < size; i++)
        tableColMap[index][i] = new JBitSet(numColumns + 1);

      if (additionalCR != null &&
        additionalCR.getTableNumber() == tableNumber)
      {
        rcl.recordColumnReferences(eqOuterCols, tableColMap[index], index);
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.