public abstract class Index extends SchemaObject
| Modifier and Type | Field and Description |
|---|---|
protected int[] |
columnIds
Identities of table columns.
|
protected Column[] |
columns
Table columns used in this index.
|
protected IndexColumn[] |
indexColumns
Columns of this index.
|
protected IndexType |
indexType
The index type.
|
protected Table |
table
The table.
|
protected int |
uniqueColumnColumn
Count of unique columns.
|
AGGREGATE, comment, COMMENT, CONSTANT, CONSTRAINT, database, DOMAIN, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, SYNONYM, TABLE_OR_VIEW, trace, TRIGGER, USERADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS| Modifier | Constructor and Description |
|---|---|
protected |
Index(Table newTable,
int id,
java.lang.String name,
IndexColumn[] newIndexColumns,
int uniqueColumnCount,
IndexType newIndexType)
Initialize the index.
|
| Modifier and Type | Method and Description |
|---|---|
abstract void |
add(SessionLocal session,
Row row)
Add a row to the index.
|
boolean |
canFindNext()
Check if the index can get the next higher value.
|
boolean |
canGetFirstOrLast()
Check if the index can directly look up the lowest or highest value of a
column.
|
boolean |
canScan()
Can this index iterate over all rows?
|
protected static void |
checkIndexColumnTypes(IndexColumn[] columns)
Check that the index columns are not CLOB or BLOB.
|
abstract void |
close(SessionLocal session)
Close this index.
|
int |
compareRows(SearchRow rowData,
SearchRow compare)
Compare two rows.
|
abstract Cursor |
find(SessionLocal session,
SearchRow first,
SearchRow last)
Find a row or a list of rows and create a cursor to iterate over the
result.
|
Cursor |
findFirstOrLast(SessionLocal session,
boolean first)
Find the first (or last) value of this index.
|
Cursor |
findNext(SessionLocal session,
SearchRow higherThan,
SearchRow last)
Find a row or a list of rows that is larger and create a cursor to
iterate over the result.
|
int |
getColumnIndex(Column col)
Get the index of a column in the list of index columns
|
Column[] |
getColumns()
Get the indexed columns.
|
abstract double |
getCost(SessionLocal session,
int[] masks,
TableFilter[] filters,
int filter,
SortOrder sortOrder,
AllColumnsForPlan allColumnsSet)
Estimate the cost to search for rows given the search mask.
|
protected long |
getCostRangeIndex(int[] masks,
long rowCount,
TableFilter[] filters,
int filter,
SortOrder sortOrder,
boolean isScanIndex,
AllColumnsForPlan allColumnsSet)
Calculate the cost for the given mask as if this index was a typical
b-tree range index.
|
java.lang.String |
getCreateSQL()
Construct the CREATE ...
|
java.lang.String |
getCreateSQLForCopy(Table targetTable,
java.lang.String quotedName)
Build a SQL statement to re-create the object, or to create a copy of the
object with a different name or referencing a different table
|
long |
getDiskSpaceUsed()
Get the used disk space for this index.
|
DbException |
getDuplicateKeyException(java.lang.String key)
Create a duplicate key exception with a message that contains the index
name.
|
protected java.lang.StringBuilder |
getDuplicatePrimaryKeyMessage(int mainIndexColumn)
Get "PRIMARY KEY ON <table> [(column)]".
|
IndexColumn[] |
getIndexColumns()
Get the indexed columns as index columns (with ordering information).
|
IndexType |
getIndexType()
Get the index type.
|
java.lang.String |
getPlanSQL()
Get the message to show in a EXPLAIN statement.
|
Row |
getRow(SessionLocal session,
long key)
Get the row with the given key.
|
abstract long |
getRowCount(SessionLocal session)
Get the row count of this table, for the given session.
|
abstract long |
getRowCountApproximation(SessionLocal session)
Get the approximated row count for this table.
|
RowFactory |
getRowFactory() |
Table |
getTable()
Get the table on which this index is based.
|
int |
getType()
Get the object type.
|
int |
getUniqueColumnCount()
Returns count of unique columns.
|
RowFactory |
getUniqueRowFactory() |
boolean |
isFindUsingFullTableScan()
Returns
true if find() implementation performs scan over all
index, false if find() performs the fast lookup. |
boolean |
isFirstColumn(Column column)
Check if the given column is the first for this index
|
boolean |
isHidden()
Check whether this is a hidden object that doesn't appear in the meta
data and in the script, and is not dropped on DROP ALL OBJECTS.
|
boolean |
isRowIdIndex()
Does this index support lookup by row id?
|
abstract boolean |
needRebuild()
Check if the index needs to be rebuilt.
|
boolean |
needsUniqueCheck(SearchRow searchRow)
Check if this row needs to be checked for duplicates.
|
abstract void |
remove(SessionLocal session)
Remove the index.
|
abstract void |
remove(SessionLocal session,
Row row)
Remove a row from the index.
|
void |
removeChildrenAndResources(SessionLocal session)
Delete all dependent children objects and resources of this object.
|
abstract void |
truncate(SessionLocal session)
Remove all rows from the index.
|
void |
update(SessionLocal session,
Row oldRow,
Row newRow)
Update index after row change.
|
getSchema, getSQL, getSQLcheckRename, getChildren, getComment, getCreateSQLForMeta, getDatabase, getDropSQL, getId, getModificationId, getName, invalidate, isTemporary, isValid, rename, setComment, setModified, setObjectName, setTemporary, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetTraceSQLprotected IndexColumn[] indexColumns
protected Column[] columns
protected int[] columnIds
protected final int uniqueColumnColumn
protected final Table table
protected final IndexType indexType
protected Index(Table newTable, int id, java.lang.String name, IndexColumn[] newIndexColumns, int uniqueColumnCount, IndexType newIndexType)
newTable - the tableid - the object idname - the index namenewIndexColumns - the columns that are indexed or null if this is
not yet knownuniqueColumnCount - count of unique columnsnewIndexType - the index typeprotected static void checkIndexColumnTypes(IndexColumn[] columns)
columns - the columnspublic final int getType()
DbObjectpublic void removeChildrenAndResources(SessionLocal session)
DbObjectremoveChildrenAndResources in class DbObjectsession - the sessionpublic final boolean isHidden()
SchemaObjectisHidden in class SchemaObjectpublic java.lang.String getCreateSQLForCopy(Table targetTable, java.lang.String quotedName)
DbObjectgetCreateSQLForCopy in class DbObjecttargetTable - the new tablequotedName - the quoted namepublic java.lang.String getCreateSQL()
DbObjectgetCreateSQL in class DbObjectpublic java.lang.String getPlanSQL()
public abstract void close(SessionLocal session)
session - the session used to write datapublic abstract void add(SessionLocal session, Row row)
session - the session to userow - the row to addpublic abstract void remove(SessionLocal session, Row row)
session - the sessionrow - the rowpublic void update(SessionLocal session, Row oldRow, Row newRow)
session - the sessionoldRow - row before the updatenewRow - row after the updatepublic boolean isFindUsingFullTableScan()
true if find() implementation performs scan over all
index, false if find() performs the fast lookup.true if find() implementation performs scan over all
index, false if find() performs the fast lookuppublic abstract Cursor find(SessionLocal session, SearchRow first, SearchRow last)
session - the sessionfirst - the first row, or null for no limitlast - the last row, or null for no limitpublic abstract double getCost(SessionLocal session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, AllColumnsForPlan allColumnsSet)
session - the sessionmasks - per-column comparison bit masks, null means 'always false',
see constants in IndexConditionfilters - all joined table filtersfilter - the current table filter indexsortOrder - the sort orderallColumnsSet - the set of all columnspublic abstract void remove(SessionLocal session)
session - the sessionpublic abstract void truncate(SessionLocal session)
session - the sessionpublic boolean canGetFirstOrLast()
public boolean canFindNext()
public Cursor findNext(SessionLocal session, SearchRow higherThan, SearchRow last)
session - the sessionhigherThan - the lower limit (excluding)last - the last row, or null for no limitpublic Cursor findFirstOrLast(SessionLocal session, boolean first)
session - the sessionfirst - true if the first (lowest for ascending indexes) or last
value should be returnedpublic abstract boolean needRebuild()
public abstract long getRowCount(SessionLocal session)
session - the sessionpublic abstract long getRowCountApproximation(SessionLocal session)
session - the sessionpublic long getDiskSpaceUsed()
public final int compareRows(SearchRow rowData, SearchRow compare)
rowData - the first rowcompare - the second rowpublic int getColumnIndex(Column col)
col - the columnpublic boolean isFirstColumn(Column column)
column - the columnpublic final IndexColumn[] getIndexColumns()
public final Column[] getColumns()
public final int getUniqueColumnCount()
public final IndexType getIndexType()
public Table getTable()
public Row getRow(SessionLocal session, long key)
session - the sessionkey - the unique keypublic boolean isRowIdIndex()
public boolean canScan()
public DbException getDuplicateKeyException(java.lang.String key)
key - the key valuesprotected java.lang.StringBuilder getDuplicatePrimaryKeyMessage(int mainIndexColumn)
mainIndexColumn - the column indexprotected final long getCostRangeIndex(int[] masks,
long rowCount,
TableFilter[] filters,
int filter,
SortOrder sortOrder,
boolean isScanIndex,
AllColumnsForPlan allColumnsSet)
masks - the IndexCondition search masks, one for each column in the
tablerowCount - the number of rows in the indexfilters - all joined table filtersfilter - the current table filter indexsortOrder - the sort orderisScanIndex - whether this is a "table scan" indexallColumnsSet - the set of all columnspublic final boolean needsUniqueCheck(SearchRow searchRow)
searchRow - the row to checktrue if check for duplicates is required,
false otherwisepublic RowFactory getRowFactory()
public RowFactory getUniqueRowFactory()