Search in sources :

Example 51 with ConglomerateDescriptor

use of org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor in project derby by apache.

the class DMLModStatementNode method getXAffectedIndexes.

/**
 *	Marks which indexes are affected by an UPDATE of the
 *	desired shape.
 *
 *	Is passed a list of updated columns. Does the following:
 *
 *	1)	finds all indices which overlap the updated columns
 *	2)	adds the index columns to a bitmap of affected columns
 *	3)	adds the index descriptors to a list of conglomerate
 *		descriptors.
 *
 *	@param	updatedColumns	a list of updated columns
 *	@param	colBitSet		OUT: evolving bitmap of affected columns
 * @param  conglomerates   OUT: list of affected indices
 *
 * @exception StandardException		Thrown on error
 */
static void getXAffectedIndexes(TableDescriptor baseTable, ResultColumnList updatedColumns, FormatableBitSet colBitSet, List<ConglomerateDescriptor> conglomerates) throws StandardException {
    ConglomerateDescriptor[] cds = baseTable.getConglomerateDescriptors();
    /* we only get distinct conglomerate numbers.  If duplicate indexes
		 * share one conglomerate, we only return one number.
		 */
    long[] distinctConglomNums = new long[cds.length - 1];
    int distinctCount = 0;
    for (int index = 0; index < cds.length; index++) {
        ConglomerateDescriptor cd = cds[index];
        if (!cd.isIndex()) {
            continue;
        }
        /*
			** If this index doesn't contain any updated
			** columns, then we can skip it.
			*/
        if ((updatedColumns != null) && (!updatedColumns.updateOverlaps(cd.getIndexDescriptor().baseColumnPositions()))) {
            continue;
        }
        if (conglomerates != null) {
            int i;
            for (i = 0; i < distinctCount; i++) {
                if (distinctConglomNums[i] == cd.getConglomerateNumber())
                    break;
            }
            if (// first appearence
            i == distinctCount) {
                distinctConglomNums[distinctCount++] = cd.getConglomerateNumber();
                conglomerates.add(cd);
            }
        }
        IndexRowGenerator ixd = cd.getIndexDescriptor();
        int[] cols = ixd.baseColumnPositions();
        if (colBitSet != null) {
            for (int i = 0; i < cols.length; i++) {
                colBitSet.set(cols[i]);
            }
        }
    // end IF
    }
// end loop through conglomerates
}
Also used : IndexRowGenerator(org.apache.derby.iapi.sql.dictionary.IndexRowGenerator) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 52 with ConglomerateDescriptor

use of org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor in project derby by apache.

the class DeleteNode method getReadMap.

/**
 *	Gets the map of all columns which must be read out of the base table.
 * These are the columns needed to:
 *
 *		o	maintain indices
 *		o	maintain foreign keys
 *
 *	The returned map is a FormatableBitSet with 1 bit for each column in the
 * table plus an extra, unsued 0-bit. If a 1-based column id must
 * be read from the base table, then the corresponding 1-based bit
 * is turned ON in the returned FormatableBitSet.
 *
 *	@param	dd				the data dictionary to look in
 *	@param	baseTable		the base table descriptor
 *
 *	@return	a FormatableBitSet of columns to be read out of the base table
 *
 * @exception StandardException		Thrown on error
 */
public FormatableBitSet getReadMap(DataDictionary dd, TableDescriptor baseTable) throws StandardException {
    boolean[] needsDeferredProcessing = new boolean[1];
    needsDeferredProcessing[0] = requiresDeferredProcessing();
    ArrayList<ConglomerateDescriptor> conglomerates = new ArrayList<ConglomerateDescriptor>();
    relevantTriggers = new TriggerDescriptorList();
    FormatableBitSet columnMap = DeleteNode.getDeleteReadMap(baseTable, conglomerates, relevantTriggers, needsDeferredProcessing);
    markAffectedIndexes(conglomerates);
    adjustDeferredFlag(needsDeferredProcessing[0]);
    return columnMap;
}
Also used : ArrayList(java.util.ArrayList) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList)

Example 53 with ConglomerateDescriptor

use of org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor in project derby by apache.

the class FromBaseTable method supersetOfUniqueIndex.

/**
 * Determine whether or not the columns marked as true in
 * the passed in array are a superset of any unique index
 * on this table.
 * This is useful for subquery flattening and distinct elimination
 * based on a uniqueness condition.
 *
 * @param eqCols	The columns to consider
 *
 * @return Whether or not the columns marked as true are a superset
 */
protected boolean supersetOfUniqueIndex(boolean[] eqCols) 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 inner = 0;
        for (; inner < keyColumns.length; inner++) {
            if (!eqCols[keyColumns[inner]]) {
                break;
            }
        }
        /* Did we get a full match? */
        if (inner == keyColumns.length) {
            return true;
        }
    }
    return false;
}
Also used : IndexDescriptor(org.apache.derby.catalog.IndexDescriptor) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 54 with ConglomerateDescriptor

use of org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor in project derby by apache.

the class FromBaseTable method isOrderedOn.

/**
 * Return whether or not the underlying ResultSet tree
 * is ordered on the specified columns.
 * RESOLVE - This method currently only considers the outermost table
 * of the query block.
 * RESOLVE - We do not currently push method calls down, so we don't
 * worry about whether the equals comparisons can be against a variant method.
 *
 * @param	crs					The specified ColumnReference[]
 * @param	permuteOrdering		Whether or not the order of the CRs in the array can be permuted
 * @param   fbtHolder           List that is to be filled with the FromBaseTable
 *
 * @return	Whether the underlying ResultSet tree
 * is ordered on the specified column.
 *
 * @exception StandardException		Thrown on error
 */
@Override
boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, List<FromBaseTable> fbtHolder) throws StandardException {
    // Verify that all CRs are from this table
    for (int index = 0; index < crs.length; index++) {
        if (crs[index].getTableNumber() != tableNumber) {
            return false;
        }
    }
    // Verify access path is an index
    ConglomerateDescriptor cd = getTrulyTheBestAccessPath().getConglomerateDescriptor();
    if (!cd.isIndex()) {
        return false;
    }
    // Now consider whether or not the CRs can be permuted
    boolean isOrdered;
    if (permuteOrdering) {
        isOrdered = isOrdered(crs, cd);
    } else {
        isOrdered = isStrictlyOrdered(crs, cd);
    }
    if (fbtHolder != null) {
        fbtHolder.add(this);
    }
    return isOrdered;
}
Also used : ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 55 with ConglomerateDescriptor

use of org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor in project derby by apache.

the class FromBaseTable method generateMaxSpecialResultSet.

private void generateMaxSpecialResultSet(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException {
    ConglomerateDescriptor cd = getTrulyTheBestAccessPath().getConglomerateDescriptor();
    CostEstimate costEst = getFinalCostEstimate();
    int colRefItem = (referencedCols == null) ? -1 : acb.addItem(referencedCols);
    boolean tableLockGranularity = tableDescriptor.getLockGranularity() == TableDescriptor.TABLE_LOCK_GRANULARITY;
    /*
		** getLastIndexKeyResultSet
		** (
		**		activation,			
		**		resultSetNumber,			
		**		resultRowAllocator,			
		**		conglomereNumber,			
		**		tableName,
		**		optimizeroverride			
		**		indexName,			
		**		colRefItem,			
		**		lockMode,			
		**		tableLocked,
		**		isolationLevel,
		**		optimizerEstimatedRowCount,
		**		optimizerEstimatedRowCost,
		**	);
		*/
    acb.pushGetResultSetFactoryExpression(mb);
    acb.pushThisAsActivation(mb);
    mb.push(getResultSetNumber());
    mb.push(acb.addItem(getResultColumns().buildRowTemplate(referencedCols, false)));
    mb.push(cd.getConglomerateNumber());
    mb.push(tableDescriptor.getName());
    // run time statistics.
    if (tableProperties != null)
        mb.push(org.apache.derby.iapi.util.PropertyUtil.sortProperties(tableProperties));
    else
        mb.pushNull("java.lang.String");
    pushIndexName(cd, mb);
    mb.push(colRefItem);
    mb.push(getTrulyTheBestAccessPath().getLockMode());
    mb.push(tableLockGranularity);
    mb.push(getCompilerContext().getScanIsolationLevel());
    mb.push(costEst.singleScanRowCount());
    mb.push(costEst.getEstimatedCost());
    mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getLastIndexKeyResultSet", ClassName.NoPutResultSet, 13);
}
Also used : CostEstimate(org.apache.derby.iapi.sql.compile.CostEstimate) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Aggregations

ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)66 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)19 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)17 TransactionController (org.apache.derby.iapi.store.access.TransactionController)13 Properties (java.util.Properties)12 UUID (org.apache.derby.catalog.UUID)12 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)12 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)12 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)11 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)11 IndexRowGenerator (org.apache.derby.iapi.sql.dictionary.IndexRowGenerator)10 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)10 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)8 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)8 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)8 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)7 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)7 RowLocation (org.apache.derby.iapi.types.RowLocation)6 ArrayList (java.util.ArrayList)5 IndexDescriptor (org.apache.derby.catalog.IndexDescriptor)5