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
}
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;
}
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;
}
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;
}
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);
}
Aggregations