## org.h2.index
Class BaseIndex

    java.lang.Object
      org.h2.engine.DbObjectBase
          org.h2.schema.SchemaObjectBase
              org.h2.index.BaseIndex

All Implemented Interfaces:
  DbObject, Index, SchemaObject

Direct Known Subclasses:
  BaseHashIndex, BtreeIndex, FunctionIndex, LinkedIndex, MetaIndex, PageIndex, RangeIndex, ScanIndex, TreeIndex, ViewIndex

    public abstract class BaseIndex

extends SchemaObjectBase
implements Index

Most index implementations extend the base index.

Field Summary
`protected int[]` `columnIds`
`protected Column[]` `columns`
`protected IndexColumn[]` `indexColumns`
`protected IndexType` `indexType`
`protected boolean` `isMultiVersion`
`protected Table` `table`

Fields inherited from class org.h2.engine.DbObjectBase
`comment, database, trace`

Fields inherited from interface org.h2.index.Index
`EMPTY_HEAD`

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
`BaseIndex()`

Method Summary
`abstract void` `add(Session session, Row row)` Add a row to this index.
`boolean` `canFindNext()` Check if the index can get the next higher value.
`abstract boolean` `canGetFirstOrLast()` Check if this index can quickly find the first or last value.
`abstract 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.
`abstract Cursor` `find(Session session, SearchRow first, SearchRow last)` Create a cursor to iterate over a number of rows.
`abstract Cursor` `findFirstOrLast(Session session, boolean first)` Find the first (or last) value of this index.
`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.
`abstract double` `getCost(Session session, int[] masks)` Calculate the cost to find rows.
`long` `getCostRangeIndex(int[] masks, long rowCount)` Calculate the cost for the given mask as if this index was a typical b-tree range index.
`java.lang.String` `getCreateSQL()` Build a SQL statement to re-create this object.
`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
`java.lang.String` `getDropSQL()` Build a SQL statement to drop this object.
`java.sql.SQLException` `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.
`Table` `getTable()` Get the table on which this index is based.
`int` `getType()` Get the object type.
`abstract boolean` `needRebuild()` Check if this index needs to be re-built.
`abstract void` `remove(Session session)` Remove the index.
`abstract void` `remove(Session session, Row row)` Remove a row from the index.
`void` `removeChildrenAndResources(Session session)` Remove all dependent objects and free all resources (files, blocks in files) of this object.
`abstract void` `truncate(Session session)` Truncate the index.

Methods inherited from class org.h2.schema.SchemaObjectBase
`getSchema, getSQL, initSchemaObjectBase`

Methods inherited from class org.h2.engine.DbObjectBase
`checkRename, getChildren, getComment, getDatabase, getHeadPos, getId, getModificationId, getName, initDbObjectBase, invalidate, isTemporary, 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.index.Index
`getRowCount, getRowCountApproximation`

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

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

Field Detail

### indexColumns

    protected IndexColumn[] indexColumns

### columns

    protected Column[] columns

### columnIds

    protected int[] columnIds

### table

    protected Table table

### indexType

    protected IndexType indexType

### isMultiVersion

    protected boolean isMultiVersion

Constructor Detail

### BaseIndex

    public BaseIndex()

Method Detail

### getRootPageId

    public int getRootPageId()

  Description copied from interface: `Index`
  Get the root page of this index.

  Specified by:
    `getRootPageId` in interface `Index`
  Returns:
    the root page id

### close

    public abstract void close(Session session)
                        throws java.sql.SQLException

  Close this index.

  Specified by:
    `close` in interface `Index`
  Parameters:
    `session` - the session
  Throws:
    `java.sql.SQLException`

### add

    public abstract void add(Session session,
                             Row row)
                      throws java.sql.SQLException

  Add a row to this index.

  Specified by:
    `add` in interface `Index`
  Parameters:
    `session` - the session
    `row` - the row to add
  Throws:
    `java.sql.SQLException`

### remove

    public abstract void remove(Session session,
                                Row row)
                         throws java.sql.SQLException

  Remove a row from the index.

  Specified by:
    `remove` in interface `Index`
  Parameters:
    `session` - the session
    `row` - the row
  Throws:
    `java.sql.SQLException`

### find

    public abstract Cursor find(Session session,
                                SearchRow first,
                                SearchRow last)
                         throws java.sql.SQLException

  Create a cursor to iterate over a number of rows.

  Specified by:
    `find` in interface `Index`
  Parameters:
    `session` - the session
    `first` - the first row to return (null if no limit)
    `last` - the last row to return (null if no limit)
  Returns:
    the cursor to iterate over the results
  Throws:
    `java.sql.SQLException`

### getCost

    public abstract double getCost(Session session,
                                   int[] masks)
                            throws java.sql.SQLException

  Calculate the cost to find rows.

  Specified by:
    `getCost` in interface `Index`
  Parameters:
    `session` - the session
    `masks` - the condition mask
  Returns:
    the cost
  Throws:
    `java.sql.SQLException`

### remove

    public abstract void remove(Session session)
                         throws java.sql.SQLException

  Remove the index.

  Specified by:
    `remove` in interface `Index`
  Parameters:
    `session` - the session
  Throws:
    `java.sql.SQLException`

### truncate

    public abstract void truncate(Session session)
                           throws java.sql.SQLException

  Truncate the index.

  Specified by:
    `truncate` in interface `Index`
  Parameters:
    `session` - the session
  Throws:
    `java.sql.SQLException`

### canGetFirstOrLast

    public abstract boolean canGetFirstOrLast()

  Check if this index can quickly find the first or last value.

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

### findFirstOrLast

    public abstract Cursor findFirstOrLast(Session session,
                                           boolean first)
                                    throws java.sql.SQLException

  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 for the first value, false for the last
  Returns:
    a cursor (never null)
  Throws:
    `java.sql.SQLException`

### needRebuild

    public abstract boolean needRebuild()

  Check if this index needs to be re-built.

  Specified by:
    `needRebuild` in interface `Index`
  Returns:
    true if it must be re-built.

### getDropSQL

    public java.lang.String getDropSQL()

  Description copied from class: `DbObjectBase`
  Build a SQL statement to drop this object.

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

### getDuplicateKeyException

    public java.sql.SQLException getDuplicateKeyException()

  Description copied from interface: `Index`
  Create a duplicate key exception with a message that contains the index name

  Specified by:
    `getDuplicateKeyException` in interface `Index`
  Returns:
    the exception

### 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

### removeChildrenAndResources

    public void removeChildrenAndResources(Session session)
                                    throws java.sql.SQLException

  Description copied from class: `DbObjectBase`
  Remove all dependent objects and free all resources (files, blocks in files) of this object.

  Specified by:
    `removeChildrenAndResources` in interface `DbObject`
  Specified by:
    `removeChildrenAndResources` in class `DbObjectBase`
  Parameters:
    `session` - the session
  Throws:
    `java.sql.SQLException`

### 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

### findNext

    public Cursor findNext(Session session,
                           SearchRow higherThan,
                           SearchRow last)
                    throws java.sql.SQLException

  Find a row or a list of rows that is larger and create a cursor to iterate over the result. The base implementation doesn't support this feature.

  Specified by:
    `findNext` in interface `Index`
  Parameters:
    `session` - the session
    `higherThan` - the lower limit (excluding)
    `last` - the last row, or null for no limit
  Returns:
    the cursor
  Throws:
    `java.sql.SQLException`

### getLookupCost

    public int getLookupCost(long rowCount)

  Description copied from interface: `Index`
  Estimate the cost required to search a number of rows.

  Specified by:
    `getLookupCost` in interface `Index`
  Parameters:
    `rowCount` - the row count
  Returns:
    the estimated cost

### getCostRangeIndex

    public long getCostRangeIndex(int[] masks,
                                  long rowCount)

  Calculate the cost for the given mask as if this index was a typical b-tree range index.

  Specified by:
    `getCostRangeIndex` in interface `Index`
  Parameters:
    `masks` - the search mask
    `rowCount` - the number of rows in the index
  Returns:
    the calculated cost

### compareRows

    public int compareRows(SearchRow rowData,
                           SearchRow compare)
                    throws java.sql.SQLException

  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
  Throws:
    `java.sql.SQLException`

### containsNullAndAllowMultipleNull

    public boolean containsNullAndAllowMultipleNull(SearchRow newRow)

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

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

### compareKeys

    public int compareKeys(SearchRow rowData,
                           SearchRow compare)

  Description copied from interface: `Index`
  Compare the positions of two rows.

  Specified by:
    `compareKeys` 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)

### getColumnListSQL

    public java.lang.String getColumnListSQL()

  Description copied from interface: `Index`
  Get the list of columns as a string.

  Specified by:
    `getColumnListSQL` in interface `Index`
  Returns:
    the list of columns

### getCreateSQLForCopy

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

  Description copied from class: `DbObjectBase`
  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`
  Specified by:
    `getCreateSQLForCopy` in class `DbObjectBase`
  Parameters:
    `targetTable` - the new table name
    `quotedName` - the new quoted name
  Returns:
    the SQL statement

### getCreateSQL

    public java.lang.String getCreateSQL()

  Description copied from class: `DbObjectBase`
  Build a SQL statement to re-create this object.

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

### 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

### getColumns

    public Column[] getColumns()

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

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

### getIndexType

    public IndexType getIndexType()

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

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

### getType

    public int getType()

  Description copied from class: `DbObjectBase`
  Get the object type.

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

### 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

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

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