## org.h2.index
Interface Index

All Superinterfaces:
  DbObject, SchemaObject

All Known Implementing Classes:
  BaseIndex, FunctionIndex, HashIndex, LinkedIndex, MetaIndex, MultiVersionIndex, NonUniqueHashIndex, PageBtreeIndex, PageDataIndex, PageDelegateIndex, PageIndex, RangeIndex, ScanIndex, TreeIndex, ViewIndex

    public interface Index

extends SchemaObject

An index. Indexes are used to speed up searching data.

Field Summary

Fields inherited from interface org.h2.engine.DbObject
`AGGREGATE, COMMENT, CONSTANT, CONSTRAINT, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, TABLE_OR_VIEW, TRIGGER, USER, USER_DATATYPE`

Method Summary
`void` `add(Session 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.
`void` `close(Session session)` Close this index.
`void` `commit(int operation, Row row)` Commit the operation for a row.
`int` `compareKeys(SearchRow rowData, SearchRow compare)` Compare the positions of two rows.
`int` `compareRows(SearchRow rowData, SearchRow compare)` Compare two rows.
`boolean` `containsNullAndAllowMultipleNull(SearchRow newRow)` Check if one of the columns is NULL and multiple rows with NULL are allowed using the current compatibility mode for unique indexes.
`Cursor` `find(Session session, SearchRow first, SearchRow last)` Find a row or a list of rows and create a cursor to iterate over the result.
`Cursor` `findFirstOrLast(Session session, boolean first)` Find the lowest or highest value of a column.
`Cursor` `findNext(Session 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
`java.lang.String` `getColumnListSQL()` Get the list of columns as a string.
`Column[]` `getColumns()` Get the indexed columns.
`double` `getCost(Session session, int[] masks)` Estimate the cost to search for rows given the search mask.
`long` `getCostRangeIndex(int[] masks, long rowCount)` Estimate the cost required to search one row, and then iterate over the given number of rows.
`DbException` `getDuplicateKeyException()` Create a duplicate key exception with a message that contains the index name
`IndexColumn[]` `getIndexColumns()` Get the indexed columns as index columns (with ordering information).
`IndexType` `getIndexType()` Get the index type.
`int` `getLookupCost(long rowCount)` Estimate the cost required to search a number of rows.
`java.lang.String` `getPlanSQL()` Get the message to show in a EXPLAIN statement.
`int` `getRootPageId()` Get the root page of this index.
`Row` `getRow(Session session, long key)` Get the row with the given key.
`long` `getRowCount(Session session)` Get the row count of this table, for the given session.
`long` `getRowCountApproximation()` Get the approximated row count for this table.
`Table` `getTable()` Get the table on which this index is based.
`boolean` `needRebuild()` Check if the index needs to be rebuilt.
`void` `remove(Session session)` Remove the index.
`void` `remove(Session session, Row row)` Remove a row from the index.
`void` `truncate(Session session)` Remove all rows from the index.

Methods inherited from interface org.h2.schema.SchemaObject
`getSchema, isHidden`

Methods inherited from interface org.h2.engine.DbObject
`checkRename, getChildren, getComment, getCreateSQL, getCreateSQLForCopy, getDatabase, getDropSQL, getId, getModificationId, getName, getSQL, getType, isTemporary, removeChildrenAndResources, rename, setComment, setModified, setTemporary`

Method Detail

### getDuplicateKeyException

    DbException getDuplicateKeyException()

  Create a duplicate key exception with a message that contains the index name

  Returns:
    the exception

### getPlanSQL

    java.lang.String getPlanSQL()

  Get the message to show in a EXPLAIN statement.

  Returns:
    the plan

### close

    void close(Session session)

  Close this index.

  Parameters:
    `session` - the session used to write data

### add

    void add(Session session,
             Row row)

  Add a row to the index.

  Parameters:
    `session` - the session to use
    `row` - the data

### remove

    void remove(Session session,
                Row row)

  Remove a row from the index.

  Parameters:
    `session` - the session
    `row` - the data

### find

    Cursor find(Session session,
                SearchRow first,
                SearchRow last)

  Find a row or a list of rows and create a cursor to iterate over the result.

  Parameters:
    `session` - the session
    `first` - the first row, or null for no limit
    `last` - the last row, or null for no limit
  Returns:
    the cursor

### getCost

    double getCost(Session session,
                   int[] masks)

  Estimate the cost to search for rows given the search mask. There is one element per column in the search mask. For possible search masks, see IndexCondition.

  Parameters:
    `session` - the session
    `masks` - the search mask
  Returns:
    the estimated cost

### remove

    void remove(Session session)

  Remove the index.

  Parameters:
    `session` - the session

### truncate

    void truncate(Session session)

  Remove all rows from the index.

  Parameters:
    `session` - the session

### canGetFirstOrLast

    boolean canGetFirstOrLast()

  Check if the index can directly look up the lowest or highest value of a column.

  Returns:
    true if it can

### canFindNext

    boolean canFindNext()

  Check if the index can get the next higher value.

  Returns:
    true if it can

### findNext

    Cursor findNext(Session 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.

  Parameters:
    `session` - the session
    `higherThan` - the lower limit (excluding)
    `last` - the last row, or null for no limit
  Returns:
    the cursor

### findFirstOrLast

    Cursor findFirstOrLast(Session session,
                           boolean first)

  Find the lowest or highest value of a column.

  Parameters:
    `session` - the session
    `first` - true if the first (lowest for ascending indexes) or last value should be returned
  Returns:
    a cursor or null

### needRebuild

    boolean needRebuild()

  Check if the index needs to be rebuilt. This method is called after opening an index.

  Returns:
    true if a rebuild is required.

### getRowCount

    long getRowCount(Session session)

  Get the row count of this table, for the given session.

  Parameters:
    `session` - the session
  Returns:
    the row count

### getRowCountApproximation

    long getRowCountApproximation()

  Get the approximated row count for this table.

  Returns:
    the approximated row count

### getLookupCost

    int getLookupCost(long rowCount)

  Estimate the cost required to search a number of rows.

  Parameters:
    `rowCount` - the row count
  Returns:
    the estimated cost

### getCostRangeIndex

    long getCostRangeIndex(int[] masks,
                           long rowCount)

  Estimate the cost required to search one row, and then iterate over the given number of rows.

  Parameters:
    `masks` - the search mask
    `rowCount` - the row count
  Returns:
    the estimated cost

### compareRows

    int compareRows(SearchRow rowData,
                    SearchRow compare)

  Compare two rows.

  Parameters:
    `rowData` - the first row
    `compare` - the second row
  Returns:
    0 if both rows are equal, -1 if the first row is smaller, otherwise 1

### containsNullAndAllowMultipleNull

    boolean containsNullAndAllowMultipleNull(SearchRow newRow)

  Check if one of the columns is NULL and multiple rows with NULL are allowed using the current compatibility mode for unique indexes. Note: NULL behavior is complicated in SQL.

  Parameters:
    `newRow` - the row to check
  Returns:
    true if one of the columns is null and multiple nulls in unique indexes are allowed

### compareKeys

    int compareKeys(SearchRow rowData,
                    SearchRow compare)

  Compare the positions of two rows.

  Parameters:
    `rowData` - the first row
    `compare` - the second row
  Returns:
    0 if both rows are equal, -1 if the first row is smaller, otherwise 1

### getColumnIndex

    int getColumnIndex(Column col)

  Get the index of a column in the list of index columns

  Parameters:
    `col` - the column
  Returns:
    the index (0 meaning first column)

### getColumnListSQL

    java.lang.String getColumnListSQL()

  Get the list of columns as a string.

  Returns:
    the list of columns

### getIndexColumns

    IndexColumn[] getIndexColumns()

  Get the indexed columns as index columns (with ordering information).

  Returns:
    the index columns

### getColumns

    Column[] getColumns()

  Get the indexed columns.

  Returns:
    the columns

### getIndexType

    IndexType getIndexType()

  Get the index type.

  Returns:
    the index type

### getTable

    Table getTable()

  Get the table on which this index is based.

  Returns:
    the table

### commit

    void commit(int operation,
                Row row)

  Commit the operation for a row. This is only important for multi-version indexes.

  Parameters:
    `operation` - the operation type
    `row` - the row

### getRootPageId

    int getRootPageId()

  Get the root page of this index.

  Returns:
    the root page id

### getRow

    Row getRow(Session session,
               long key)

  Get the row with the given key.

  Parameters:
    `session` - the session
    `key` - the unique key
  Returns:
    the row