Search in sources :

Example 31 with JBitSet

use of org.apache.derby.iapi.util.JBitSet in project derby by apache.

the class BinaryRelationalOperatorNode method selfComparison.

/**
 * @see RelationalOperator#selfComparison
 *
 * @exception StandardException		Thrown on error
 */
public boolean selfComparison(ColumnReference cr) throws StandardException {
    ValueNode otherSide;
    JBitSet tablesReferenced;
    /*
		** Figure out which side the given ColumnReference is on,
		** and look for the same table on the other side.
		*/
    if (leftOperand == cr) {
        otherSide = rightOperand;
    } else if (rightOperand == cr) {
        otherSide = leftOperand;
    } else {
        otherSide = null;
        if (SanityManager.DEBUG) {
            SanityManager.THROWASSERT("ColumnReference not found on either side of binary comparison.");
        }
    }
    tablesReferenced = otherSide.getTablesReferenced();
    /* Return true if the table we're looking for is in the bit map */
    return tablesReferenced.get(cr.getTableNumber());
}
Also used : JBitSet(org.apache.derby.iapi.util.JBitSet)

Example 32 with JBitSet

use of org.apache.derby.iapi.util.JBitSet in project derby by apache.

the class FromBaseTable method preprocess.

/**
 * Preprocess a ResultSetNode - this currently means:
 *	o  Generating a referenced table map for each ResultSetNode.
 *  o  Putting the WHERE and HAVING clauses in conjunctive normal form (CNF).
 *  o  Converting the WHERE and HAVING clauses into PredicateLists and
 *	   classifying them.
 *  o  Ensuring that a ProjectRestrictNode is generated on top of every
 *     FromBaseTable and generated in place of every FromSubquery.
 *  o  Pushing single table predicates down to the new ProjectRestrictNodes.
 *
 * @param numTables			The number of tables in the DML Statement
 * @param gbl				The group by list, if any
 * @param fromList			The from list, if any
 *
 * @return ResultSetNode at top of preprocessed tree.
 *
 * @exception StandardException		Thrown on error
 */
@Override
ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException {
    // 
    if (authorizeSYSUSERS) {
        int passwordColNum = SYSUSERSRowFactory.PASSWORD_COL_NUM;
        FormatableBitSet refCols = getResultColumns().getReferencedFormatableBitSet(false, true, false);
        if ((refCols.getLength() >= passwordColNum) && refCols.isSet(passwordColNum - 1)) {
            throw StandardException.newException(SQLState.HIDDEN_COLUMN, SYSUSERSRowFactory.TABLE_NAME, SYSUSERSRowFactory.PASSWORD_COL_NAME);
        }
    }
    /* Generate the referenced table map */
    setReferencedTableMap(new JBitSet(numTables));
    getReferencedTableMap().set(tableNumber);
    return genProjectRestrict(numTables);
}
Also used : JBitSet(org.apache.derby.iapi.util.JBitSet) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet)

Example 33 with JBitSet

use of org.apache.derby.iapi.util.JBitSet in project derby by apache.

the class FromBaseTable method LOJgetReferencedTables.

@Override
JBitSet LOJgetReferencedTables(int numTables) throws StandardException {
    JBitSet map = new JBitSet(numTables);
    fillInReferencedTableMap(map);
    return map;
}
Also used : JBitSet(org.apache.derby.iapi.util.JBitSet)

Example 34 with JBitSet

use of org.apache.derby.iapi.util.JBitSet in project derby by apache.

the class FromBaseTable method supersetOfUniqueIndex.

/**
 * Determine whether or not the columns marked as true in
 * the passed in join table matrix are a superset of any single column unique index
 * on this table.
 * This is useful for distinct elimination
 * based on a uniqueness condition.
 *
 * @param tableColMap	The columns to consider
 *
 * @return Whether or not the columns marked as true for one at least
 * 	one table are a superset
 */
protected boolean supersetOfUniqueIndex(JBitSet[] tableColMap) throws StandardException {
    ConglomerateDescriptor[] cds = tableDescriptor.getConglomerateDescriptors();
    /* Cycle through the ConglomerateDescriptors */
    for (int index = 0; index < cds.length; index++) {
        ConglomerateDescriptor cd = cds[index];
        if (!cd.isIndex()) {
            continue;
        }
        IndexDescriptor id = cd.getIndexDescriptor();
        if (!id.isUnique()) {
            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;
            }
        }
    }
    return false;
}
Also used : JBitSet(org.apache.derby.iapi.util.JBitSet) IndexDescriptor(org.apache.derby.catalog.IndexDescriptor) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 35 with JBitSet

use of org.apache.derby.iapi.util.JBitSet in project derby by apache.

the class FromList method genExistsBaseTables.

/**
 * Mark all of the FromBaseTables in the list as EXISTS FBTs.
 * Each EBT has the same dependency list - those tables that are referenced
 * minus the tables in the from list.
 *
 * @param referencedTableMap	The referenced table map.
 * @param outerFromList			FromList from outer query block
 * @param isNotExists			Whether or not for NOT EXISTS
 *
 * @exception StandardException		Thrown on error
 */
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);
            }
        }
    }
}
Also used : JBitSet(org.apache.derby.iapi.util.JBitSet)

Aggregations

JBitSet (org.apache.derby.iapi.util.JBitSet)39 OptimizablePredicate (org.apache.derby.iapi.sql.compile.OptimizablePredicate)12 OptimizablePredicateList (org.apache.derby.iapi.sql.compile.OptimizablePredicateList)7 Optimizable (org.apache.derby.iapi.sql.compile.Optimizable)2 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IndexDescriptor (org.apache.derby.catalog.IndexDescriptor)1 ContextManager (org.apache.derby.iapi.services.context.ContextManager)1 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)1 CostEstimate (org.apache.derby.iapi.sql.compile.CostEstimate)1 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)1 StandardException (org.apache.derby.shared.common.error.StandardException)1