Search in sources :

Example 1 with StaticCompiledOpenConglomInfo

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

the class InsertNode method makeConstantAction.

/**
 * Compile constants that Execution will use
 *
 * @exception StandardException		Thrown on failure
 */
@Override
public ConstantAction makeConstantAction() throws StandardException {
    /* Different constant actions for base tables and updatable VTIs */
    if (targetTableDescriptor != null) {
        // Base table
        long heapConglomId = targetTableDescriptor.getHeapConglomerateId();
        TransactionController tc = getLanguageConnectionContext().getTransactionCompile();
        int numIndexes = (targetTableDescriptor != null) ? indexConglomerateNumbers.length : 0;
        StaticCompiledOpenConglomInfo[] indexSCOCIs = new StaticCompiledOpenConglomInfo[numIndexes];
        for (int index = 0; index < numIndexes; index++) {
            indexSCOCIs[index] = tc.getStaticCompiledConglomInfo(indexConglomerateNumbers[index]);
        }
        /*
			** If we're doing bulk insert, do table locking regardless of
			** what the optimizer decided.  This is because bulk insert is
			** generally done with a large number of rows into an empty table.
			** We also do table locking if the table's lock granularity is
			** set to table.
			*/
        if (bulkInsert || targetTableDescriptor.getLockGranularity() == TableDescriptor.TABLE_LOCK_GRANULARITY) {
            lockMode = TransactionController.MODE_TABLE;
        }
        return getGenericConstantActionFactory().getInsertConstantAction(targetTableDescriptor, heapConglomId, tc.getStaticCompiledConglomInfo(heapConglomId), indicesToMaintain, indexConglomerateNumbers, indexSCOCIs, indexNames, deferred, false, hasDeferrableCheckConstraints, targetTableDescriptor.getUUID(), lockMode, null, null, targetProperties, getFKInfo(), getTriggerInfo(), resultColumnList.getStreamStorableColIds(targetTableDescriptor.getNumberOfColumns()), getIndexedCols(), (UUID) null, null, null, resultSet.isOneRowResultSet(), autoincRowLocation, inMatchingClause(), identitySequenceUUIDString);
    } else {
        /* Return constant action for VTI
			 * NOTE: ConstantAction responsible for preserving instantiated
			 * VTIs for in-memory queries and for only preserving VTIs
			 * that implement Serializable for SPSs.
			 */
        return getGenericConstantActionFactory().getUpdatableVTIConstantAction(DeferModification.INSERT_STATEMENT, deferred);
    }
}
Also used : StaticCompiledOpenConglomInfo(org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 2 with StaticCompiledOpenConglomInfo

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

the class FromBaseTable method generateDistinctScan.

private void generateDistinctScan(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;
    /*
		** getDistinctScanResultSet
		** (
		**		activation,			
		**		resultSetNumber,			
		**		resultRowAllocator,			
		**		conglomereNumber,			
		**		tableName,
		**		optimizeroverride			
		**		indexName,			
		**		colRefItem,			
		**		lockMode,			
		**		tableLocked,
		**		isolationLevel,
		**		optimizerEstimatedRowCount,
		**		optimizerEstimatedRowCost,
		**		closeCleanupMethod
		**	);
		*/
    /* Get the hash key columns and wrap them in a formattable */
    int[] hashKeyCols;
    hashKeyCols = new int[getResultColumns().size()];
    if (referencedCols == null) {
        for (int index = 0; index < hashKeyCols.length; index++) {
            hashKeyCols[index] = index;
        }
    } else {
        int index = 0;
        for (int colNum = referencedCols.anySetBit(); colNum != -1; colNum = referencedCols.anySetBit(colNum)) {
            hashKeyCols[index++] = colNum;
        }
    }
    FormatableIntHolder[] fihArray = FormatableIntHolder.getFormatableIntHolders(hashKeyCols);
    FormatableArrayHolder hashKeyHolder = new FormatableArrayHolder(fihArray);
    int hashKeyItem = acb.addItem(hashKeyHolder);
    long conglomNumber = cd.getConglomerateNumber();
    StaticCompiledOpenConglomInfo scoci = getLanguageConnectionContext().getTransactionCompile().getStaticCompiledConglomInfo(conglomNumber);
    acb.pushGetResultSetFactoryExpression(mb);
    acb.pushThisAsActivation(mb);
    mb.push(conglomNumber);
    mb.push(acb.addItem(scoci));
    mb.push(acb.addItem(getResultColumns().buildRowTemplate(referencedCols, false)));
    mb.push(getResultSetNumber());
    mb.push(hashKeyItem);
    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(cd.isConstraint());
    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, "getDistinctScanResultSet", ClassName.NoPutResultSet, 16);
}
Also used : FormatableIntHolder(org.apache.derby.iapi.services.io.FormatableIntHolder) FormatableArrayHolder(org.apache.derby.iapi.services.io.FormatableArrayHolder) CostEstimate(org.apache.derby.iapi.sql.compile.CostEstimate) StaticCompiledOpenConglomInfo(org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 3 with StaticCompiledOpenConglomInfo

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

the class DeleteNode method makeConstantAction.

/**
 * Compile constants that Execution will use
 *
 * @exception StandardException		Thrown on failure
 */
@Override
public ConstantAction makeConstantAction() throws StandardException {
    /* Different constant actions for base tables and updatable VTIs */
    if (targetTableDescriptor != null) {
        // Base table
        int lckMode = resultSet.updateTargetLockMode();
        long heapConglomId = targetTableDescriptor.getHeapConglomerateId();
        TransactionController tc = getLanguageConnectionContext().getTransactionCompile();
        StaticCompiledOpenConglomInfo[] indexSCOCIs = new StaticCompiledOpenConglomInfo[indexConglomerateNumbers.length];
        for (int index = 0; index < indexSCOCIs.length; index++) {
            indexSCOCIs[index] = tc.getStaticCompiledConglomInfo(indexConglomerateNumbers[index]);
        }
        /*
			** Do table locking if the table's lock granularity is
			** set to table.
			*/
        if (targetTableDescriptor.getLockGranularity() == TableDescriptor.TABLE_LOCK_GRANULARITY) {
            lckMode = TransactionController.MODE_TABLE;
        }
        ResultDescription resultDescription = null;
        if (isDependentTable) {
            // triggers need the result description ,
            // dependent tables  don't have a source from generation time
            // to get the result description
            resultDescription = makeResultDescription();
        }
        return getGenericConstantActionFactory().getDeleteConstantAction(heapConglomId, targetTableDescriptor.getTableType(), tc.getStaticCompiledConglomInfo(heapConglomId), indicesToMaintain, indexConglomerateNumbers, indexSCOCIs, deferred, false, targetTableDescriptor.getUUID(), lckMode, null, null, null, 0, null, null, resultDescription, getFKInfo(), getTriggerInfo(), (readColsBitSet == null) ? (FormatableBitSet) null : new FormatableBitSet(readColsBitSet), getReadColMap(targetTableDescriptor.getNumberOfColumns(), readColsBitSet), resultColumnList.getStreamStorableColIds(targetTableDescriptor.getNumberOfColumns()), (readColsBitSet == null) ? targetTableDescriptor.getNumberOfColumns() : readColsBitSet.getNumBitsSet(), (UUID) null, resultSet.isOneRowResultSet(), dependentConstantActions, inMatchingClause());
    } else {
        /* Return constant action for VTI
			 * NOTE: ConstantAction responsible for preserving instantiated
			 * VTIs for in-memory queries and for only preserving VTIs
			 * that implement Serializable for SPSs.
			 */
        return getGenericConstantActionFactory().getUpdatableVTIConstantAction(DeferModification.DELETE_STATEMENT, deferred);
    }
}
Also used : ResultDescription(org.apache.derby.iapi.sql.ResultDescription) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) StaticCompiledOpenConglomInfo(org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 4 with StaticCompiledOpenConglomInfo

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

the class UpdateNode method makeConstantAction.

/**
 * Compile constants that Execution will use
 *
 * @exception StandardException		Thrown on failure
 */
@Override
public ConstantAction makeConstantAction() throws StandardException {
    /*
		** Updates are also deferred if they update a column in the index
		** used to scan the table being updated.
		*/
    if (!deferred && !inMatchingClause()) {
        ConglomerateDescriptor updateCD = targetTable.getTrulyTheBestAccessPath().getConglomerateDescriptor();
        if (updateCD != null && updateCD.isIndex()) {
            int[] baseColumns = updateCD.getIndexDescriptor().baseColumnPositions();
            if (resultSet.getResultColumns().updateOverlaps(baseColumns)) {
                deferred = true;
            }
        }
    }
    if (null == targetTableDescriptor) {
        /* Return constant action for VTI
			 * NOTE: ConstantAction responsible for preserving instantiated
			 * VTIs for in-memory queries and for only preserving VTIs
			 * that implement Serializable for SPSs.
			 */
        return getGenericConstantActionFactory().getUpdatableVTIConstantAction(DeferModification.UPDATE_STATEMENT, deferred, changedColumnIds);
    }
    int lckMode = inMatchingClause() ? TransactionController.MODE_RECORD : resultSet.updateTargetLockMode();
    long heapConglomId = targetTableDescriptor.getHeapConglomerateId();
    TransactionController tc = getLanguageConnectionContext().getTransactionCompile();
    StaticCompiledOpenConglomInfo[] indexSCOCIs = new StaticCompiledOpenConglomInfo[indexConglomerateNumbers.length];
    for (int index = 0; index < indexSCOCIs.length; index++) {
        indexSCOCIs[index] = tc.getStaticCompiledConglomInfo(indexConglomerateNumbers[index]);
    }
    /*
		** Do table locking if the table's lock granularity is
		** set to table.
		*/
    if (targetTableDescriptor.getLockGranularity() == TableDescriptor.TABLE_LOCK_GRANULARITY) {
        lckMode = TransactionController.MODE_TABLE;
    }
    return getGenericConstantActionFactory().getUpdateConstantAction(targetTableDescriptor, tc.getStaticCompiledConglomInfo(heapConglomId), indicesToMaintain, indexConglomerateNumbers, indexSCOCIs, indexNames, deferred, targetTableDescriptor.getUUID(), lckMode, false, changedColumnIds, null, null, getFKInfo(), getTriggerInfo(), (readColsBitSet == null) ? (FormatableBitSet) null : new FormatableBitSet(readColsBitSet), getReadColMap(targetTableDescriptor.getNumberOfColumns(), readColsBitSet), resultColumnList.getStreamStorableColIds(targetTableDescriptor.getNumberOfColumns()), (readColsBitSet == null) ? targetTableDescriptor.getNumberOfColumns() : readColsBitSet.getNumBitsSet(), positionedUpdate, resultSet.isOneRowResultSet(), autoincRowLocation, inMatchingClause(), identitySequenceUUIDString);
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) StaticCompiledOpenConglomInfo(org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo) TransactionController(org.apache.derby.iapi.store.access.TransactionController) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 5 with StaticCompiledOpenConglomInfo

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

the class TabInfoImpl method getRowChanger.

/**
 *	Gets a row changer for this catalog.
 *
 *	@param	tc	transaction controller
 *	@param	changedCols	the columns to change (1 based), may be null
 * @param  baseRow used to detemine column types at creation time
 *         only. The row changer does ***Not*** keep a referance to
 *         this row or change it in any way.
 *
 *	@return	a row changer for this catalog.
 * @exception StandardException		Thrown on failure
 */
private RowChanger getRowChanger(TransactionController tc, int[] changedCols, ExecRow baseRow) throws StandardException {
    RowChanger rc;
    int indexCount = crf.getNumIndexes();
    IndexRowGenerator[] irgs = new IndexRowGenerator[indexCount];
    long[] cids = new long[indexCount];
    if (SanityManager.DEBUG) {
        if (changedCols != null) {
            for (int i = changedCols.length - 1; i >= 0; i--) {
                SanityManager.ASSERT(changedCols[i] != 0, "Column id is 0, but should be 1 based");
            }
        }
    }
    for (int ictr = 0; ictr < indexCount; ictr++) {
        irgs[ictr] = getIndexRowGenerator(ictr);
        cids[ictr] = getIndexConglomerate(ictr);
    }
    rc = crf.getExecutionFactory().getRowChanger(getHeapConglomerate(), (StaticCompiledOpenConglomInfo) null, (DynamicCompiledOpenConglomInfo) null, irgs, cids, (StaticCompiledOpenConglomInfo[]) null, (DynamicCompiledOpenConglomInfo[]) null, crf.getHeapColumnCount(), tc, changedCols, getStreamStorableHeapColIds(baseRow), (Activation) null);
    return rc;
}
Also used : IndexRowGenerator(org.apache.derby.iapi.sql.dictionary.IndexRowGenerator) RowChanger(org.apache.derby.iapi.sql.execute.RowChanger) DynamicCompiledOpenConglomInfo(org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo) Activation(org.apache.derby.iapi.sql.Activation) StaticCompiledOpenConglomInfo(org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo)

Aggregations

StaticCompiledOpenConglomInfo (org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo)7 TransactionController (org.apache.derby.iapi.store.access.TransactionController)3 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)2 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)2 ReferencedColumnsDescriptorImpl (org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl)1 MethodBuilder (org.apache.derby.iapi.services.compiler.MethodBuilder)1 FormatableArrayHolder (org.apache.derby.iapi.services.io.FormatableArrayHolder)1 FormatableIntHolder (org.apache.derby.iapi.services.io.FormatableIntHolder)1 Activation (org.apache.derby.iapi.sql.Activation)1 ResultDescription (org.apache.derby.iapi.sql.ResultDescription)1 CostEstimate (org.apache.derby.iapi.sql.compile.CostEstimate)1 IndexRowGenerator (org.apache.derby.iapi.sql.dictionary.IndexRowGenerator)1 RowChanger (org.apache.derby.iapi.sql.execute.RowChanger)1 DynamicCompiledOpenConglomInfo (org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo)1