ConstantAction
, RowLocationRetRowSource
, RowSource
class AlterTableConstantAction extends DDLSingleTableConstantAction implements RowLocationRetRowSource
Modifier and Type | Field | Description |
---|---|---|
private Activation |
activation |
|
private ExecRow[] |
baseRow |
|
private DataValueDescriptor[][] |
baseRowArray |
|
private int |
behavior |
|
private int |
bulkFetchSize |
|
private int[][] |
collation |
|
private ColumnInfo[] |
columnInfo |
|
private ConglomerateController |
compressHeapCC |
|
private GroupFetchScanController |
compressHeapGSC |
|
private IndexRowGenerator[] |
compressIRGs |
|
private RowLocation[] |
compressRL |
|
private boolean |
compressTable |
|
private ConstraintConstantAction[] |
constraintActions |
|
private int |
currentCompressRow |
|
private ExecRow |
currentRow |
|
private DataDictionary |
dd |
|
private boolean |
defragment |
|
private DependencyManager |
dm |
|
private boolean |
doneScan |
|
private int |
droppedColumnPosition |
|
private boolean |
dropStatistics |
dropStatistics will indicate that we are here for dropping the
statistics.
|
private boolean |
dropStatisticsAll |
The flag dropStatisticsAll will tell if we are going to drop the
statistics of all indexes or just one index on a table.
|
private long |
estimatedRowCount |
|
private long[] |
indexConglomerateNumbers |
|
private FormatableBitSet |
indexedCols |
|
private java.lang.String |
indexNameForStatistics |
If statistic is getting updated/dropped for just one index, then
indexNameForStatistics will tell the name of the specific index
whose statistics need to be updated/dropped.
|
private ExecIndexRow[] |
indexRows |
|
private LanguageConnectionContext |
lcc |
|
private char |
lockGranularity |
|
private boolean[] |
needToDropSort |
|
private int |
numIndexes |
|
private ColumnOrdering[][] |
ordering |
|
private boolean |
purge |
|
private static int |
RANGE_BOTTOM |
|
private static int |
RANGE_TOP |
|
private int |
rowCount |
|
private UUID |
schemaId |
|
private SchemaDescriptor |
sd |
|
private boolean |
sequential |
|
private SortController[] |
sorters |
|
private long[] |
sortIds |
|
private long |
tableConglomerateId |
|
private java.lang.String |
tableName |
|
private int |
tableType |
|
private TransactionController |
tc |
|
private TableDescriptor |
td |
|
private boolean |
truncateEndOfTable |
|
private boolean |
truncateTable |
|
private boolean |
updateStatistics |
updateStatistics will indicate that we are here for updating the
statistics.
|
private boolean |
updateStatisticsAll |
The flag updateStatisticsAll will tell if we are going to update the
statistics of all indexes or just one index on a table.
|
private boolean[] |
validRow |
WHEN_MATCHED_THEN_DELETE, WHEN_MATCHED_THEN_UPDATE, WHEN_NOT_MATCHED_THEN_INSERT
tableId
Constructor | Description |
---|---|
AlterTableConstantAction(SchemaDescriptor sd,
java.lang.String tableName,
UUID tableId,
long tableConglomerateId,
int tableType,
ColumnInfo[] columnInfo,
ConstraintConstantAction[] constraintActions,
char lockGranularity,
boolean compressTable,
int behavior,
boolean sequential,
boolean truncateTable,
boolean purge,
boolean defragment,
boolean truncateEndOfTable,
boolean updateStatistics,
boolean updateStatisticsAll,
boolean dropStatistics,
boolean dropStatisticsAll,
java.lang.String indexNameForStatistics) |
Make the AlterAction for an ALTER TABLE statement.
|
Modifier and Type | Method | Description |
---|---|---|
private void |
addNewColumnToTable(int ix) |
Workhorse for adding a new column to a table.
|
private void |
cleanUp() |
|
private void |
clearState() |
Clear the state of this constant action.
|
private void |
closeBulkFetchScan() |
|
void |
closeRowSource() |
closeRowSource tells the RowSource that it will no longer need to
return any rows and it can release any resource it may have.
|
private boolean |
columnDroppedAndTriggerDependencies(TriggerDescriptor trd,
UUID spsUUID,
boolean isWhenClause,
boolean cascade,
java.lang.String columnName) |
|
private java.lang.Object[] |
compressIndexArrays(long[] indexCIDS,
IndexRowGenerator[] irgs) |
Get rid of duplicates from a set of index conglomerate numbers and
index descriptors.
|
private void |
compressTable() |
routine to process compress table or ALTER TABLE
|
private void |
createNewBackingCongloms(java.util.ArrayList<ConstantAction> newConglomActions,
long[] ixCongNums) |
Iterate through the received list of CreateIndexConstantActions and
execute each one, It's possible that one or more of the constant
actions in the list has been rendered "unneeded" by the time we get
here (because the index that the constant action was going to create
is no longer needed), so we have to check for that.
|
private void |
defragmentRows(TransactionController tc) |
Defragment rows in the given table.
|
private void |
dropColumnFromTable(java.lang.String columnName) |
Workhorse for dropping a column from a table.
|
private void |
dropStatistics() |
Drop statistics of either all the indexes on the table or only one
specific index depending on what user has requested.
|
void |
executeConstantAction(Activation activation) |
Run this constant action.
|
private void |
executeConstantActionBody(Activation activation) |
This is the guts of the Execution-time logic for ALTER TABLE.
|
private static void |
executeUpdate(LanguageConnectionContext lcc,
java.lang.String updateStmt) |
|
private static void |
fixIndex(DataValueDescriptor[] base_row,
DataValueDescriptor[] index_row,
RowLocation old_row_loc,
RowLocation new_row_loc,
ConglomerateController index_cc,
ScanController index_scan,
int[] index_col_map) |
Delete old index row and insert new index row in input index.
|
private void |
getAffectedIndexes() |
Get info on the indexes on the table being compressed.
|
private long |
getColumnMax(TableDescriptor td,
java.lang.String columnName,
long increment) |
computes the minimum/maximum value in a column of a table.
|
DataValueDescriptor[] |
getNextRowFromRowSource() |
Get the next row as an array of column objects.
|
private long |
getRangeBound(DataTypeDescriptor dtd,
int topOrBottom) |
Get the ran max or min range bound for an autoincrement column.
|
private int |
getSemiRowCount(TransactionController tc) |
Return the "semi" row count of a table.
|
FormatableBitSet |
getValidColumns() |
getValidColumns describes the DataValueDescriptor[] returned by all calls
to the getNextRowFromRowSource() call.
|
private void |
insertIntoSorter(int index,
RowLocation rl) |
|
private void |
modifyColumnConstraint(java.lang.String colName,
boolean nullability) |
Workhorse for modifying column level constraints.
|
private void |
modifyColumnDefault(int ix) |
Workhorse for modifying the default value of a column.
|
private void |
modifyColumnType(int ix) |
|
private void |
modifyIdentityState(int ix) |
Change an identity from ALWAYS to BY DEFAULT (or vice versa)
|
boolean |
needsRowLocation() |
needsRowLocation returns true iff this the row source expects the
drainer of the row source to call rowLocation after getting a row from
getNextRowFromRowSource.
|
boolean |
needsRowLocationForDeferredCheckConstraints() |
|
boolean |
needsToClone() |
Does the caller of getNextRowFromRowSource() need to clone the row
in order to keep a reference to the row past the
getNextRowFromRowSource() call which returned the row.
|
private void |
objectifyStreamingColumns() |
|
void |
offendingRowLocation(RowLocation rl,
long containdId) |
|
private void |
openBulkFetchScan(long heapConglomNumber) |
|
private void |
purgeRows(TransactionController tc) |
Purge committed deleted rows from conglomerate.
|
void |
rowLocation(RowLocation rl) |
rowLocation is a callback for the drainer of the row source to return
the rowLocation of the current row, i.e, the row that is being returned
by getNextRowFromRowSource.
|
private static void |
setup_indexes(TransactionController tc,
TableDescriptor td,
int[][] index_col_map,
ScanController[] index_scan,
ConglomerateController[] index_cc,
DataValueDescriptor[][] index_row) |
|
private void |
setUpAllSorts(ExecRow sourceRow,
RowLocation rl) |
Set up to update all of the indexes on a table when doing a bulk insert
on an empty table.
|
java.lang.String |
toString() |
|
private void |
truncateEnd(TransactionController tc) |
Truncate end of conglomerate.
|
private void |
truncateTable() |
|
private void |
updateAllIndexes(long newHeapConglom,
DataDictionary dd) |
Update all of the indexes on a table when doing a bulk insert
on an empty table.
|
private void |
updateIndex(long newHeapConglom,
DataDictionary dd,
int index,
long[] newIndexCongloms) |
|
private void |
updateNewColumnToDefault(ColumnDescriptor columnDescriptor) |
Update a new column with its default.
|
private void |
updateStatistics() |
Update statistics of either all the indexes on the table or only one
specific index depending on what user has requested.
|
private boolean |
validateNotNullConstraint(java.lang.String[] columnNames,
boolean[] nullCols,
int numRows,
LanguageConnectionContext lcc,
java.lang.String errorMsg) |
Make sure that the columns are non null
If any column is nullable, check that the data is null.
|
addColumnDependencies, adjustUDTDependencies, adjustUDTDependencies, constructToString, getAndCheckSchemaDescriptor, getSchemaDescriptorForCreate, lockTableForDDL, storeConstraintDependenciesOnPrivileges, storeViewTriggerDependenciesOnPrivileges
dropConglomerate, dropConglomerate, dropConstraint, dropConstraint, dropConstraint, executeConglomReplacement, getConglomReplacementAction, recreateUniqueConstraintBackingIndexAsUniqueWhenNotNull
private static final int RANGE_TOP
private static final int RANGE_BOTTOM
private SchemaDescriptor sd
private java.lang.String tableName
private UUID schemaId
private int tableType
private ColumnInfo[] columnInfo
private ConstraintConstantAction[] constraintActions
private char lockGranularity
private long tableConglomerateId
private boolean compressTable
private int behavior
private boolean sequential
private boolean truncateTable
private boolean purge
private boolean defragment
private boolean truncateEndOfTable
private boolean updateStatistics
private boolean updateStatisticsAll
private boolean dropStatistics
private boolean dropStatisticsAll
private java.lang.String indexNameForStatistics
private boolean doneScan
private boolean[] needToDropSort
private boolean[] validRow
private int bulkFetchSize
private int currentCompressRow
private int numIndexes
private int rowCount
private long estimatedRowCount
private long[] indexConglomerateNumbers
private long[] sortIds
private FormatableBitSet indexedCols
private ConglomerateController compressHeapCC
private ExecIndexRow[] indexRows
private ExecRow[] baseRow
private ExecRow currentRow
private GroupFetchScanController compressHeapGSC
private IndexRowGenerator[] compressIRGs
private DataValueDescriptor[][] baseRowArray
private RowLocation[] compressRL
private SortController[] sorters
private int droppedColumnPosition
private ColumnOrdering[][] ordering
private int[][] collation
private TableDescriptor td
private LanguageConnectionContext lcc
private DataDictionary dd
private DependencyManager dm
private TransactionController tc
private Activation activation
AlterTableConstantAction(SchemaDescriptor sd, java.lang.String tableName, UUID tableId, long tableConglomerateId, int tableType, ColumnInfo[] columnInfo, ConstraintConstantAction[] constraintActions, char lockGranularity, boolean compressTable, int behavior, boolean sequential, boolean truncateTable, boolean purge, boolean defragment, boolean truncateEndOfTable, boolean updateStatistics, boolean updateStatisticsAll, boolean dropStatistics, boolean dropStatisticsAll, java.lang.String indexNameForStatistics)
sd
- descriptor for the table's schema.tableName
- Name of table.tableId
- UUID of tabletableConglomerateId
- heap conglomerate number of tabletableType
- Type of table (e.g., BASE).columnInfo
- Information on all the columns in the table.constraintActions
- ConstraintConstantAction[] for constraintslockGranularity
- The lock granularity.compressTable
- Whether or not this is a compress tablebehavior
- drop behavior for dropping columnsequential
- If compress table/drop column,
whether or not sequentialtruncateTable
- Whether or not this is a truncate tablepurge
- PURGE during INPLACE COMPRESS?defragment
- DEFRAGMENT during INPLACE COMPRESS?truncateEndOfTable
- TRUNCATE END during INPLACE COMPRESS?updateStatistics
- TRUE means we are here to update statisticsupdateStatisticsAll
- TRUE means we are here to update statistics
of all the indexes. False means we are here to update statistics of
only one index.dropStatistics
- TRUE means we are here to drop statisticsdropStatisticsAll
- TRUE means we are here to drop statistics
of all the indexes. False means we are here to drop statistics of
only one index.indexNameForStatistics
- Will name the index whose statistics
will be updated/dropped. This param is looked at only if
updateStatisticsAll/dropStatisticsAll is set to false and
updateStatistics/dropStatistics is set to true.public java.lang.String toString()
toString
in class java.lang.Object
public void executeConstantAction(Activation activation) throws StandardException
executeConstantAction
in interface ConstantAction
activation
- the activation in which to run the actionStandardException
- if an error happens during execution
of the actionprivate void executeConstantActionBody(Activation activation) throws StandardException
StandardException
- Thrown on failureConstantAction.executeConstantAction(org.apache.derby.iapi.sql.Activation)
private void clearState()
private void dropStatistics() throws StandardException
StandardException
private void updateStatistics() throws StandardException
StandardException
private void truncateEnd(TransactionController tc) throws StandardException
Returns the contiguous free space at the end of the table back to the operating system. Takes care of space allocation bit maps, and OS call to return the actual space.
tc
- transaction controller to use to do updates.StandardException
private void defragmentRows(TransactionController tc) throws StandardException
Scans the rows at the end of a table and moves them to free spots towards the beginning of the table. In the same transaction all associated indexes are updated to reflect the new location of the base table row.
After a defragment pass, if was possible, there will be a set of empty pages at the end of the table which can be returned to the operating system by calling truncateEnd(). The allocation bit maps will be set so that new inserts will tend to go to empty and half filled pages starting from the front of the conglomerate.
tc
- transaction controller to use to do updates.StandardException
private static void setup_indexes(TransactionController tc, TableDescriptor td, int[][] index_col_map, ScanController[] index_scan, ConglomerateController[] index_cc, DataValueDescriptor[][] index_row) throws StandardException
StandardException
private static void fixIndex(DataValueDescriptor[] base_row, DataValueDescriptor[] index_row, RowLocation old_row_loc, RowLocation new_row_loc, ConglomerateController index_cc, ScanController index_scan, int[] index_col_map) throws StandardException
base_row
- all columns of base rowindex_row
- an index row template, filled in by this routineold_row_loc
- old location of base row, used to delete indexnew_row_loc
- new location of base row, used to update indexindex_cc
- index conglomerate to insert new rowindex_scan
- index scan to delete old entryindex_col_map
- description of mapping of index row to base row,StandardException
- Standard exception policy.private void purgeRows(TransactionController tc) throws StandardException
Scans the table and purges any committed deleted rows from the table. If all rows on a page are purged then page is also reclaimed.
tc
- transaction controller to use to do updates.StandardException
private void addNewColumnToTable(int ix) throws StandardException
ix
- the index of the column specfication in the ALTER
statement-- currently we allow only one.StandardException
- thrown on failure.private void dropColumnFromTable(java.lang.String columnName) throws StandardException
columnName
- the name of the column specfication in the ALTER
statement-- currently we allow only one.StandardException
- thrown on failure.private boolean columnDroppedAndTriggerDependencies(TriggerDescriptor trd, UUID spsUUID, boolean isWhenClause, boolean cascade, java.lang.String columnName) throws StandardException
StandardException
private void modifyColumnType(int ix) throws StandardException
StandardException
private void modifyColumnConstraint(java.lang.String colName, boolean nullability) throws StandardException
StandardException
private void modifyColumnDefault(int ix) throws StandardException
ix
- the index of the column specfication in the ALTER
statement-- currently we allow only one.StandardException
private long getRangeBound(DataTypeDescriptor dtd, int topOrBottom) throws StandardException
dtd
- The type of the autoincrement column.topOrBottom
- RANGE_TOP or RANGE_BOTTOMStandardException
private void modifyIdentityState(int ix) throws StandardException
ix
- the index of the column specfication in the ALTER
statement-- currently we allow only one.StandardException
private void compressTable() throws StandardException
Uses class level variable "compressTable" to determine if processing compress table or drop column: if (!compressTable) must be drop column.
Handles rebuilding of base conglomerate and all necessary indexes.
StandardException
private void truncateTable() throws StandardException
StandardException
private void updateAllIndexes(long newHeapConglom, DataDictionary dd) throws StandardException
StandardException
- thrown on errorprivate void updateIndex(long newHeapConglom, DataDictionary dd, int index, long[] newIndexCongloms) throws StandardException
StandardException
private void getAffectedIndexes() throws StandardException
StandardException
- Thrown on errorprivate void createNewBackingCongloms(java.util.ArrayList<ConstantAction> newConglomActions, long[] ixCongNums) throws StandardException
newConglomActions
- Potentially empty list of constant actions
to execute, if still neededixCongNums
- Optional array of conglomerate numbers; if non-null
then any entries in the array which correspond to a dropped physical
conglomerate (as determined from the list of constant actions) will
be updated to have the conglomerate number of the newly-created
physical conglomerate.StandardException
private void setUpAllSorts(ExecRow sourceRow, RowLocation rl) throws StandardException
StandardException
- thrown on errorpublic FormatableBitSet getValidColumns()
RowSource
getValidColumns
in interface RowSource
RowSource.getValidColumns()
public DataValueDescriptor[] getNextRowFromRowSource() throws StandardException
RowSource
A null column can be specified by leaving the object null, or indicated by returning a non-null getValidColumns. On streaming columns, it can be indicated by returning a non-null get FieldStates.
If RowSource.needToClone() is true then the returned row (the DataValueDescriptor[]) is guaranteed not to be modified by drainer of the RowSource (except that the input stream will be read, of course) and drainer will keep no reference to it before making the subsequent nextRow call. So it is safe to return the same DataValueDescriptor[] in subsequent nextRow calls if that is desirable for performance reasons.
If RowSource.needToClone() is false then the returned row (the DataValueDescriptor[]) may be be modified by drainer of the RowSource, and the drainer may keep a reference to it after making the subsequent nextRow call. In this case the client should severe all references to the row after returning it from getNextRowFromRowSource().
getNextRowFromRowSource
in interface RowSource
StandardException
- on errorRowSource.getNextRowFromRowSource()
public boolean needsToClone()
RowSource
needsToClone
in interface RowSource
RowSource.needsToClone()
public void closeRowSource()
RowSource
closeRowSource
in interface RowSource
RowSource.closeRowSource()
public boolean needsRowLocation()
RowLocationRetRowSource
needsRowLocation
in interface RowLocationRetRowSource
RowLocationRetRowSource.needsRowLocation()
public boolean needsRowLocationForDeferredCheckConstraints()
needsRowLocationForDeferredCheckConstraints
in interface RowLocationRetRowSource
public void rowLocation(RowLocation rl) throws StandardException
RowLocationRetRowSource
boolean needsRL = rowSource.needsRowLocation(); DataValueDescriptor[] row; while((row = rowSource.getNextRowFromRowSource()) != null) { RowLocation rl = heapConglomerate.insertRow(row); if (needsRL) rowSource.rowLocation(rl); }
rowLocation
in interface RowLocationRetRowSource
StandardException
- on errorRowLocationRetRowSource.rowLocation(org.apache.derby.iapi.types.RowLocation)
private void objectifyStreamingColumns() throws StandardException
StandardException
private void insertIntoSorter(int index, RowLocation rl) throws StandardException
StandardException
private void cleanUp() throws StandardException
StandardException
- Thrown on errorprivate int getSemiRowCount(TransactionController tc) throws StandardException
StandardException
- Thrown on failureprivate void updateNewColumnToDefault(ColumnDescriptor columnDescriptor) throws StandardException
columnDescriptor
- catalog descriptor for the columnStandardException
- if update to default failsprivate static void executeUpdate(LanguageConnectionContext lcc, java.lang.String updateStmt) throws StandardException
StandardException
private long getColumnMax(TableDescriptor td, java.lang.String columnName, long increment) throws StandardException
StandardException
private void openBulkFetchScan(long heapConglomNumber) throws StandardException
StandardException
private void closeBulkFetchScan() throws StandardException
StandardException
private boolean validateNotNullConstraint(java.lang.String[] columnNames, boolean[] nullCols, int numRows, LanguageConnectionContext lcc, java.lang.String errorMsg) throws StandardException
columnNames
- names of columns to be checkednullCols
- true if corresponding column is nullablenumRows
- number of rows in the tablelcc
- language contexterrorMsg
- error message to use for exceptionStandardException
- on errorprivate java.lang.Object[] compressIndexArrays(long[] indexCIDS, IndexRowGenerator[] irgs)
indexCIDS
- array of index conglomerate numbersirgs
- array of index row generaterspublic void offendingRowLocation(RowLocation rl, long containdId) throws StandardException
offendingRowLocation
in interface RowLocationRetRowSource
StandardException
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.