Search in sources :

Example 41 with ExecRow

use of org.apache.derby.iapi.sql.execute.ExecRow 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)

Example 42 with ExecRow

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

the class AnyResultSet method getNextRowCore.

/**
 * Return the requested value computed from the next row.
 *
 * @exception StandardException thrown on failure.
 */
public ExecRow getNextRowCore() throws StandardException {
    if (isXplainOnlyMode())
        return null;
    ExecRow candidateRow = null;
    ExecRow secondRow = null;
    ExecRow result = null;
    beginTime = getCurrentTimeMillis();
    // outermost in the tree and so a next call when closed will not occur.
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(isOpen, "AnyResultSet not open");
    }
    if (isOpen) {
        candidateRow = source.getNextRowCore();
        if (candidateRow != null) {
            result = candidateRow;
        } else if (rowWithNulls == null) {
            rowWithNulls = (ExecRow) emptyRowFun.invoke(activation);
            result = rowWithNulls;
        } else {
            result = rowWithNulls;
        }
    }
    setCurrentRow(result);
    rowsSeen++;
    nextTime += getElapsedMillis(beginTime);
    return result;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 43 with ExecRow

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

the class BasicNoPutResultSetImpl method setCompactRow.

/**
 * Copy columns from the candidate row from the store to the given
 * compact row. If there is no column map, just use the candidate row.
 *
 * This method assumes the above method (getCompactRow()) was called
 * first. getCompactRow() sets up the baseColumnMap.
 *
 * @param candidateRow	The candidate row from the store
 * @param compactRow	The compact row to fill in
 *
 * @return	The compact row to use
 */
protected ExecRow setCompactRow(ExecRow candidateRow, ExecRow compactRow) {
    ExecRow retval;
    // System.out.println("base col map " + baseColumnMap);
    if (baseColumnMap == null) {
        retval = candidateRow;
    } else {
        retval = compactRow;
        setCompatRow(compactRow, candidateRow.getRowArray());
    }
    return retval;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 44 with ExecRow

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

the class BulkTableScanResultSet method getNextRowCore.

/**
 * Return the next row (if any) from the scan (if open).
 * Reload the rowArray as necessary.
 *
 * @exception StandardException thrown on failure to get next row
 */
public ExecRow getNextRowCore() throws StandardException {
    if (isXplainOnlyMode())
        return null;
    ExecRow result = null;
    checkCancellationFlag();
    beginTime = getCurrentTimeMillis();
    if (isOpen && scanControllerOpened) {
        if (currentRow == null) {
            currentRow = getCompactRow(candidate, accessedCols, isKeyed);
        }
        outer: for (; ; ) {
            if (curRowPosition >= numRowsInArray - 1) {
                if (reloadArray() == OUT_OF_ROWS) {
                    clearCurrentRow();
                    setRowCountIfPossible(rowsThisScan);
                    return null;
                }
            }
            while (++curRowPosition < numRowsInArray) {
                candidate.setRowArray(rowArray[curRowPosition]);
                currentRow = setCompactRow(candidate, currentRow);
                rowsSeen++;
                rowsThisScan++;
                /*
					** Skip rows where there are start or stop positioners
					** that do not implement ordered null semantics and
					** there are columns in those positions that contain
					** null.
					*/
                if (skipRow(candidate)) {
                    rowsFiltered++;
                    continue;
                }
                result = currentRow;
                if (fetchRowLocations) {
                    result = new ValueRow(resultColumnCount);
                    int idx = 1;
                    for (; idx < resultColumnCount; idx++) {
                        result.setColumn(idx, currentRow.getColumn(idx));
                    }
                    result.setColumn(idx, rowLocations[curRowPosition]);
                }
                break outer;
            }
        }
    }
    setCurrentRow(result);
    nextTime += getElapsedMillis(beginTime);
    return result;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 45 with ExecRow

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

the class ProjectRestrictResultSet method getCurrentRow.

/**
 * Gets last row returned.
 *
 * @see CursorResultSet
 *
 * @return the last row returned.
 * @exception StandardException thrown on failure.
 */
/* RESOLVE - this should return activation.getCurrentRow(resultSetNumber),
	 * once there is such a method.  (currentRow is redundant)
	 */
public ExecRow getCurrentRow() throws StandardException {
    ExecRow candidateRow = null;
    ExecRow result = null;
    boolean restrict = false;
    DataValueDescriptor restrictBoolean;
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(isOpen, "PRRS is expected to be open");
    /* Nothing to do if we're not currently on a row */
    if (currentRow == null) {
        return null;
    }
    /* Call the child result set to get it's current row.
		 * If no row exists, then return null, else requalify it
		 * before returning.
		 */
    candidateRow = ((CursorResultSet) source).getCurrentRow();
    if (candidateRow != null) {
        setCurrentRow(candidateRow);
        /* If restriction is null, then all rows qualify */
        restrictBoolean = (DataValueDescriptor) ((restriction == null) ? null : restriction.invoke(activation));
        // if the result is null, we make it false --
        // so the row won't be returned.
        restrict = (restrictBoolean == null) || ((!restrictBoolean.isNull()) && restrictBoolean.getBoolean());
    }
    if (candidateRow != null && restrict) {
        result = doProjection(candidateRow);
    }
    currentRow = result;
    /* Clear the current row, if null */
    if (result == null) {
        clearCurrentRow();
    }
    return currentRow;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Aggregations

ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)155 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)62 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)34 RowLocation (org.apache.derby.iapi.types.RowLocation)27 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)23 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)22 ScanController (org.apache.derby.iapi.store.access.ScanController)22 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)22 SQLChar (org.apache.derby.iapi.types.SQLChar)21 SQLLongint (org.apache.derby.iapi.types.SQLLongint)21 UUID (org.apache.derby.catalog.UUID)19 Properties (java.util.Properties)12 TransactionController (org.apache.derby.iapi.store.access.TransactionController)12 CursorResultSet (org.apache.derby.iapi.sql.execute.CursorResultSet)11 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)10 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)10 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)10 UserType (org.apache.derby.iapi.types.UserType)9 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)8 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)7