## org.h2.index
Class MultiVersionIndex

    java.lang.Object
      org.h2.index.MultiVersionIndex

All Implemented Interfaces:
  DbObject, Index, SchemaObject

    public class MultiVersionIndex

extends java.lang.Object
implements Index

A multi-version index is a combination of a regular index, and a in-memory tree index that contains uncommitted changes. Uncommitted changes can include new rows, and deleted rows.

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`

Constructor Summary
`MultiVersionIndex(Index base, RegularTable table)`

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.
`boolean` `canScan()` Can this index iterate over all rows?
`void` `checkRename()` Check if renaming is allowed.
`void` `close(Session session)` Close this index.
`void` `commit(int operation, Row row)` Commit the operation for a row.
`int` `compareRows(SearchRow rowData, SearchRow compare)` Compare two rows.
`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` `find(TableFilter filter, 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 first (or last) value of this index.
`Cursor` `findNext(Session session, SearchRow first, SearchRow last)` Find a row or a list of rows that is larger and create a cursor to iterate over the result.
`Index` `getBaseIndex()`
`java.util.ArrayList<DbObject>` `getChildren()` Get the list of dependent children (for tables, this includes indexes and so on).
`int` `getColumnIndex(Column col)` Get the index of a column in the list of index columns
`Column[]` `getColumns()` Get the indexed columns.
`java.lang.String` `getComment()` Get the current comment of this object.
`double` `getCost(Session session, int[] masks, TableFilter filter, SortOrder sortOrder)` Estimate the cost to search for rows given the search mask.
`java.lang.String` `getCreateSQL()` Construct the original CREATE ...
`java.lang.String` `getCreateSQLForCopy(Table forTable, 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
`Database` `getDatabase()` Get the database.
`long` `getDiskSpaceUsed()` Get the used disk space for this index.
`java.lang.String` `getDropSQL()` Construct a DROP ...
`int` `getId()` Get the unique object id.
`IndexColumn[]` `getIndexColumns()` Get the indexed columns as index columns (with ordering information).
`IndexType` `getIndexType()` Get the index type.
`java.lang.String` `getName()` Get the name.
`java.lang.String` `getPlanSQL()` Get the message to show in a EXPLAIN statement.
`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.
`Schema` `getSchema()` Get the schema in which this object is defined
`java.lang.String` `getSQL()` Get the SQL name of this object (may be quoted).
`Table` `getTable()` Get the table on which this index is based.
`int` `getType()` Get the object type.
`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?
`boolean` `isTemporary()` Check if this object is temporary (for example, a temporary table).
`boolean` `isUncommittedFromOtherSession(Session session, Row row)` Check if there is an uncommitted row with the given key within a different session.
`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` `removeChildrenAndResources(Session session)` Delete all dependent children objects and resources of this object.
`void` `rename(java.lang.String newName)` Rename the object.
`void` `setComment(java.lang.String comment)` Change the comment of this object.
`void` `setSortedInsertMode(boolean sortedInsertMode)` Enable or disable the 'sorted insert' optimizations (rows are inserted in ascending or descending order) if applicable for this index implementation.
`void` `setTemporary(boolean temporary)` Tell this object that it is temporary or not.
`void` `truncate(Session session)` Remove all rows from the index.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MultiVersionIndex

    public MultiVersionIndex(Index base,
                             RegularTable table)

Method Detail

### add

    public void add(Session session,
                    Row row)

  Description copied from interface: `Index`
  Add a row to the index.

  Specified by:
    `add` in interface `Index`
  Parameters:
    `session` - the session to use
    `row` - the row to add

### close

    public void close(Session session)

  Description copied from interface: `Index`
  Close this index.

  Specified by:
    `close` in interface `Index`
  Parameters:
    `session` - the session used to write data

### find

    public Cursor find(TableFilter filter,
                       SearchRow first,
                       SearchRow last)

  Description copied from interface: `Index`
  Find a row or a list of rows and create a cursor to iterate over the result.

  Specified by:
    `find` in interface `Index`
  Parameters:
    `filter` - the table filter (which possibly knows about additional conditions)
    `first` - the first row, or null for no limit
    `last` - the last row, or null for no limit
  Returns:
    the cursor to iterate over the results

### find

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

  Description copied from interface: `Index`
  Find a row or a list of rows and create a cursor to iterate over the result.

  Specified by:
    `find` in interface `Index`
  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 to iterate over the results

### findNext

    public Cursor findNext(Session session,
                           SearchRow first,
                           SearchRow last)

  Description copied from interface: `Index`
  Find a row or a list of rows that is larger and create a cursor to iterate over the result.

  Specified by:
    `findNext` in interface `Index`
  Parameters:
    `session` - the session
    `first` - the lower limit (excluding)
    `last` - the last row, or null for no limit
  Returns:
    the cursor

### canFindNext

    public boolean canFindNext()

  Description copied from interface: `Index`
  Check if the index can get the next higher value.

  Specified by:
    `canFindNext` in interface `Index`
  Returns:
    true if it can

### canGetFirstOrLast

    public boolean canGetFirstOrLast()

  Description copied from interface: `Index`
  Check if the index can directly look up the lowest or highest value of a column.

  Specified by:
    `canGetFirstOrLast` in interface `Index`
  Returns:
    true if it can

### findFirstOrLast

    public Cursor findFirstOrLast(Session session,
                                  boolean first)

  Description copied from interface: `Index`
  Find the first (or last) value of this index. The cursor returned is positioned on the correct row, or on null if no row has been found.

  Specified by:
    `findFirstOrLast` in interface `Index`
  Parameters:
    `session` - the session
    `first` - true if the first (lowest for ascending indexes) or last value should be returned
  Returns:
    a cursor (never null)

### getCost

    public double getCost(Session session,
                          int[] masks,
                          TableFilter filter,
                          SortOrder sortOrder)

  Description copied from interface: `Index`
  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.

  Specified by:
    `getCost` in interface `Index`
  Parameters:
    `session` - the session
    `masks` - per-column comparison bit masks, null means 'always false', see constants in IndexCondition
    `filter` - the table filter
    `sortOrder` - the sort order
  Returns:
    the estimated cost

### needRebuild

    public boolean needRebuild()

  Description copied from interface: `Index`
  Check if the index needs to be rebuilt. This method is called after opening an index.

  Specified by:
    `needRebuild` in interface `Index`
  Returns:
    true if a rebuild is required.

### isUncommittedFromOtherSession

    public boolean isUncommittedFromOtherSession(Session session,
                                                 Row row)

  Check if there is an uncommitted row with the given key within a different session.

  Parameters:
    `session` - the original session
    `row` - the row (only the key is checked)
  Returns:
    true if there is an uncommitted row

### remove

    public void remove(Session session,
                       Row row)

  Description copied from interface: `Index`
  Remove a row from the index.

  Specified by:
    `remove` in interface `Index`
  Parameters:
    `session` - the session
    `row` - the row

### remove

    public void remove(Session session)

  Description copied from interface: `Index`
  Remove the index.

  Specified by:
    `remove` in interface `Index`
  Parameters:
    `session` - the session

### truncate

    public void truncate(Session session)

  Description copied from interface: `Index`
  Remove all rows from the index.

  Specified by:
    `truncate` in interface `Index`
  Parameters:
    `session` - the session

### commit

    public void commit(int operation,
                       Row row)

  Description copied from interface: `Index`
  Commit the operation for a row. This is only important for multi-version indexes. The method is only called if multi-version is enabled.

  Specified by:
    `commit` in interface `Index`
  Parameters:
    `operation` - the operation type
    `row` - the row

### compareRows

    public int compareRows(SearchRow rowData,
                           SearchRow compare)

  Description copied from interface: `Index`
  Compare two rows.

  Specified by:
    `compareRows` in interface `Index`
  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

    public int getColumnIndex(Column col)

  Description copied from interface: `Index`
  Get the index of a column in the list of index columns

  Specified by:
    `getColumnIndex` in interface `Index`
  Parameters:
    `col` - the column
  Returns:
    the index (0 meaning first column)

### getColumns

    public Column[] getColumns()

  Description copied from interface: `Index`
  Get the indexed columns.

  Specified by:
    `getColumns` in interface `Index`
  Returns:
    the columns

### getIndexColumns

    public IndexColumn[] getIndexColumns()

  Description copied from interface: `Index`
  Get the indexed columns as index columns (with ordering information).

  Specified by:
    `getIndexColumns` in interface `Index`
  Returns:
    the index columns

### getCreateSQL

    public java.lang.String getCreateSQL()

  Description copied from interface: `DbObject`
  Construct the original CREATE ... SQL statement for this object.

  Specified by:
    `getCreateSQL` in interface `DbObject`
  Returns:
    the SQL statement

### getCreateSQLForCopy

    public java.lang.String getCreateSQLForCopy(Table forTable,
                                                java.lang.String quotedName)

  Description copied from interface: `DbObject`
  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

  Specified by:
    `getCreateSQLForCopy` in interface `DbObject`
  Parameters:
    `forTable` - the new table
    `quotedName` - the quoted name
  Returns:
    the SQL statement

### getDropSQL

    public java.lang.String getDropSQL()

  Description copied from interface: `DbObject`
  Construct a DROP ... SQL statement for this object.

  Specified by:
    `getDropSQL` in interface `DbObject`
  Returns:
    the SQL statement

### getIndexType

    public IndexType getIndexType()

  Description copied from interface: `Index`
  Get the index type.

  Specified by:
    `getIndexType` in interface `Index`
  Returns:
    the index type

### getPlanSQL

    public java.lang.String getPlanSQL()

  Description copied from interface: `Index`
  Get the message to show in a EXPLAIN statement.

  Specified by:
    `getPlanSQL` in interface `Index`
  Returns:
    the plan

### getRowCount

    public long getRowCount(Session session)

  Description copied from interface: `Index`
  Get the row count of this table, for the given session.

  Specified by:
    `getRowCount` in interface `Index`
  Parameters:
    `session` - the session
  Returns:
    the row count

### getTable

    public Table getTable()

  Description copied from interface: `Index`
  Get the table on which this index is based.

  Specified by:
    `getTable` in interface `Index`
  Returns:
    the table

### getType

    public int getType()

  Description copied from interface: `DbObject`
  Get the object type.

  Specified by:
    `getType` in interface `DbObject`
  Returns:
    the object type

### removeChildrenAndResources

    public void removeChildrenAndResources(Session session)

  Description copied from interface: `DbObject`
  Delete all dependent children objects and resources of this object.

  Specified by:
    `removeChildrenAndResources` in interface `DbObject`
  Parameters:
    `session` - the session

### getSQL

    public java.lang.String getSQL()

  Description copied from interface: `DbObject`
  Get the SQL name of this object (may be quoted).

  Specified by:
    `getSQL` in interface `DbObject`
  Returns:
    the SQL name

### getSchema

    public Schema getSchema()

  Description copied from interface: `SchemaObject`
  Get the schema in which this object is defined

  Specified by:
    `getSchema` in interface `SchemaObject`
  Returns:
    the schema

### checkRename

    public void checkRename()

  Description copied from interface: `DbObject`
  Check if renaming is allowed. Does nothing when allowed.

  Specified by:
    `checkRename` in interface `DbObject`

### getChildren

    public java.util.ArrayList<DbObject> getChildren()

  Description copied from interface: `DbObject`
  Get the list of dependent children (for tables, this includes indexes and so on).

  Specified by:
    `getChildren` in interface `DbObject`
  Returns:
    the list of children

### getComment

    public java.lang.String getComment()

  Description copied from interface: `DbObject`
  Get the current comment of this object.

  Specified by:
    `getComment` in interface `DbObject`
  Returns:
    the comment, or null if not set

### getDatabase

    public Database getDatabase()

  Description copied from interface: `DbObject`
  Get the database.

  Specified by:
    `getDatabase` in interface `DbObject`
  Returns:
    the database

### getId

    public int getId()

  Description copied from interface: `DbObject`
  Get the unique object id.

  Specified by:
    `getId` in interface `DbObject`
  Returns:
    the object id

### getName

    public java.lang.String getName()

  Description copied from interface: `DbObject`
  Get the name.

  Specified by:
    `getName` in interface `DbObject`
  Returns:
    the name

### isTemporary

    public boolean isTemporary()

  Description copied from interface: `DbObject`
  Check if this object is temporary (for example, a temporary table).

  Specified by:
    `isTemporary` in interface `DbObject`
  Returns:
    true if is temporary

### rename

    public void rename(java.lang.String newName)

  Description copied from interface: `DbObject`
  Rename the object.

  Specified by:
    `rename` in interface `DbObject`
  Parameters:
    `newName` - the new name

### setComment

    public void setComment(java.lang.String comment)

  Description copied from interface: `DbObject`
  Change the comment of this object.

  Specified by:
    `setComment` in interface `DbObject`
  Parameters:
    `comment` - the new comment, or null for no comment

### setTemporary

    public void setTemporary(boolean temporary)

  Description copied from interface: `DbObject`
  Tell this object that it is temporary or not.

  Specified by:
    `setTemporary` in interface `DbObject`
  Parameters:
    `temporary` - the new value

### getRowCountApproximation

    public long getRowCountApproximation()

  Description copied from interface: `Index`
  Get the approximated row count for this table.

  Specified by:
    `getRowCountApproximation` in interface `Index`
  Returns:
    the approximated row count

### getDiskSpaceUsed

    public long getDiskSpaceUsed()

  Description copied from interface: `Index`
  Get the used disk space for this index.

  Specified by:
    `getDiskSpaceUsed` in interface `Index`
  Returns:
    the estimated number of bytes

### getBaseIndex

    public Index getBaseIndex()

### getRow

    public Row getRow(Session session,
                      long key)

  Description copied from interface: `Index`
  Get the row with the given key.

  Specified by:
    `getRow` in interface `Index`
  Parameters:
    `session` - the session
    `key` - the unique key
  Returns:
    the row

### isHidden

    public boolean isHidden()

  Description copied from interface: `SchemaObject`
  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.

  Specified by:
    `isHidden` in interface `SchemaObject`
  Returns:
    true if it is hidden

### isRowIdIndex

    public boolean isRowIdIndex()

  Description copied from interface: `Index`
  Does this index support lookup by row id?

  Specified by:
    `isRowIdIndex` in interface `Index`
  Returns:
    true if it does

### canScan

    public boolean canScan()

  Description copied from interface: `Index`
  Can this index iterate over all rows?

  Specified by:
    `canScan` in interface `Index`
  Returns:
    true if it can

### setSortedInsertMode

    public void setSortedInsertMode(boolean sortedInsertMode)

  Description copied from interface: `Index`
  Enable or disable the 'sorted insert' optimizations (rows are inserted in ascending or descending order) if applicable for this index implementation.

  Specified by:
    `setSortedInsertMode` in interface `Index`
  Parameters:
    `sortedInsertMode` - the new value