Package org.apache.derby.iapi.util

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


   */
  void genExistsBaseTables(JBitSet referencedTableMap, FromList outerFromList,
               boolean isNotExists)
    throws StandardException
  {
    JBitSet      dependencyMap = (JBitSet) referencedTableMap.clone();

    // We currently only flatten single table from lists
    if (SanityManager.DEBUG)
    {
      if (size() != 1)
      {
        SanityManager.THROWASSERT(
          "size() expected to be 1, not " + size());
      }
    }

    /* Create the dependency map */
    int size = size();
    for (int index = 0; index < size; index++)
    {
      ResultSetNode ft = ((ProjectRestrictNode) elementAt(index)).getChildResult();
      if (ft instanceof FromTable)
      {
        dependencyMap.clear(((FromTable) ft).getTableNumber());
      }
    }

    /* Degenerate case - If flattening a non-correlated EXISTS subquery
     * then we need to make the table that is getting flattened dependendent on
     * all of the tables in the outer query block.  Gross but true.  Otherwise
     * that table can get chosen as an outer table and introduce duplicates.
     * The reason that duplicates can be introduced is that we do special processing
     * in the join to make sure only one qualified row from the right side is
     * returned.  If the exists table is on the left, we can return all the
     * qualified rows.
     */
    if (dependencyMap.getFirstSetBit() == -1)
    {
      int outerSize = outerFromList.size();
      for (int outer = 0; outer < outerSize; outer++)
        dependencyMap.or(((FromTable) outerFromList.elementAt(outer)).getReferencedTableMap());
    }

    /* Do the marking */
    for (int index = 0; index < size; index++)
    {
      FromTable fromTable = (FromTable) elementAt(index);
      if (fromTable instanceof ProjectRestrictNode)
      {
        ProjectRestrictNode prn = (ProjectRestrictNode) fromTable;
        if (prn.getChildResult() instanceof FromBaseTable)
        {
          FromBaseTable fbt = (FromBaseTable) prn.getChildResult();
          fbt.setExistsBaseTable(true, (JBitSet) dependencyMap.clone(), isNotExists);
        }
      }
    }
  }
View Full Code Here


                          C_NodeTypes.PREDICATE_LIST,
                          getContextManager()));
    }

    /* Allocate a dummy referenced table map */
    referencedTableMap = new JBitSet(numTables);
    referencedTableMap.set(tableNumber);
    return this;
  }
View Full Code Here

         * up then the single next logic for an EXISTS join does not work
         * because that row may get disqualified at a higher level.)
         */
        else if ( (isIN() || isANY() || isEXISTS() || flattenableNotExists) &&
              ((leftOperand == null) ? true :
               leftOperand.categorize(new JBitSet(numTables), false)) &&
              select.getWherePredicates().allPushable() &&
              singleFromBaseTable(select.getFromList()))
        {
          return flattenToExistsJoin(numTables,
                       outerFromList, outerSubqueryList,
View Full Code Here

        int numTables)
      throws StandardException
  {
    AndNode            andNode;
    BinaryComparisonOperatorNode bcoNode = null;
    JBitSet            tableMap;
    Predicate          predicate;
    ResultColumn        firstRC;
    ResultColumnList      resultColumns;
    UnaryComparisonOperatorNode  ucoNode = null;
    ValueNode          oldWhereClause;
    ValueNode          rightOperand;

    /* We have to ensure that the resultSet immediately under us has
     * a PredicateList, otherwise we can't push the predicate down.
     */
    resultSet = resultSet.ensurePredicateList(numTables);

    /* RESOLVE - once we understand how correlated columns will work,
     * we probably want to mark leftOperand as a correlated column
     */
    resultColumns = resultSet.getResultColumns();

    /*
    ** Create a new PR node.  Put it over the original subquery.  resulSet
    ** is now the new PR.  We give the chance that things under the PR node
    ** can be materialized.  See beetle 4373.
    */
    ResultColumnList newRCL = resultColumns.copyListAndObjects();
    newRCL.genVirtualColumnNodes(resultSet, resultColumns);
    resultSet = (ResultSetNode) getNodeFactory().getNode(
                    C_NodeTypes.PROJECT_RESTRICT_NODE,
                    resultSet,  // child
                    newRCL,      // result columns
                    null,      // restriction
                    null,       // restriction list
                    null,      // project subqueries
                    null,      // restrict subqueries 
                    null,
                    getContextManager());
    resultColumns = newRCL;
 
    firstRC = (ResultColumn) resultColumns.elementAt(0);
    rightOperand = firstRC.getExpression();

    bcoNode = getNewJoinCondition(leftOperand, rightOperand);

    ValueNode andLeft = bcoNode;

    /* For NOT IN or ALL, and if either side of the comparison is nullable, and the
     * subquery can not be flattened (because of that), we need to add IS NULL node
     * on top of the nullables, such that the behavior is (beetle 5173):
     *
     *    (1) If we have nulls in right operand, no row is returned.
     *    (2) If subquery result is empty before applying join predicate, every
     *      left row (including NULLs) is returned.
     *    (3) Otherwise, return {all left row} - {NULLs}
     */
    if (isNOT_IN() || isALL())
    {
      boolean leftNullable = leftOperand.getTypeServices().isNullable();
      boolean rightNullable = rightOperand.getTypeServices().isNullable();
      if (leftNullable || rightNullable)
      {
        /* Create a normalized structure.
         */
        BooleanConstantNode falseNode = (BooleanConstantNode) getNodeFactory().getNode(
                        C_NodeTypes.BOOLEAN_CONSTANT_NODE,
                        Boolean.FALSE,
                        getContextManager());
        OrNode newOr = (OrNode) getNodeFactory().getNode(
                        C_NodeTypes.OR_NODE,
                        bcoNode,
                        falseNode,
                        getContextManager());
        newOr.postBindFixup();
        andLeft = newOr;

        if (leftNullable)
        {
          UnaryComparisonOperatorNode leftIsNull = (UnaryComparisonOperatorNode)
                  getNodeFactory().getNode(
                            C_NodeTypes.IS_NULL_NODE,
                            leftOperand,
                            getContextManager());
          leftIsNull.bindComparisonOperator();
          newOr = (OrNode) getNodeFactory().getNode(
                          C_NodeTypes.OR_NODE,
                          leftIsNull,
                          andLeft,
                          getContextManager());
          newOr.postBindFixup();
          andLeft = newOr;
        }
        if (rightNullable)
        {
          UnaryComparisonOperatorNode rightIsNull = (UnaryComparisonOperatorNode)
                  getNodeFactory().getNode(
                            C_NodeTypes.IS_NULL_NODE,
                            rightOperand,
                            getContextManager());
          rightIsNull.bindComparisonOperator();
          newOr = (OrNode) getNodeFactory().getNode(
                          C_NodeTypes.OR_NODE,
                          rightIsNull,
                          andLeft,
                          getContextManager());
          newOr.postBindFixup();
          andLeft = newOr;
        }
      }
    }

    /* Place an AndNode above the <BinaryComparisonOperator> */
    andNode = (AndNode) getNodeFactory().getNode(
                          C_NodeTypes.AND_NODE,
                          andLeft,
                          getTrueNode(),
                          getContextManager());

    /* Build the referenced table map for the new predicate */
    tableMap = new JBitSet(numTables);
    andNode.postBindFixup();

    /* Put the AndNode under a Predicate */
    predicate = (Predicate) getNodeFactory().getNode(
                    C_NodeTypes.PREDICATE,
View Full Code Here

   */

  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

  }

  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

   * @exception StandardException      Thrown on error
   */
  JBitSet getTablesReferenced()
    throws StandardException
  {
    ReferencedTablesVisitor rtv = new ReferencedTablesVisitor(new JBitSet(0));
    accept(rtv);
    return rtv.getTableMap();
  }
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.