Top Description Fields Constructors Methods
org.apache.derby.impl.sql.execute

pack-priv Class CreateIndexConstantAction

extends IndexConstantAction
Class Inheritance
Imports
java.util.Properties, org.apache.derby.catalog.UUID, org.apache.derby.catalog.types.StatisticsImpl, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.services.loader.ClassFactory, org.apache.derby.iapi.sql.Activation, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.iapi.sql.depend.DependencyManager, org.apache.derby.iapi.sql.dictionary.ColumnDescriptor, .ColumnDescriptorList, .ConglomerateDescriptor, .ConglomerateDescriptorList, .ConstraintDescriptor, .DataDescriptorGenerator, .DataDictionary, .IndexRowGenerator, .SchemaDescriptor, .StatisticsDescriptor, .TableDescriptor, org.apache.derby.iapi.sql.execute.ConstantAction, .ExecIndexRow, .ExecRow, org.apache.derby.iapi.store.access.AccessFactoryGlobals, .ColumnOrdering, .ConglomerateController, .GroupFetchScanController, .RowLocationRetRowSource, .SortController, .SortObserver, .TransactionController, org.apache.derby.iapi.types.DataTypeDescriptor, .DataValueDescriptor, .RowLocation, .TypeId, org.apache.derby.impl.services.daemon.IndexStatisticsDaemonImpl, org.apache.derby.shared.common.sanity.SanityManager

ConstantAction to create an index either through a CREATE INDEX statement or as a backing index to a constraint.

Field Summary

Modifier and TypeField and Description
private String[]
private UUID
private long
conglomId

Conglomerate number for the conglomerate created by this constant action; -1L if this constant action has not been executed.

private final int
constraintType

The constraint type, see org.apache.derby.iapi.sql.dictionary.DataDictionary definition of constants.

private long
droppedConglomNum

Conglomerate number of the physical conglomerate that we will "replace" using this constant action.

private final boolean
forCreateTable

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
hasDeferrableChecking

The index duplicate checking is deferrable.

private ExecRow
private String
private final boolean
initiallyDeferred

Used to determine sorting behavior for existing rows if any

private boolean[]
private boolean
private Properties
private boolean
private boolean
uniqueDeferrable

The index represents a PRIMARY KEY or a UNIQUE NOT NULL constraint which is deferrable.

private boolean
Inherited from org.apache.derby.impl.sql.execute.IndexConstantAction:
constraintIDindexNameschemaNametableName

Constructor Summary

AccessConstructor and Description
pack-priv
CreateIndexConstantAction(boolean
Being executed within a CREATE TABLE statement
forCreateTable
,
boolean
True means it will be a unique index
unique
,
boolean
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.
uniqueWithDuplicateNulls
,
boolean
True means this index backs a deferrable constraint. isConstraint will be true.
hasDeferrableChecking
,
boolean
True means the index represents a deferred constraint. Implies hasDeferrableChecking.
initiallyDeferred
,
int constraintType, String
type of index (BTREE, for example)
indexType
,
String
schema that table (and index) lives in.
schemaName
,
String
Name of the index
indexName
,
String
Name of table the index will be on
tableName
,
UUID
UUID of table
tableId
,
String[]
Names of the columns in the index, in order
columnNames
,
boolean[]
Array of booleans telling asc/desc on each column
isAscending
,
boolean
TRUE if index is backing up a constraint, else FALSE
isConstraint
,
UUID
ID of conglomerate
conglomerateUUID
,
Properties
The optional properties list associated with the index.
properties
)

Make the ConstantAction to create an index.

pack-priv
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 TypeMethod and Description
private boolean

Returns:

true if statistics should be written to SYS.SYSSTATISTICS, false otherwise.
addStatistics
(DataDictionary
the data dictionary
dd
,
IndexRowGenerator
the index row generator
irg
,
long
the number of rows in the index
numRows
)

Determines if a statistics entry is to be added for the index.

public void
executeConstantAction(Activation
The execution environment for this constant action.
activation
)

Implements org.apache.derby.iapi.sql.execute.ConstantAction.executeConstantAction.

This is the guts of the Execution-time logic for creating an index.

pack-priv long
getCreatedConglomNumber()

Get the conglomerate number for the conglomerate that was created by this constant action.

pack-priv UUID
getCreatedUUID()

Get the UUID for the conglomerate descriptor that was created (or re-used) by this constant action.

pack-priv ExecRow
pack-priv 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.

private RowLocationRetRowSource

Returns:

RowSource on the sorted index keys.
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.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.apache.derby.impl.sql.execute.IndexConstantAction:
getIndexNamesetConstraintIDsetIndexName

Field Detail

columnNamesback to summary
private String[] columnNames
conglomerateUUIDback to summary
private UUID conglomerateUUID
conglomIdback to summary
private long conglomId

Conglomerate 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.

constraintTypeback to summary
private final int constraintType

The constraint type, see org.apache.derby.iapi.sql.dictionary.DataDictionary definition of constants.

droppedConglomNumback to summary
private long droppedConglomNum

Conglomerate 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.

forCreateTableback to summary
private final boolean forCreateTable

Is this for a CREATE TABLE, i.e. it is for a constraint declared in a CREATE TABLE statement that requires a backing index.

hasDeferrableCheckingback to summary
private final boolean hasDeferrableChecking

The index duplicate checking is deferrable. true implies unique == false and (uniqueDeferrable || uniqueWithDuplicateNulls).

indexTemplateRowback to summary
private ExecRow indexTemplateRow
indexTypeback to summary
private String indexType
initiallyDeferredback to summary
private final boolean initiallyDeferred

Used to determine sorting behavior for existing rows if any

isAscendingback to summary
private boolean[] isAscending
isConstraintback to summary
private boolean isConstraint
propertiesback to summary
private Properties properties
uniqueback to summary
private boolean unique
uniqueDeferrableback to summary
private boolean uniqueDeferrable

The index represents a PRIMARY KEY or a UNIQUE NOT NULL constraint which is deferrable. true implies unique == false and uniqueWithDuplicateNulls == false and hasDeferrableChecking == true.

uniqueWithDuplicateNullsback to summary
private boolean uniqueWithDuplicateNulls

Constructor Detail

CreateIndexConstantActionback to summary
pack-priv 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:boolean

Being executed within a CREATE TABLE statement

unique:boolean

True means it will be a unique index

uniqueWithDuplicateNulls:boolean

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:boolean

True means this index backs a deferrable constraint. isConstraint will be true.

initiallyDeferred:boolean

True means the index represents a deferred constraint. Implies hasDeferrableChecking.

indexType:String

type of index (BTREE, for example)

schemaName:String

schema that table (and index) lives in.

indexName:String

Name of the index

tableName:String

Name of table the index will be on

tableId:UUID

UUID of table

columnNames:String[]

Names of the columns in the index, in order

isAscending:boolean[]

Array of booleans telling asc/desc on each column

isConstraint:boolean

TRUE if index is backing up a constraint, else FALSE

conglomerateUUID:UUID

ID of conglomerate

properties:Properties

The optional properties list associated with the index.

CreateIndexConstantActionback to summary
pack-priv 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 Detail

addStatisticsback to summary
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:DataDictionary

the data dictionary

irg:IndexRowGenerator

the index row generator

numRows:long

the number of rows in the index

Returns:boolean

true if statistics should be written to SYS.SYSSTATISTICS, false otherwise.

Exceptions
StandardException:
if accessing the data dictionary fails
executeConstantActionback to summary
public void executeConstantAction(Activation activation) throws StandardException

Implements org.apache.derby.iapi.sql.execute.ConstantAction.executeConstantAction.

This is the guts of the Execution-time logic for creating an index.

A index is represented as:

  • ConglomerateDescriptor.
No dependencies are created.
Parameters
activation:Activation

Doc from org.apache.derby.iapi.sql.execute.ConstantAction.executeConstantAction.

The execution environment for this constant action.

Exceptions
StandardException:
Thrown on failure
See Also
ConglomerateDescriptor, SchemaDescriptor, ConstantAction#executeConstantAction
getCreatedConglomNumberback to summary
pack-priv 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).

getCreatedUUIDback to summary
pack-priv UUID getCreatedUUID()

Get the UUID for the conglomerate descriptor that was created (or re-used) by this constant action.

getIndexTemplateRowback to summary
pack-priv ExecRow getIndexTemplateRow()
getReplacedConglomNumberback to summary
pack-priv 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.

loadSorterback to summary
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:RowLocationRetRowSource

RowSource on the sorted index keys.

Exceptions
StandardException:
thrown on error
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override