Package org.apache.derby.iapi.util

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


              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


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

  {
    if (this instanceof FromTable)
    {
      if (((FromTable)this).tableNumber != -1)
      {
        JBitSet map = new JBitSet(numTables);
        map.set(((FromTable)this).tableNumber);
        return map;
      }
    }

    return null;
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

    /* 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);
    newInvocation.categorize(referencedTableMap, false);

    // Create the dependency map
    dependencyMap = new JBitSet(numTables);
    for (int index = 0; index < numTables; index++)
    {
      if ((index != tableNumber) && referencedTableMap.get(index))
      {
        dependencyMap.set(index);
      }
    }

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

  }

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

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

    {
      FromTable ft = (FromTable)innerTable;

      // First get a list of all of the base tables in the subtree
      // below innerTable.
      JBitSet tNums = new JBitSet(ft.getReferencedTableMap().size());
      BaseTableNumbersVisitor btnVis = new BaseTableNumbersVisitor(tNums);
      ft.accept(btnVis);

      // Now get a list of all table numbers referenced by the
      // join predicates that we'll be searching.
      JBitSet pNums = new JBitSet(tNums.size());
      Predicate pred = null;
      for (int i = 0; i < predList.size(); i++)
      {
        pred = (Predicate)predList.getOptPredicate(i);
        if (pred.isJoinPredicate())
          pNums.or(pred.getReferencedSet());
      }

      // If tNums and pNums have anything in common, then at
      // least one predicate in the list refers directly to
      // a base table beneath this node (as opposed to referring
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.