Class CreateIndexConstantAction
java.lang.Object
org.apache.derby.impl.sql.execute.DDLConstantAction
org.apache.derby.impl.sql.execute.DDLSingleTableConstantAction
org.apache.derby.impl.sql.execute.IndexConstantAction
org.apache.derby.impl.sql.execute.CreateIndexConstantAction
- All Implemented Interfaces:
ConstantAction
ConstantAction to create an index either through
a CREATE INDEX statement or as a backing index to
a constraint.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String[]
private UUID
private long
Conglomerate number for the conglomerate created by this constant action; -1L if this constant action has not been executed.private final int
The constraint type, seeDataDictionary
definition of constants.private long
Conglomerate number of the physical conglomerate that we will "replace" using this constant action.private final boolean
Is this for a CREATE TABLE, i.e. it is for a constraint declared in a CREATE TABLE statement that requires a backing index.private final boolean
The index duplicate checking is deferrable.private ExecRow
private String
private final boolean
Used to determine sorting behavior for existing rows if anyprivate boolean[]
private boolean
private Properties
private boolean
private boolean
The index represents a PRIMARY KEY or a UNIQUE NOT NULL constraint which is deferrable.private boolean
Fields inherited from class org.apache.derby.impl.sql.execute.IndexConstantAction
constraintID, indexName, schemaName, tableName
Fields inherited from class org.apache.derby.impl.sql.execute.DDLSingleTableConstantAction
tableId
Fields inherited from interface org.apache.derby.iapi.sql.execute.ConstantAction
WHEN_MATCHED_THEN_DELETE, WHEN_MATCHED_THEN_UPDATE, WHEN_NOT_MATCHED_THEN_INSERT
-
Constructor Summary
ConstructorsConstructorDescriptionCreateIndexConstantAction
(boolean forCreateTable, boolean unique, boolean uniqueWithDuplicateNulls, boolean hasDeferrableChecking, boolean initiallyDeferred, int constraintType, String indexType, String schemaName, String indexName, String tableName, UUID tableId, String[] columnNames, boolean[] isAscending, boolean isConstraint, UUID conglomerateUUID, Properties properties) Make the ConstantAction to create an index.CreateIndexConstantAction
(ConglomerateDescriptor srcCD, TableDescriptor td, Properties properties) Make a ConstantAction that creates a new physical conglomerate based on index information stored in the received descriptors. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
addStatistics
(DataDictionary dd, IndexRowGenerator irg, long numRows) Determines if a statistics entry is to be added for the index.void
executeConstantAction
(Activation activation) This is the guts of the Execution-time logic for creating an index.(package private) long
Get the conglomerate number for the conglomerate that was created by this constant action.(package private) UUID
Get the UUID for the conglomerate descriptor that was created (or re-used) by this constant action.(package private) ExecRow
(package private) long
If the purpose of this constant action was to "replace" a dropped physical conglomerate, then this method returns the conglomerate number of the dropped conglomerate.private RowLocationRetRowSource
loadSorter
(ExecRow[] baseRows, ExecIndexRow[] indexRows, TransactionController tc, GroupFetchScanController scan, long sortId, RowLocation[] rl) Scan the base conglomerate and insert the keys into a sorter, returning a rowSource on the sorter.toString()
Methods inherited from class org.apache.derby.impl.sql.execute.IndexConstantAction
getIndexName, setConstraintID, setIndexName
Methods inherited from class org.apache.derby.impl.sql.execute.DDLSingleTableConstantAction
dropConglomerate, dropConglomerate, dropConstraint, dropConstraint, dropConstraint, executeConglomReplacement, getConglomReplacementAction, recreateUniqueConstraintBackingIndexAsUniqueWhenNotNull
Methods inherited from class org.apache.derby.impl.sql.execute.DDLConstantAction
addColumnDependencies, adjustUDTDependencies, adjustUDTDependencies, constructToString, getAndCheckSchemaDescriptor, getSchemaDescriptorForCreate, lockTableForDDL, storeConstraintDependenciesOnPrivileges, storeViewTriggerDependenciesOnPrivileges
-
Field Details
-
forCreateTable
private final boolean forCreateTableIs this for a CREATE TABLE, i.e. it is for a constraint declared in a CREATE TABLE statement that requires a backing index. -
unique
private boolean unique -
uniqueWithDuplicateNulls
private boolean uniqueWithDuplicateNulls -
uniqueDeferrable
private boolean uniqueDeferrableThe index represents a PRIMARY KEY or a UNIQUE NOT NULL constraint which is deferrable.true
impliesunique == false
anduniqueWithDuplicateNulls == false
andhasDeferrableChecking == true
. -
hasDeferrableChecking
private final boolean hasDeferrableCheckingThe index duplicate checking is deferrable.true
impliesunique == false
and(uniqueDeferrable || uniqueWithDuplicateNulls)
. -
initiallyDeferred
private final boolean initiallyDeferredUsed to determine sorting behavior for existing rows if any -
constraintType
private final int constraintTypeThe constraint type, seeDataDictionary
definition of constants. -
indexType
-
columnNames
-
isAscending
private boolean[] isAscending -
isConstraint
private boolean isConstraint -
conglomerateUUID
-
properties
-
indexTemplateRow
-
conglomId
private long conglomIdConglomerate number for the conglomerate created by this constant action; -1L if this constant action has not been executed. If this constant action doesn't actually create a new conglomerate--which can happen if it finds an existing conglomerate that satisfies all of the criteria--then this field will hold the conglomerate number of whatever existing conglomerate was found. -
droppedConglomNum
private long droppedConglomNumConglomerate number of the physical conglomerate that we will "replace" using this constant action. That is, if the purpose of this constant action is to create a new physical conglomerate to replace a dropped physical conglomerate, then this field holds the conglomerate number of the dropped physical conglomerate. If -1L then we are not replacing a conglomerate, we're simply creating a new index (and backing physical conglomerate) as normal.
-
-
Constructor Details
-
CreateIndexConstantAction
CreateIndexConstantAction(boolean forCreateTable, boolean unique, boolean uniqueWithDuplicateNulls, boolean hasDeferrableChecking, boolean initiallyDeferred, int constraintType, String indexType, String schemaName, String indexName, String tableName, UUID tableId, String[] columnNames, boolean[] isAscending, boolean isConstraint, UUID conglomerateUUID, Properties properties) Make the ConstantAction to create an index.- Parameters:
forCreateTable
- Being executed within a CREATE TABLE statementunique
- True means it will be a unique indexuniqueWithDuplicateNulls
- True means index check and disallow any duplicate key if key has no column with a null value. If any column in the key has a null value, no checking is done and insert will always succeed.hasDeferrableChecking
- True means this index backs a deferrable constraint. isConstraint will be true.initiallyDeferred
- True means the index represents a deferred constraint. Implies hasDeferrableChecking.indexType
- type of index (BTREE, for example)schemaName
- schema that table (and index) lives in.indexName
- Name of the indextableName
- Name of table the index will be ontableId
- UUID of tablecolumnNames
- Names of the columns in the index, in orderisAscending
- Array of booleans telling asc/desc on each columnisConstraint
- TRUE if index is backing up a constraint, else FALSEconglomerateUUID
- ID of conglomerateproperties
- The optional properties list associated with the index.
-
CreateIndexConstantAction
CreateIndexConstantAction(ConglomerateDescriptor srcCD, TableDescriptor td, Properties properties) Make a ConstantAction that creates a new physical conglomerate based on index information stored in the received descriptors. Assumption is that the received ConglomerateDescriptor is still valid (meaning it has corresponding entries in the system tables and it describes some constraint/index that has _not_ been dropped--though the physical conglomerate underneath has). This constructor is used in cases where the physical conglomerate for an index has been dropped but the index still exists. That can happen if multiple indexes share a physical conglomerate but then the conglomerate is dropped as part of "drop index" processing for one of the indexes. (Note that "indexes" here includes indexes which were created to back constraints.) In that case we have to create a new conglomerate to satisfy the remaining sharing indexes, so that's what we're here for. See ConglomerateDescriptor.drop() for details on when that is necessary.
-
-
Method Details
-
toString
-
executeConstantAction
This is the guts of the Execution-time logic for creating an index.A index is represented as:
- ConglomerateDescriptor.
- Parameters:
activation
- The execution environment for this constant action.- Throws:
StandardException
- Thrown on failure- See Also:
-
addStatistics
private boolean addStatistics(DataDictionary dd, IndexRowGenerator irg, long numRows) throws StandardException Determines if a statistics entry is to be added for the index.As an optimization, it may be better to not write a statistics entry to SYS.SYSSTATISTICS. If it isn't needed by Derby as part of query optimization there is no reason to spend resources keeping the statistics up to date.
- Parameters:
dd
- the data dictionaryirg
- the index row generatornumRows
- the number of rows in the index- Returns:
true
if statistics should be written to SYS.SYSSTATISTICS,false
otherwise.- Throws:
StandardException
- if accessing the data dictionary fails
-
getIndexTemplateRow
ExecRow getIndexTemplateRow() -
getCreatedConglomNumber
long getCreatedConglomNumber()Get the conglomerate number for the conglomerate that was created by this constant action. Will return -1L if the constant action has not yet been executed. This is used for updating conglomerate descriptors which share a conglomerate that has been dropped, in which case those "sharing" descriptors need to point to the newly-created conglomerate (the newly-created conglomerate replaces the dropped one). -
getReplacedConglomNumber
long getReplacedConglomNumber()If the purpose of this constant action was to "replace" a dropped physical conglomerate, then this method returns the conglomerate number of the dropped conglomerate. Otherwise this method will end up returning -1. -
getCreatedUUID
UUID getCreatedUUID()Get the UUID for the conglomerate descriptor that was created (or re-used) by this constant action. -
loadSorter
private RowLocationRetRowSource loadSorter(ExecRow[] baseRows, ExecIndexRow[] indexRows, TransactionController tc, GroupFetchScanController scan, long sortId, RowLocation[] rl) throws StandardException Scan the base conglomerate and insert the keys into a sorter, returning a rowSource on the sorter.- Returns:
- RowSource on the sorted index keys.
- Throws:
StandardException
- thrown on error
-