Search in sources :

Example 16 with ConglomerateDescriptor

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

the class BaseJoinStrategy method fillInScanArgs2.

final void fillInScanArgs2(MethodBuilder mb, Optimizable innerTable, int bulkFetch, int colRefItem, int indexColItem, int lockMode, boolean tableLocked, int isolationLevel) throws StandardException {
    mb.push(innerTable.getBaseTableName());
    // run time statistics.
    if (innerTable.getProperties() != null)
        mb.push(PropertyUtil.sortProperties(innerTable.getProperties()));
    else
        mb.pushNull("java.lang.String");
    ConglomerateDescriptor cd = innerTable.getTrulyTheBestAccessPath().getConglomerateDescriptor();
    if (cd.isConstraint()) {
        DataDictionary dd = innerTable.getDataDictionary();
        TableDescriptor td = innerTable.getTableDescriptor();
        ConstraintDescriptor constraintDesc = dd.getConstraintDescriptor(td, cd.getUUID());
        mb.push(constraintDesc.getConstraintName());
    } else if (cd.isIndex()) {
        mb.push(cd.getConglomerateName());
    } else {
        mb.pushNull("java.lang.String");
    }
    // Whether or not the conglomerate is the backing index for a constraint
    mb.push(cd.isConstraint());
    // tell it whether it's to open for update, which we should do if
    // it's an update or delete statement, or if it's the target
    // table of an updatable cursor.
    mb.push(innerTable.forUpdate());
    mb.push(colRefItem);
    mb.push(indexColItem);
    mb.push(lockMode);
    mb.push(tableLocked);
    mb.push(isolationLevel);
    if (bulkFetch > 0) {
        mb.push(bulkFetch);
        // If the table references LOBs, we want to disable bulk fetching
        // when the cursor is holdable. Otherwise, a commit could close
        // LOBs before they have been returned to the user.
        mb.push(innerTable.hasLargeObjectColumns());
    }
    /* 1 row scans (avoiding 2nd next()) are
 		 * only meaningful for some join strategies.
		 * (Only an issue for outer table, which currently
		 * can only be nested loop, as avoidance of 2nd next
		 * on inner table already factored in to join node.)
		 */
    if (validForOutermostTable()) {
        mb.push(innerTable.isOneRowScan());
    }
    mb.push(innerTable.getTrulyTheBestAccessPath().getCostEstimate().rowCount());
    mb.push(innerTable.getTrulyTheBestAccessPath().getCostEstimate().getEstimatedCost());
}
Also used : ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 17 with ConglomerateDescriptor

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

the class GenericLanguageConnectionContext method cleanupTempTableOnCommitOrRollback.

/**
 * If dropAndRedeclare is true, that means we have come here for temp
 * tables with on commit delete rows and no held curosr open on them. We
 * will drop the existing conglomerate and redeclare a new conglomerate
 * similar to old conglomerate. This is a more efficient way of deleting
 * all rows from the table.
 *
 * If dropAndRedeclare is false, that means we have come here for the
 * rollback cleanup work. We are trying to restore old definition of the
 * temp table (because the drop on it is being rolled back).
 */
private TableDescriptor cleanupTempTableOnCommitOrRollback(TableDescriptor td, boolean dropAndRedeclare) throws StandardException {
    TransactionController tc = getTransactionExecute();
    // create new conglomerate with same properties as the old conglomerate
    // and same row template as the old conglomerate
    long conglomId = tc.createConglomerate(// we're requesting a heap conglomerate
    "heap", // row template
    td.getEmptyExecRow().getRowArray(), // column sort order - not required for heap
    null, // same ids as old conglomerate
    td.getColumnCollationIds(), // properties
    null, (TransactionController.IS_TEMPORARY | TransactionController.IS_KEPT));
    long cid = td.getHeapConglomerateId();
    // remove the old conglomerate descriptor from the table descriptor
    ConglomerateDescriptor cgd = td.getConglomerateDescriptor(cid);
    td.getConglomerateDescriptorList().dropConglomerateDescriptorByUUID(cgd.getUUID());
    // add the new conglomerate descriptor to the table descriptor
    cgd = getDataDictionary().getDataDescriptorGenerator().newConglomerateDescriptor(conglomId, null, false, null, false, null, td.getUUID(), td.getSchemaDescriptor().getUUID());
    ConglomerateDescriptorList conglomList = td.getConglomerateDescriptorList();
    conglomList.add(cgd);
    // reset the heap conglomerate number in table descriptor to -1 so it
    // will be refetched next time with the new value
    td.resetHeapConglomNumber();
    if (dropAndRedeclare) {
        // remove the old conglomerate from the system
        tc.dropConglomerate(cid);
        replaceDeclaredGlobalTempTable(td.getName(), td);
    }
    return (td);
}
Also used : ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) TransactionController(org.apache.derby.iapi.store.access.TransactionController) XATransactionController(org.apache.derby.iapi.store.access.XATransactionController) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 18 with ConglomerateDescriptor

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

the class CreateConstraintConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *	This is the guts of the Execution-time logic for CREATE CONSTRAINT.
 *  <P>
 *  A constraint is represented as:
 *  <UL>
 *  <LI> ConstraintDescriptor.
 *  </UL>
 *  If a backing index is required then the index will
 *  be created through an CreateIndexConstantAction setup
 *  by the compiler.
 *  <BR>
 *  Dependencies are created as:
 *  <UL>
 *  <LI> ConstraintDescriptor depends on all the providers collected
 *  at compile time and passed into the constructor.
 *  <LI> For a FOREIGN KEY constraint ConstraintDescriptor depends
 *  on the ConstraintDescriptor for the referenced constraints
 *  and the privileges required to create the constraint.
 *  </UL>
 *
 *  @see ConstraintDescriptor
 *  @see CreateIndexConstantAction
 *	@see ConstantAction#executeConstantAction
 *
 * @exception StandardException		Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    ConglomerateDescriptor conglomDesc = null;
    ConglomerateDescriptor[] conglomDescs = null;
    ConstraintDescriptor conDesc = null;
    TableDescriptor td = null;
    UUID indexId = null;
    String uniqueName;
    String backingIndexName;
    /* RESOLVE - blow off not null constraints for now (and probably for ever) */
    if (constraintType == DataDictionary.NOTNULL_CONSTRAINT) {
        return;
    }
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();
    cf = lcc.getLanguageConnectionFactory().getClassFactory();
    /*
		** Inform the data dictionary that we are about to write to it.
		** There are several calls to data dictionary "get" methods here
		** that might be done in "read" mode in the data dictionary, but
		** it seemed safer to do this whole operation in "write" mode.
		**
		** We tell the data dictionary we're done writing at the end of
		** the transaction.
		*/
    dd.startWriting(lcc);
    /* Table gets locked in AlterTableConstantAction */
    /*
		** If the schema descriptor is null, then
		** we must have just read ourselves in.  
		** So we will get the corresponding schema
		** descriptor from the data dictionary.
		*/
    SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true);
    /* Try to get the TableDescriptor from
		 * the Activation. We will go to the
		 * DD if not there. (It should always be
		 * there except when in a target.)
		 */
    td = activation.getDDLTableDescriptor();
    if (td == null) {
        /* tableId will be non-null if adding a
			 * constraint to an existing table.
			 */
        if (tableId != null) {
            td = dd.getTableDescriptor(tableId);
        } else {
            td = dd.getTableDescriptor(tableName, sd, tc);
        }
        if (td == null) {
            throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
        }
        activation.setDDLTableDescriptor(td);
    }
    /* Generate the UUID for the backing index.  This will become the
		 * constraint's name, if no name was specified.
		 */
    UUIDFactory uuidFactory = dd.getUUIDFactory();
    UUID constrId = uuidFactory.createUUID();
    /* Create the index, if there's one for this constraint */
    if (indexAction != null) {
        if (indexAction.getIndexName() == null) {
            /* Set the index name */
            backingIndexName = uuidFactory.createUUID().toString();
            indexAction.setIndexName(backingIndexName);
        } else {
            backingIndexName = indexAction.getIndexName();
        }
        indexAction.setConstraintID(constrId);
        /* Create the index */
        indexAction.executeConstantAction(activation);
        /* Get the conglomerate descriptor for the backing index */
        conglomDescs = td.getConglomerateDescriptors();
        for (int index = 0; index < conglomDescs.length; index++) {
            conglomDesc = conglomDescs[index];
            /* Check for conglomerate being an index first, since
				 * name is null for heap.
				 */
            if (conglomDesc.isIndex() && backingIndexName.equals(conglomDesc.getConglomerateName())) {
                break;
            }
        }
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(conglomDesc != null, "conglomDesc is expected to be non-null after search for backing index");
            SanityManager.ASSERT(conglomDesc.isIndex(), "conglomDesc is expected to be indexable after search for backing index");
            SanityManager.ASSERT(conglomDesc.getConglomerateName().equals(backingIndexName), "conglomDesc name expected to be the same as backing index name after search for backing index");
        }
        indexId = conglomDesc.getUUID();
    }
    boolean[] defaults = new boolean[] { ConstraintDefinitionNode.DEFERRABLE_DEFAULT, ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT, ConstraintDefinitionNode.ENFORCED_DEFAULT };
    for (int i = 0; i < characteristics.length; i++) {
        if (characteristics[i] != defaults[i]) {
            dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_11, "DEFERRED CONSTRAINTS");
            if (constraintType == DataDictionary.NOTNULL_CONSTRAINT || !characteristics[2]) /* not enforced */
            {
                // Remove when feature DERBY-532 is completed
                if (!PropertyUtil.getSystemProperty("derby.constraintsTesting", "false").equals("true")) {
                    throw StandardException.newException(SQLState.NOT_IMPLEMENTED, "non-default constraint characteristics");
                }
            }
        }
    }
    /* Now, lets create the constraint descriptor */
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    switch(constraintType) {
        case DataDictionary.PRIMARYKEY_CONSTRAINT:
            conDesc = ddg.newPrimaryKeyConstraintDescriptor(td, constraintName, // deferable,
            characteristics[0], // initiallyDeferred,
            characteristics[1], // int[],
            genColumnPositions(td, false), constrId, indexId, sd, characteristics[2], // referenceCount
            0);
            dd.addConstraintDescriptor(conDesc, tc);
            break;
        case DataDictionary.UNIQUE_CONSTRAINT:
            conDesc = ddg.newUniqueConstraintDescriptor(td, constraintName, // deferable,
            characteristics[0], // initiallyDeferred,
            characteristics[1], // int[],
            genColumnPositions(td, false), constrId, indexId, sd, characteristics[2], // referenceCount
            0);
            dd.addConstraintDescriptor(conDesc, tc);
            break;
        case DataDictionary.CHECK_CONSTRAINT:
            conDesc = ddg.newCheckConstraintDescriptor(td, constraintName, // deferable,
            characteristics[0], // initiallyDeferred,
            characteristics[1], constrId, constraintText, // int[],
            new ReferencedColumnsDescriptorImpl(genColumnPositions(td, false)), sd, characteristics[2]);
            dd.addConstraintDescriptor(conDesc, tc);
            storeConstraintDependenciesOnPrivileges(activation, conDesc, null, providerInfo);
            break;
        case DataDictionary.FOREIGNKEY_CONSTRAINT:
            ReferencedKeyConstraintDescriptor referencedConstraint = DDUtils.locateReferencedConstraint(dd, td, constraintName, columnNames, otherConstraintInfo);
            DDUtils.validateReferentialActions(dd, td, constraintName, otherConstraintInfo, columnNames);
            conDesc = ddg.newForeignKeyConstraintDescriptor(td, constraintName, // deferable,
            characteristics[0], // initiallyDeferred,
            characteristics[1], // int[],
            genColumnPositions(td, false), constrId, indexId, sd, referencedConstraint, characteristics[2], otherConstraintInfo.getReferentialActionDeleteRule(), otherConstraintInfo.getReferentialActionUpdateRule());
            // try to create the constraint first, because it
            // is expensive to do the bulk check, find obvious
            // errors first
            dd.addConstraintDescriptor(conDesc, tc);
            /* No need to do check if we're creating a 
				 * table.
				 */
            if ((!forCreateTable) && dd.activeConstraint(conDesc)) {
                validateFKConstraint(activation, tc, dd, (ForeignKeyConstraintDescriptor) conDesc, referencedConstraint, ((CreateIndexConstantAction) indexAction).getIndexTemplateRow());
            }
            /* Create stored dependency on the referenced constraint */
            dm.addDependency(conDesc, referencedConstraint, lcc.getContextManager());
            // store constraint's dependency on REFERENCES privileges in the dependeny system
            storeConstraintDependenciesOnPrivileges(activation, conDesc, referencedConstraint.getTableId(), providerInfo);
            break;
        case DataDictionary.MODIFY_CONSTRAINT:
            throw StandardException.newException(SQLState.NOT_IMPLEMENTED, "ALTER CONSTRAINT");
        default:
            if (SanityManager.DEBUG) {
                SanityManager.THROWASSERT("contraintType (" + constraintType + ") has unexpected value");
            }
            break;
    }
    /* Create stored dependencies for each provider */
    if (providerInfo != null) {
        for (int ix = 0; ix < providerInfo.length; ix++) {
            Provider provider = null;
            /* We should always be able to find the Provider */
            provider = (Provider) providerInfo[ix].getDependableFinder().getDependable(dd, providerInfo[ix].getObjectId());
            dm.addDependency(conDesc, provider, lcc.getContextManager());
        }
    }
    /* Finally, invalidate off of the table descriptor(s)
		 * to ensure that any dependent statements get
		 * re-compiled.
		 */
    if (!forCreateTable) {
        dm.invalidateFor(td, DependencyManager.CREATE_CONSTRAINT, lcc);
    }
    if (constraintType == DataDictionary.FOREIGNKEY_CONSTRAINT) {
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(conDesc != null, "conDesc expected to be non-null");
            if (!(conDesc instanceof ForeignKeyConstraintDescriptor)) {
                SanityManager.THROWASSERT("conDesc expected to be instance of ForeignKeyConstraintDescriptor, not " + conDesc.getClass().getName());
            }
        }
        dm.invalidateFor(((ForeignKeyConstraintDescriptor) conDesc).getReferencedConstraint().getTableDescriptor(), DependencyManager.CREATE_CONSTRAINT, lcc);
    }
    this.constraintId = constrId;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) UUIDFactory(org.apache.derby.iapi.services.uuid.UUIDFactory) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) ReferencedColumnsDescriptorImpl(org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) ForeignKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) Provider(org.apache.derby.iapi.sql.depend.Provider) DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ReferencedKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor) ForeignKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) ReferencedKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor) UUID(org.apache.derby.catalog.UUID) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 19 with ConglomerateDescriptor

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

the class CreateTableConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *	This is the guts of the Execution-time logic for CREATE TABLE.
 *
 *	@see ConstantAction#executeConstantAction
 *
 * @exception StandardException		Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    TableDescriptor td;
    UUID toid;
    SchemaDescriptor schemaDescriptor;
    ColumnDescriptor columnDescriptor;
    ExecRow template;
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();
    /* Mark the activation as being for create table */
    activation.setForCreateTable();
    // setup for create conglomerate call:
    // o create row template to tell the store what type of rows this
    // table holds.
    // o create array of collation id's to tell collation id of each
    // column in table.
    template = RowUtil.getEmptyValueRow(columnInfo.length, lcc);
    int[] collation_ids = new int[columnInfo.length];
    for (int ix = 0; ix < columnInfo.length; ix++) {
        ColumnInfo col_info = columnInfo[ix];
        if (col_info.defaultValue != null) {
            /* If there is a default value, use it, otherwise use null */
            template.setColumn(ix + 1, col_info.defaultValue);
        } else {
            template.setColumn(ix + 1, col_info.dataType.getNull());
        }
        // get collation info for each column.
        collation_ids[ix] = col_info.dataType.getCollationType();
    }
    /* create the conglomerate to hold the table's rows
		 * RESOLVE - If we ever have a conglomerate creator
		 * that lets us specify the conglomerate number then
		 * we will need to handle it here.
		 */
    long conglomId = tc.createConglomerate(// we're requesting a heap conglomerate
    "heap", // row template
    template.getRowArray(), // column sort order - not required for heap
    null, collation_ids, // properties
    properties, tableType == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE ? (TransactionController.IS_TEMPORARY | TransactionController.IS_KEPT) : TransactionController.IS_DEFAULT);
    /*
		** Inform the data dictionary that we are about to write to it.
		** There are several calls to data dictionary "get" methods here
		** that might be done in "read" mode in the data dictionary, but
		** it seemed safer to do this whole operation in "write" mode.
		**
		** We tell the data dictionary we're done writing at the end of
		** the transaction.
		*/
    if (tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE)
        dd.startWriting(lcc);
    SchemaDescriptor sd;
    if (tableType == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE)
        sd = dd.getSchemaDescriptor(schemaName, tc, true);
    else
        sd = DDLConstantAction.getSchemaDescriptorForCreate(dd, activation, schemaName);
    // 
    // Create a new table descriptor.
    // 
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    if (tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
        td = ddg.newTableDescriptor(tableName, sd, tableType, lockGranularity);
        dd.addDescriptor(td, sd, DataDictionary.SYSTABLES_CATALOG_NUM, false, tc);
    } else {
        td = ddg.newTableDescriptor(tableName, sd, tableType, onCommitDeleteRows, onRollbackDeleteRows);
        td.setUUID(dd.getUUIDFactory().createUUID());
    }
    toid = td.getUUID();
    // Save the TableDescriptor off in the Activation
    activation.setDDLTableDescriptor(td);
    /* NOTE: We must write the columns out to the system
		 * tables before any of the conglomerates, including
		 * the heap, since we read the columns before the
		 * conglomerates when building a TableDescriptor.
		 * This will hopefully reduce the probability of
		 * a deadlock involving those system tables.
		 */
    // for each column, stuff system.column
    int index = 1;
    ColumnDescriptor[] cdlArray = new ColumnDescriptor[columnInfo.length];
    for (int ix = 0; ix < columnInfo.length; ix++) {
        UUID defaultUUID = columnInfo[ix].newDefaultUUID;
        /* Generate a UUID for the default, if one exists
			 * and there is no default id yet.
			 */
        if (columnInfo[ix].defaultInfo != null && defaultUUID == null) {
            defaultUUID = dd.getUUIDFactory().createUUID();
        }
        if (// dealing with autoinc column
        columnInfo[ix].autoincInc != 0) {
            columnDescriptor = new ColumnDescriptor(columnInfo[ix].name, index++, columnInfo[ix].dataType, columnInfo[ix].defaultValue, columnInfo[ix].defaultInfo, td, defaultUUID, columnInfo[ix].autoincStart, columnInfo[ix].autoincInc, columnInfo[ix].autoinc_create_or_modify_Start_Increment, columnInfo[ix].autoincCycle);
            // 
            if (dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_11, null)) {
                CreateSequenceConstantAction csca = makeCSCA(columnInfo[ix], TableDescriptor.makeSequenceName(toid));
                csca.executeConstantAction(activation);
            }
        } else {
            columnDescriptor = new ColumnDescriptor(columnInfo[ix].name, index++, columnInfo[ix].dataType, columnInfo[ix].defaultValue, columnInfo[ix].defaultInfo, td, defaultUUID, columnInfo[ix].autoincStart, columnInfo[ix].autoincInc, columnInfo[ix].autoincCycle);
        }
        cdlArray[ix] = columnDescriptor;
    }
    if (tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
        dd.addDescriptorArray(cdlArray, td, DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);
    }
    // now add the column descriptors to the table.
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    for (int i = 0; i < cdlArray.length; i++) cdl.add(cdlArray[i]);
    // 
    // Create a conglomerate desciptor with the conglomId filled in and
    // add it.
    // 
    // RESOLVE: Get information from the conglomerate descriptor which
    // was provided.
    // 
    ConglomerateDescriptor cgd = ddg.newConglomerateDescriptor(conglomId, null, false, null, false, null, toid, sd.getUUID());
    if (tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
        dd.addDescriptor(cgd, sd, DataDictionary.SYSCONGLOMERATES_CATALOG_NUM, false, tc);
    }
    // add the newly added conglomerate to the table descriptor
    ConglomerateDescriptorList conglomList = td.getConglomerateDescriptorList();
    conglomList.add(cgd);
    /* Create any constraints */
    if (constraintActions != null) {
        /*
			** Do everything but FK constraints first,
			** then FK constraints on 2nd pass.
			*/
        for (int conIndex = 0; conIndex < constraintActions.length; conIndex++) {
            // skip fks
            if (!constraintActions[conIndex].isForeignKeyConstraint()) {
                constraintActions[conIndex].executeConstantAction(activation);
            }
        }
        for (int conIndex = 0; conIndex < constraintActions.length; conIndex++) {
            // only foreign keys
            if (constraintActions[conIndex].isForeignKeyConstraint()) {
                constraintActions[conIndex].executeConstantAction(activation);
            }
        }
    }
    // 
    for (int ix = 0; ix < columnInfo.length; ix++) {
        addColumnDependencies(lcc, dd, td, columnInfo[ix]);
    }
    // 
    // The table itself can depend on the user defined types of its columns.
    // 
    adjustUDTDependencies(lcc, dd, td, columnInfo, false);
    if (tableType == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
        lcc.addDeclaredGlobalTempTable(td);
    }
    // Indicate that the CREATE TABLE statement itself depends on the
    // table it is creating. Normally such statement dependencies are
    // added during compilation, but here we have a bootstrapping issue
    // because the table doesn't exist until the CREATE TABLE statement
    // has been executed, so we had to defer the creation of this
    // dependency until now. (DERBY-4479)
    dd.getDependencyManager().addDependency(activation.getPreparedStatement(), td, lcc.getContextManager());
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) UUID(org.apache.derby.catalog.UUID) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 20 with ConglomerateDescriptor

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

the class AlterTableConstantAction method compressTable.

/**
 * routine to process compress table or ALTER TABLE <t> DROP COLUMN <c>;
 * <p>
 * Uses class level variable "compressTable" to determine if processing
 * compress table or drop column:
 *     if (!compressTable)
 *         must be drop column.
 * <p>
 * Handles rebuilding of base conglomerate and all necessary indexes.
 */
private void compressTable() throws StandardException {
    long newHeapConglom;
    Properties properties = new Properties();
    RowLocation rl;
    if (SanityManager.DEBUG) {
        if (lockGranularity != '\0') {
            SanityManager.THROWASSERT("lockGranularity expected to be '\0', not " + lockGranularity);
        }
        SanityManager.ASSERT(!compressTable || columnInfo == null, "columnInfo expected to be null");
        SanityManager.ASSERT(constraintActions == null, "constraintActions expected to be null");
    }
    ExecRow emptyHeapRow = td.getEmptyExecRow();
    int[] collation_ids = td.getColumnCollationIds();
    compressHeapCC = tc.openConglomerate(td.getHeapConglomerateId(), false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE);
    rl = compressHeapCC.newRowLocationTemplate();
    // Get the properties on the old heap
    compressHeapCC.getInternalTablePropertySet(properties);
    compressHeapCC.close();
    compressHeapCC = null;
    // Create an array to put base row template
    baseRow = new ExecRow[bulkFetchSize];
    baseRowArray = new DataValueDescriptor[bulkFetchSize][];
    validRow = new boolean[bulkFetchSize];
    /* Set up index info */
    getAffectedIndexes();
    // Get an array of RowLocation template
    compressRL = new RowLocation[bulkFetchSize];
    indexRows = new ExecIndexRow[numIndexes];
    if (!compressTable) {
        // must be a drop column, thus the number of columns in the
        // new template row and the collation template is one less.
        ExecRow newRow = activation.getExecutionFactory().getValueRow(emptyHeapRow.nColumns() - 1);
        int[] new_collation_ids = new int[collation_ids.length - 1];
        for (int i = 0; i < newRow.nColumns(); i++) {
            newRow.setColumn(i + 1, i < droppedColumnPosition - 1 ? emptyHeapRow.getColumn(i + 1) : emptyHeapRow.getColumn(i + 1 + 1));
            new_collation_ids[i] = collation_ids[(i < droppedColumnPosition - 1) ? i : (i + 1)];
        }
        emptyHeapRow = newRow;
        collation_ids = new_collation_ids;
    }
    setUpAllSorts(emptyHeapRow, rl);
    // Start by opening a full scan on the base table.
    openBulkFetchScan(td.getHeapConglomerateId());
    // Get the estimated row count for the sorters
    estimatedRowCount = compressHeapGSC.getEstimatedRowCount();
    // Create the array of base row template
    for (int i = 0; i < bulkFetchSize; i++) {
        // create a base row template
        baseRow[i] = td.getEmptyExecRow();
        baseRowArray[i] = baseRow[i].getRowArray();
        compressRL[i] = compressHeapGSC.newRowLocationTemplate();
    }
    newHeapConglom = tc.createAndLoadConglomerate("heap", emptyHeapRow.getRowArray(), // column sort order - not required for heap
    null, collation_ids, properties, TransactionController.IS_DEFAULT, this, (long[]) null);
    closeBulkFetchScan();
    // Set the "estimated" row count
    ScanController compressHeapSC = tc.openScan(newHeapConglom, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, (DataValueDescriptor[]) null, 0, (Qualifier[][]) null, (DataValueDescriptor[]) null, 0);
    compressHeapSC.setEstimatedRowCount(rowCount);
    compressHeapSC.close();
    // RESOLVE DJD CLEANUP
    compressHeapSC = null;
    /*
		** Inform the data dictionary that we are about to write to it.
		** There are several calls to data dictionary "get" methods here
		** that might be done in "read" mode in the data dictionary, but
		** it seemed safer to do this whole operation in "write" mode.
		**
		** We tell the data dictionary we're done writing at the end of
		** the transaction.
		*/
    dd.startWriting(lcc);
    // Update all indexes
    if (compressIRGs.length > 0) {
        updateAllIndexes(newHeapConglom, dd);
    }
    /* Update the DataDictionary
		 * RESOLVE - this will change in 1.4 because we will get
		 * back the same conglomerate number
		 */
    // Get the ConglomerateDescriptor for the heap
    long oldHeapConglom = td.getHeapConglomerateId();
    ConglomerateDescriptor cd = td.getConglomerateDescriptor(oldHeapConglom);
    // Update sys.sysconglomerates with new conglomerate #
    dd.updateConglomerateDescriptor(cd, newHeapConglom, tc);
    // Now that the updated information is available in the system tables,
    // we should invalidate all statements that use the old conglomerates
    dm.invalidateFor(td, DependencyManager.COMPRESS_TABLE, lcc);
    // Drop the old conglomerate
    tc.dropConglomerate(oldHeapConglom);
    cleanUp();
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) GroupFetchScanController(org.apache.derby.iapi.store.access.GroupFetchScanController) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) Properties(java.util.Properties) RowLocation(org.apache.derby.iapi.types.RowLocation) 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