Search in sources :

Example 61 with ConglomerateController

use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.

the class TabInfoImpl method deleteRows.

/**
 * @inheritDoc
 */
private int deleteRows(TransactionController tc, ExecIndexRow startKey, int startOp, Qualifier[][] qualifier, TupleFilter filter, ExecIndexRow stopKey, int stopOp, int indexNumber, boolean wait) throws StandardException {
    ConglomerateController heapCC;
    ScanController drivingScan;
    ExecIndexRow drivingIndexRow;
    RowLocation baseRowLocation;
    RowChanger rc;
    ExecRow baseRow = crf.makeEmptyRow();
    int rowsDeleted = 0;
    boolean passedFilter = true;
    rc = getRowChanger(tc, (int[]) null, baseRow);
    /*
		** If we have a start and a stop key, then we are going to 
		** get row locks, otherwise, we are getting table locks.
		** This may be excessive locking for the case where there
		** is a start key and no stop key or vice versa.
		*/
    int lockMode = ((startKey != null) && (stopKey != null)) ? TransactionController.MODE_RECORD : TransactionController.MODE_TABLE;
    /*
		** Don't use level 3 if we have the same start/stop key.
		*/
    int isolation = ((startKey != null) && (stopKey != null) && (startKey == stopKey)) ? TransactionController.ISOLATION_REPEATABLE_READ : TransactionController.ISOLATION_SERIALIZABLE;
    // Row level locking
    rc.open(lockMode, wait);
    DataValueDescriptor[] startKeyRow = startKey == null ? null : startKey.getRowArray();
    DataValueDescriptor[] stopKeyRow = stopKey == null ? null : stopKey.getRowArray();
    /* Open the heap conglomerate */
    heapCC = tc.openConglomerate(getHeapConglomerate(), false, (TransactionController.OPENMODE_FORUPDATE | ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)), lockMode, TransactionController.ISOLATION_REPEATABLE_READ);
    drivingScan = tc.openScan(// conglomerate to open
    getIndexConglomerate(indexNumber), // don't hold open across commit
    false, (TransactionController.OPENMODE_FORUPDATE | ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)), lockMode, isolation, // all fields as objects
    (FormatableBitSet) null, // start position - first row
    startKeyRow, // startSearchOperation
    startOp, // scanQualifier
    qualifier, // stop position - through last row
    stopKeyRow, // stopSearchOperation
    stopOp);
    // Get an index row based on the base row
    drivingIndexRow = getIndexRowFromHeapRow(getIndexRowGenerator(indexNumber), heapCC.newRowLocationTemplate(), crf.makeEmptyRow());
    while (drivingScan.fetchNext(drivingIndexRow.getRowArray())) {
        baseRowLocation = (RowLocation) drivingIndexRow.getColumn(drivingIndexRow.nColumns());
        boolean base_row_exists = heapCC.fetch(baseRowLocation, baseRow.getRowArray(), (FormatableBitSet) null);
        if (SanityManager.DEBUG) {
            // it can not be possible for heap row to disappear while
            // holding scan cursor on index at ISOLATION_REPEATABLE_READ.
            SanityManager.ASSERT(base_row_exists, "base row not found");
        }
        // only delete rows which pass the base-row filter
        if (filter != null) {
            passedFilter = filter.execute(baseRow).equals(true);
        }
        if (passedFilter) {
            rc.deleteRow(baseRow, baseRowLocation);
            rowsDeleted++;
        }
    }
    heapCC.close();
    drivingScan.close();
    rc.close();
    return rowsDeleted;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) RowChanger(org.apache.derby.iapi.sql.execute.RowChanger) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 62 with ConglomerateController

use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.

the class InsertResultSet method updateAllIndexes.

/**
 * Update all of the indexes on a table when doing a bulk insert
 * on an empty table.
 *
 * @exception StandardException					thrown on error
 */
private void updateAllIndexes(long newHeapConglom, InsertConstantAction constants, TableDescriptor td, DataDictionary dd, ExecRow fullTemplate) throws StandardException {
    int numIndexes = constants.irgs.length;
    /*
		** If we didn't actually read in any rows, then
		** we don't need to do anything, unless we were
		** doing a replace.
		*/
    if (indexRows == null) {
        if (bulkInsertReplace) {
            emptyIndexes(newHeapConglom, constants, td, dd, fullTemplate);
        }
        return;
    }
    dd.dropStatisticsDescriptors(td.getUUID(), null, tc);
    long[] newIndexCongloms = new long[numIndexes];
    indexConversionTable = new Hashtable<Long, Long>(numIndexes);
    // Populate each index
    for (int index = 0; index < numIndexes; index++) {
        ConglomerateController indexCC;
        Properties properties = new Properties();
        ConglomerateDescriptor cd;
        // Get the ConglomerateDescriptor for the index
        cd = td.getConglomerateDescriptor(constants.indexCIDS[index]);
        // Build the properties list for the new conglomerate
        indexCC = tc.openCompiledConglomerate(false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, constants.indexSCOCIs[index], indexDCOCIs[index]);
        // Get the properties on the old index
        indexCC.getInternalTablePropertySet(properties);
        /* Create the properties that language supplies when creating the
			 * the index.  (The store doesn't preserve these.)
			 */
        int indexRowLength = indexRows[index].nColumns();
        properties.put("baseConglomerateId", Long.toString(newHeapConglom));
        if (cd.getIndexDescriptor().isUnique()) {
            properties.put("nUniqueColumns", Integer.toString(indexRowLength - 1));
        } else {
            properties.put("nUniqueColumns", Integer.toString(indexRowLength));
        }
        if (cd.getIndexDescriptor().isUniqueWithDuplicateNulls() && !cd.getIndexDescriptor().hasDeferrableChecking()) {
            properties.put("uniqueWithDuplicateNulls", Boolean.toString(true));
        }
        properties.put("rowLocationColumn", Integer.toString(indexRowLength - 1));
        properties.put("nKeyFields", Integer.toString(indexRowLength));
        indexCC.close();
        // We can finally drain the sorter and rebuild the index
        // RESOLVE - all indexes are btrees right now
        // Populate the index.
        sorters[index].completedInserts();
        sorters[index] = null;
        rowSources[index] = new CardinalityCounter(tc.openSortRowSource(sortIds[index]));
        newIndexCongloms[index] = tc.createAndLoadConglomerate("BTREE", indexRows[index].getRowArray(), ordering[index], collation[index], properties, TransactionController.IS_DEFAULT, rowSources[index], (long[]) null);
        CardinalityCounter cCount = (CardinalityCounter) rowSources[index];
        long numRows;
        if ((numRows = cCount.getRowCount()) > 0) {
            long[] c = cCount.getCardinality();
            for (int i = 0; i < c.length; i++) {
                StatisticsDescriptor statDesc = new StatisticsDescriptor(dd, dd.getUUIDFactory().createUUID(), cd.getUUID(), td.getUUID(), "I", new StatisticsImpl(numRows, c[i]), i + 1);
                dd.addDescriptor(statDesc, null, DataDictionary.SYSSTATISTICS_CATALOG_NUM, true, tc);
            }
        }
        /* Update the DataDictionary
			 * RESOLVE - this will change in 1.4 because we will get
			 * back the same conglomerate number
			 *
			 * Update sys.sysconglomerates with new conglomerate #, if the
			 * conglomerate is shared by duplicate indexes, all the descriptors
			 * for those indexes need to be updated with the new number.
			 */
        dd.updateConglomerateDescriptor(td.getConglomerateDescriptors(constants.indexCIDS[index]), newIndexCongloms[index], tc);
        // Drop the old conglomerate
        tc.dropConglomerate(constants.indexCIDS[index]);
        indexConversionTable.put(constants.indexCIDS[index], newIndexCongloms[index]);
    }
}
Also used : StatisticsImpl(org.apache.derby.catalog.types.StatisticsImpl) StatisticsDescriptor(org.apache.derby.iapi.sql.dictionary.StatisticsDescriptor) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) Properties(java.util.Properties) LanguageProperties(org.apache.derby.iapi.sql.LanguageProperties) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 63 with ConglomerateController

use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.

the class LockTableConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *	This is the guts of the Execution-time logic for LOCK TABLE.
 *
 *	@see ConstantAction#executeConstantAction
 *
 * @exception StandardException		Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    ConglomerateController cc;
    TransactionController tc;
    /* Get a ConglomerateController for the base conglomerate */
    tc = activation.getTransactionController();
    try {
        cc = tc.openConglomerate(conglomerateNumber, false, (exclusiveMode) ? (TransactionController.OPENMODE_FORUPDATE | TransactionController.OPENMODE_FOR_LOCK_ONLY) : TransactionController.OPENMODE_FOR_LOCK_ONLY, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE);
        cc.close();
    } catch (StandardException se) {
        String msgId = se.getMessageId();
        if (se.isLockTimeoutOrDeadlock()) {
            String mode = (exclusiveMode) ? "EXCLUSIVE" : "SHARE";
            se = StandardException.newException(SQLState.LANG_CANT_LOCK_TABLE, se, fullTableName, mode);
        }
        throw se;
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 64 with ConglomerateController

use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.

the class DataDictionaryImpl method isSchemaReferenced.

/**
 * Is the schema id referenced by the system table in question?
 * Currently assumes that the schema id is in an index.
 * NOTE: could be generalized a bit, and possibly used
 * elsewhere...
 *
 * @param tc	transaction controller
 * @param ti	table info for the system table
 * @param indexId	index id
 * @param indexCol	1 based index column
 * @param schemaIdOrderable	the schemaid in a char orderable
 *
 * @return true if there is a reference to this schema
 *
 * @exception StandardException on error
 */
protected boolean isSchemaReferenced(TransactionController tc, TabInfoImpl ti, int indexId, int indexCol, DataValueDescriptor schemaIdOrderable) throws StandardException {
    ConglomerateController heapCC = null;
    ScanController scanController = null;
    boolean foundRow;
    FormatableBitSet colToCheck = new FormatableBitSet(indexCol);
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(indexId >= 0, "code needs to be enhanced" + " to support a table scan to find the index id");
    }
    colToCheck.set(indexCol - 1);
    ScanQualifier[][] qualifier = exFactory.getScanQualifier(1);
    qualifier[0][0].setQualifier(indexCol - 1, schemaIdOrderable, Orderable.ORDER_OP_EQUALS, false, false, false);
    try {
        heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
        scanController = tc.openScan(// conglomerate to open
        ti.getIndexConglomerate(indexId), // don't hold open across commit
        false, // for read
        0, // row locking
        TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // don't get any rows
        colToCheck, // start position - first row
        null, // startSearchOperation
        ScanController.GE, // scanQualifier,
        qualifier, // stop position - through last row
        null, // stopSearchOperation
        ScanController.GT);
        foundRow = (scanController.next());
    } finally {
        if (scanController != null) {
            scanController.close();
        }
        if (heapCC != null) {
            heapCC.close();
        }
    }
    return foundRow;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet)

Example 65 with ConglomerateController

use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.

the class DataDictionaryImpl method getRowLocationTemplate.

public RowLocation getRowLocationTemplate(LanguageConnectionContext lcc, TableDescriptor td) throws StandardException {
    RowLocation rl;
    ConglomerateController heapCC = null;
    TransactionController tc = lcc.getTransactionCompile();
    long tableId = td.getHeapConglomerateId();
    heapCC = tc.openConglomerate(tableId, false, 0, tc.MODE_RECORD, tc.ISOLATION_READ_COMMITTED);
    try {
        rl = heapCC.newRowLocationTemplate();
    } finally {
        heapCC.close();
    }
    return rl;
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) TransactionController(org.apache.derby.iapi.store.access.TransactionController) RowLocation(org.apache.derby.iapi.types.RowLocation)

Aggregations

ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)73 RowLocation (org.apache.derby.iapi.types.RowLocation)40 ScanController (org.apache.derby.iapi.store.access.ScanController)32 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)32 SQLLongint (org.apache.derby.iapi.types.SQLLongint)24 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)22 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)18 Properties (java.util.Properties)14 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)14 StandardException (org.apache.derby.shared.common.error.StandardException)12 TransactionController (org.apache.derby.iapi.store.access.TransactionController)11 SQLChar (org.apache.derby.iapi.types.SQLChar)9 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)8 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)6 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)5 ColumnOrdering (org.apache.derby.iapi.store.access.ColumnOrdering)5 UUID (org.apache.derby.catalog.UUID)4 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)4 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)4 IndexRowGenerator (org.apache.derby.iapi.sql.dictionary.IndexRowGenerator)4