Package org.h2.mvstore.db

# Class MVSecondaryIndex

java.lang.Object
org.h2.engine.DbObject
org.h2.schema.SchemaObject
org.h2.index.Index
org.h2.mvstore.db.MVIndex<SearchRow,Value>
org.h2.mvstore.db.MVSecondaryIndex

All Implemented Interfaces:
  `HasSQL`

public final class MVSecondaryIndex extends MVIndex<SearchRow,Value>
An index stored in a MVStore.

## Field Summary

### Fields inherited from class org.h2.index.Index

`columnIds, columns, indexColumns, indexType, table, uniqueColumnColumn`

### Fields inherited from class org.h2.engine.DbObject

`AGGREGATE, comment, COMMENT, CONSTANT, CONSTRAINT, database, DOMAIN, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, SYNONYM, TABLE_OR_VIEW, trace, TRIGGER, USER`

### Fields inherited from interface org.h2.util.HasSQL

`ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS`

## Constructor Summary

Constructors
Constructor
Description
`MVSecondaryIndex(Database db, MVTable table, int id, String indexName, IndexColumn[] columns, int uniqueColumnCount, IndexType indexType)`

## Method Summary

Modifier and Type
Method
Description
`void`
`add(SessionLocal session, Row row)`
Add a row to the index.
`void`
`addBufferedRows(List<String> bufferNames)`
Add all the index data from the buffers to the index.
`void`
`addRowsToBuffer(List<Row> rows, String bufferName)`
Add the rows to a temporary storage (not to the index yet).
`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(SessionLocal session)`
Close this index.
`Cursor`
`find(SessionLocal session, SearchRow first, SearchRow last, boolean reverse)`
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.
`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.
`MVMap<SearchRow,VersionedValue<Value>>`
`getMVMap()`
`long`
`getRowCount(SessionLocal session)`
Get the row count of this table, for the given session.
`long`
`getRowCountApproximation(SessionLocal session)`
Get the approximated row count for this table.
`MVTable`
`getTable()`
Get the table on which this index is based.
`boolean`
`needRebuild()`
Check if the index needs to be rebuilt.
`void`
`remove(SessionLocal session)`
Remove the index.
`void`
`remove(SessionLocal session, Row row)`
Remove a row from the index.
`void`
`truncate(SessionLocal session)`
Remove all rows from the index.
`void`
`update(SessionLocal session, Row oldRow, Row newRow)`
Update index after row change.

### Methods inherited from class org.h2.mvstore.db.MVIndex

`getDiskSpaceUsed`

### Methods inherited from class org.h2.index.Index

`canScan, checkIndexColumnTypes, compareRows, getColumnIndex, getColumns, getCostRangeIndex, getCreateSQL, getCreateSQLForCopy, getDuplicateKeyException, getDuplicatePrimaryKeyMessage, getIndexColumns, getIndexType, getPlanSQL, getRow, getRowFactory, getType, getUniqueColumnCount, getUniqueRowFactory, isFindUsingFullTableScan, isFirstColumn, isRowIdIndex, needsUniqueCheck, removeChildrenAndResources`

### Methods inherited from class org.h2.schema.SchemaObject

`getSchema, getSQL, getSQL`

### Methods inherited from class org.h2.engine.DbObject

`checkRename, getChildren, getComment, getCreateSQLForMeta, getDatabase, getDropSQL, getId, getModificationId, getName, invalidate, isTemporary, isValid, rename, setComment, setModified, setObjectName, setTemporary, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.h2.util.HasSQL

`getTraceSQL`

## Constructor Details

### MVSecondaryIndex

public MVSecondaryIndex(Database db, MVTable table, int id, String indexName, IndexColumn[] columns, int uniqueColumnCount, IndexType indexType)

## Method Details

### addRowsToBuffer

public void addRowsToBuffer(List<Row> rows, String bufferName)
Description copied from class: `MVIndex`
Add the rows to a temporary storage (not to the index yet). The rows are sorted by the index columns. This is to more quickly build the index.

Specified by:
  `addRowsToBuffer` in class `MVIndex<SearchRow,Value>`
Parameters:
  `rows` - the rows
  `bufferName` - the name of the temporary storage

### addBufferedRows

public void addBufferedRows(List<String> bufferNames)
Description copied from class: `MVIndex`
Add all the index data from the buffers to the index. The index will typically use merge sort to add the data more quickly in sorted order.

Specified by:
  `addBufferedRows` in class `MVIndex<SearchRow,Value>`
Parameters:
  `bufferNames` - the names of the temporary storage

### close

public void close(SessionLocal session)
Description copied from class: `Index`
Close this index.

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

### add

public void add(SessionLocal session, Row row)
Description copied from class: `Index`
Add a row to the index.

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

### remove

public void remove(SessionLocal session, Row row)
Description copied from class: `Index`
Remove a row from the index.

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

### update

public void update(SessionLocal session, Row oldRow, Row newRow)
Description copied from class: `Index`
Update index after row change.

Overrides:
  `update` in class `Index`
Parameters:
  `session` - the session
  `oldRow` - row before the update
  `newRow` - row after the update

### find

public Cursor find(SessionLocal session, SearchRow first, SearchRow last, boolean reverse)
Description copied from class: `Index`
Find a row or a list of rows and create a cursor to iterate over the result.

Specified by:
  `find` in class `Index`
Parameters:
  `session` - the session
  `first` - the first row, or null for no limit
  `last` - the last row, or null for no limit
  `reverse` - if true, iterate in reverse (descending) order
Returns:
  the cursor to iterate over the results

### getTable

public MVTable getTable()
Description copied from class: `Index`
Get the table on which this index is based.

Overrides:
  `getTable` in class `Index`
Returns:
  the table

### getCost

public double getCost(SessionLocal session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, AllColumnsForPlan allColumnsSet)
Description copied from class: `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 class `Index`
Parameters:
  `session` - the session
  `masks` - per-column comparison bit masks, null means 'always false', see constants in IndexCondition
  `filters` - all joined table filters
  `filter` - the current table filter index
  `sortOrder` - the sort order
  `allColumnsSet` - the set of all columns
Returns:
  the estimated cost

### remove

public void remove(SessionLocal session)
Description copied from class: `Index`
Remove the index.

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

### truncate

public void truncate(SessionLocal session)
Description copied from class: `Index`
Remove all rows from the index.

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

### canGetFirstOrLast

public boolean canGetFirstOrLast()
Description copied from class: `Index`
Check if the index can directly look up the lowest or highest value of a column.

Overrides:
  `canGetFirstOrLast` in class `Index`
Returns:
  true if it can

### findFirstOrLast

public Cursor findFirstOrLast(SessionLocal session, boolean first)
Description copied from class: `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.

Overrides:
  `findFirstOrLast` in class `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)

### needRebuild

public boolean needRebuild()
Description copied from class: `Index`
Check if the index needs to be rebuilt. This method is called after opening an index.

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

### getRowCount

public long getRowCount(SessionLocal session)
Description copied from class: `Index`
Get the row count of this table, for the given session.

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

### getRowCountApproximation

public long getRowCountApproximation(SessionLocal session)
Description copied from class: `Index`
Get the approximated row count for this table.

Specified by:
  `getRowCountApproximation` in class `Index`
Parameters:
  `session` - the session
Returns:
  the approximated row count

### canFindNext

public boolean canFindNext()
Description copied from class: `Index`
Check if the index can get the next higher value.

Overrides:
  `canFindNext` in class `Index`
Returns:
  true if it can

### findNext

public Cursor findNext(SessionLocal session, SearchRow higherThan, SearchRow last)
Description copied from class: `Index`
Find a row or a list of rows that is larger and create a cursor to iterate over the result.

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

### getMVMap

public MVMap<SearchRow,VersionedValue<Value>> getMVMap()

Specified by:
  `getMVMap` in class `MVIndex<SearchRow,Value>`