Search in sources :

Example 31 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class DataDictionaryImpl method getDescriptorViaIndexMinion.

private <T extends TupleDescriptor> T getDescriptorViaIndexMinion(int indexId, ExecIndexRow keyRow, ScanQualifier[][] scanQualifiers, TabInfoImpl ti, TupleDescriptor parentTupleDescriptor, List<? super T> list, Class<T> returnType, boolean forUpdate, int isolationLevel, TransactionController tc) throws StandardException {
    CatalogRowFactory rf = ti.getCatalogRowFactory();
    ConglomerateController heapCC;
    ExecIndexRow indexRow1;
    ExecRow outRow;
    RowLocation baseRowLocation;
    ScanController scanController;
    T td = null;
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(isolationLevel == TransactionController.ISOLATION_REPEATABLE_READ || isolationLevel == TransactionController.ISOLATION_READ_UNCOMMITTED);
    }
    outRow = rf.makeEmptyRow();
    heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, isolationLevel);
    /* Scan the index and go to the data pages for qualifying rows to
		 * build the column descriptor.
		 */
    scanController = tc.openScan(// conglomerate to open
    ti.getIndexConglomerate(indexId), // don't hold open across commit
    false, (forUpdate) ? TransactionController.OPENMODE_FORUPDATE : 0, TransactionController.MODE_RECORD, isolationLevel, // all fields as objects
    (FormatableBitSet) null, // start position - first row
    keyRow.getRowArray(), // startSearchOperation
    ScanController.GE, // scanQualifier,
    scanQualifiers, // stop position - through last row
    keyRow.getRowArray(), // stopSearchOperation
    ScanController.GT);
    while (true) {
        // create an index row template
        indexRow1 = getIndexRowFromHeapRow(ti.getIndexRowGenerator(indexId), heapCC.newRowLocationTemplate(), outRow);
        // from the table.
        if (!scanController.fetchNext(indexRow1.getRowArray())) {
            break;
        }
        baseRowLocation = (RowLocation) indexRow1.getColumn(indexRow1.nColumns());
        // RESOLVE paulat - remove the try catch block when track 3677 is fixed
        // just leave the contents of the try block
        // adding to get more info on track 3677
        boolean base_row_exists = false;
        try {
            base_row_exists = heapCC.fetch(baseRowLocation, outRow.getRowArray(), (FormatableBitSet) null);
        } catch (RuntimeException re) {
            if (SanityManager.DEBUG) {
                if (re instanceof AssertFailure) {
                    StringBuffer strbuf = new StringBuffer("Error retrieving base row in table " + ti.getTableName());
                    strbuf.append(": An ASSERT was thrown when trying to locate a row matching index row " + indexRow1 + " from index " + ti.getIndexName(indexId) + ", conglom number " + ti.getIndexConglomerate(indexId));
                    debugGenerateInfo(strbuf, tc, heapCC, ti, indexId);
                }
            }
            throw re;
        } catch (StandardException se) {
            if (SanityManager.DEBUG) {
                // do not want to catch lock timeout errors here
                if (se.getSQLState().equals("XSRS9")) {
                    StringBuffer strbuf = new StringBuffer("Error retrieving base row in table " + ti.getTableName());
                    strbuf.append(": A StandardException was thrown when trying to locate a row matching index row " + indexRow1 + " from index " + ti.getIndexName(indexId) + ", conglom number " + ti.getIndexConglomerate(indexId));
                    debugGenerateInfo(strbuf, tc, heapCC, ti, indexId);
                }
            }
            throw se;
        }
        if (SanityManager.DEBUG) {
            // holding scan cursor on index at ISOLATION_REPEATABLE_READ.
            if (!base_row_exists && (isolationLevel == TransactionController.ISOLATION_REPEATABLE_READ)) {
                StringBuffer strbuf = new StringBuffer("Error retrieving base row in table " + ti.getTableName());
                strbuf.append(": could not locate a row matching index row " + indexRow1 + " from index " + ti.getIndexName(indexId) + ", conglom number " + ti.getIndexConglomerate(indexId));
                debugGenerateInfo(strbuf, tc, heapCC, ti, indexId);
                // RESOLVE: for now, we are going to kill the VM
                // to help debug this problem.
                System.exit(1);
            // RESOLVE: not currently reached
            // SanityManager.THROWASSERT(strbuf.toString());
            }
        }
        if (!base_row_exists && (isolationLevel == TransactionController.ISOLATION_READ_UNCOMMITTED)) {
            // If isolationLevel == ISOLATION_READ_UNCOMMITTED we may
            // possibly see that the base row does not exist even if the
            // index row did.  This mode is currently only used by
            // TableNameInfo's call to hashAllTableDescriptorsByTableId,
            // cf. DERBY-3678, and by getStatisticsDescriptors,
            // cf. DERBY-4881.
            // 
            // For the former call, a table's schema descriptor is attempted
            // read, and if the base row for the schema has gone between
            // reading the index and the base table, the table that needs
            // this information has gone, too.  So, the table should not
            // be needed for printing lock timeout or deadlock
            // information, so we can safely just return an empty (schema)
            // descriptor. Furthermore, neither Timeout or DeadLock
            // diagnostics access the schema of a table descriptor, so it
            // seems safe to just return an empty schema descriptor for
            // the table.
            // 
            // There is a theoretical chance another row may have taken
            // the first one's place, but only if a compress of the base
            // table managed to run between the time we read the index and
            // the base row, which seems unlikely so we ignore that.
            // 
            // Even the index row may be gone in the above use case, of
            // course, and that case also returns an empty descriptor
            // since no match is found.
            td = null;
        } else {
            // normal case
            td = returnType.cast(rf.buildDescriptor(outRow, parentTupleDescriptor, this));
        }
        /* If list is null, then caller only wants a single descriptor - we're done
			 * else just add the current descriptor to the list.
			 */
        if (list == null) {
            break;
        } else if (td != null) {
            list.add(td);
        }
    }
    scanController.close();
    heapCC.close();
    return td;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) CatalogRowFactory(org.apache.derby.iapi.sql.dictionary.CatalogRowFactory) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) StandardException(org.apache.derby.shared.common.error.StandardException) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) AssertFailure(org.apache.derby.shared.common.sanity.AssertFailure) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 32 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class DataDictionaryImpl method getSubCheckConstraint.

/**
 * Get a SubCheckConstraintDescriptor from syschecks for
 * the specified constraint id.  (Useful for check constraints.)
 *
 * @param constraintId	The UUID for the constraint.
 *
 * @return SubCheckConstraintDescriptor	The Sub descriptor for the constraint.
 *
 * @exception StandardException		Thrown on failure
 */
private SubCheckConstraintDescriptor getSubCheckConstraint(UUID constraintId) throws StandardException {
    DataValueDescriptor constraintIDOrderable = null;
    TabInfoImpl ti = getNonCoreTI(SYSCHECKS_CATALOG_NUM);
    /* Use constraintIDOrderable in both start and stop positions for scan */
    constraintIDOrderable = getIDValueAsCHAR(constraintId);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow.setColumn(1, constraintIDOrderable);
    return getDescriptorViaIndex(SYSCHECKSRowFactory.SYSCHECKS_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, SubCheckConstraintDescriptor.class, false);
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 33 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class DataDictionaryImpl method dropConstraintDescriptor.

/**
 * Drops the given ConstraintDescriptor from the data dictionary.
 *
 * @param descriptor	The descriptor to drop
 * @param tc			The TransactionController
 *
 * @exception StandardException		Thrown on error
 */
public void dropConstraintDescriptor(ConstraintDescriptor descriptor, TransactionController tc) throws StandardException {
    ExecIndexRow keyRow = null;
    DataValueDescriptor schemaIDOrderable;
    DataValueDescriptor constraintNameOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM);
    switch(descriptor.getConstraintType()) {
        case DataDictionary.PRIMARYKEY_CONSTRAINT:
        case DataDictionary.FOREIGNKEY_CONSTRAINT:
        case DataDictionary.UNIQUE_CONSTRAINT:
            dropSubKeyConstraint(descriptor, tc);
            break;
        case DataDictionary.CHECK_CONSTRAINT:
            dropSubCheckConstraint(descriptor.getUUID(), tc);
            break;
    }
    /* Use constraintNameOrderable and schemaIdOrderable in both start 
		 * and stop position for index 2 scan. 
		 */
    constraintNameOrderable = new SQLVarchar(descriptor.getConstraintName());
    schemaIDOrderable = getIDValueAsCHAR(descriptor.getSchemaDescriptor().getUUID());
    /* Set up the start/stop position for the scan */
    keyRow = (ExecIndexRow) exFactory.getIndexableRow(2);
    keyRow.setColumn(1, constraintNameOrderable);
    keyRow.setColumn(2, schemaIDOrderable);
    ti.deleteRow(tc, keyRow, SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX2_ID);
}
Also used : DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 34 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class DataDictionaryImpl method updateLockGranularity.

/**
 * Update the lockGranularity for the specified table.
 *
 * @param td				The TableDescriptor for the table
 * @param schema			The SchemaDescriptor for the table
 * @param lockGranularity	The new lockGranularity
 * @param tc				The TransactionController to use.
 *
 * @exception StandardException		Thrown on error
 */
public void updateLockGranularity(TableDescriptor td, SchemaDescriptor schema, char lockGranularity, TransactionController tc) throws StandardException {
    ExecRow row;
    DataValueDescriptor schemaIDOrderable;
    DataValueDescriptor tableNameOrderable;
    TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM];
    SYSTABLESRowFactory rf = (SYSTABLESRowFactory) ti.getCatalogRowFactory();
    /* Use tableIdOrderable and schemaIdOrderable in both start 
		 * and stop position for index 1 scan. 
		 */
    tableNameOrderable = new SQLVarchar(td.getName());
    schemaIDOrderable = getIDValueAsCHAR(schema.getUUID());
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow1 = exFactory.getIndexableRow(2);
    keyRow1.setColumn(1, tableNameOrderable);
    keyRow1.setColumn(2, schemaIDOrderable);
    // build the row to be stuffed into SYSTABLES.
    row = rf.makeRow(td, schema);
    // update row in catalog (no indexes)
    boolean[] bArray = new boolean[2];
    for (int index = 0; index < 2; index++) {
        bArray[index] = false;
    }
    ti.updateRow(keyRow1, row, SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, bArray, (int[]) null, tc);
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 35 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class DataDictionaryImpl method getViewDescriptorScan.

/**
 * Get the information for the view from sys.sysviews.
 *
 * @param tdi					The TableDescriptor for the view.
 *
 * @return ViewDescriptor	The ViewDescriptor for the view.
 *
 * @exception StandardException		Thrown on error
 */
private ViewDescriptor getViewDescriptorScan(TableDescriptor tdi) throws StandardException {
    ViewDescriptor vd;
    DataValueDescriptor viewIdOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSVIEWS_CATALOG_NUM);
    UUID viewID = tdi.getUUID();
    /* Use viewIdOrderable in both start 
		 * and stop position for scan. 
		 */
    viewIdOrderable = getIDValueAsCHAR(viewID);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(1);
    keyRow.setColumn(1, viewIdOrderable);
    vd = getDescriptorViaIndex(SYSVIEWSRowFactory.SYSVIEWS_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, ViewDescriptor.class, false);
    if (vd != null) {
        vd.setViewName(tdi.getName());
    }
    return vd;
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) ScanQualifier(org.apache.derby.iapi.sql.execute.ScanQualifier) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) ArrayList(java.util.ArrayList) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList) List(java.util.List) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) LinkedList(java.util.LinkedList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor)

Aggregations

ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)110 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)72 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)34 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)30 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)27 SQLChar (org.apache.derby.iapi.types.SQLChar)22 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)14 SQLLongint (org.apache.derby.iapi.types.SQLLongint)13 RowLocation (org.apache.derby.iapi.types.RowLocation)12 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)10 ScanController (org.apache.derby.iapi.store.access.ScanController)9 UUID (org.apache.derby.catalog.UUID)8 ArrayList (java.util.ArrayList)7 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)6 ConglomerateDescriptorList (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList)6 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)6 TransactionController (org.apache.derby.iapi.store.access.TransactionController)6 Properties (java.util.Properties)5 PermissionsDescriptor (org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor)5 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)5