Package org.h2.mvstore.db
Class MVPrimaryIndex
- All Implemented Interfaces:
HasSQL
A table stored in a MVStore.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
A cursor. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TransactionMap
<Long, SearchRow> private final AtomicLong
private int
private final String
private final MVTable
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
ConstructorsConstructorDescriptionMVPrimaryIndex
(Database db, MVTable table, int id, IndexColumn[] columns, IndexType indexType) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Check if the index can directly look up the lowest or highest value of a column.void
close
(SessionLocal session) Close this index.private long
extractPKFromRow
(SearchRow row, long defaultValue) private Cursor
find
(SessionLocal session, Long first, Long last) find
(SessionLocal session, SearchRow first, SearchRow last) Find a row or a list of rows and create a cursor to iterate over the result.findFirstOrLast
(SessionLocal session, boolean first) Find the first (or last) value of this index.int
getColumnIndex
(Column col) Get the index of a column in the list of index columnsdouble
getCost
(SessionLocal session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, AllColumnsForPlan allColumnsSet) Estimate the cost to search for rows given the search mask.Construct the CREATE ...long
Get the used disk space for this index.int
(package private) TransactionMap
<Long, SearchRow> getMap
(SessionLocal session) Get the map to store the data.getMVMap()
Get the message to show in a EXPLAIN statement.getRow
(SessionLocal session, long key) Get the row with the given key.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.long
The maximum number of rows, including uncommitted rows of any session.getTable()
Get the table on which this index is based.boolean
isFirstColumn
(Column column) Check if the given column is the first for this indexboolean
Does this index support lookup by row id?(package private) Row
lockRow
(SessionLocal session, Row row) Lock a single row.private Row
lockRow
(TransactionMap<Long, SearchRow> map, long key) boolean
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
setMainIndexColumn
(int mainIndexColumn) private static Row
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.index.Index
canFindNext, canScan, checkIndexColumnTypes, compareRows, findNext, getColumns, getCostRangeIndex, getCreateSQLForCopy, getDuplicateKeyException, getDuplicatePrimaryKeyMessage, getIndexColumns, getIndexType, getRowFactory, getType, getUniqueColumnCount, getUniqueRowFactory, isFindUsingFullTableScan, isHidden, mayHaveNullDuplicates, 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
-
Field Details
-
mvTable
-
mapName
-
dataMap
-
lastKey
-
mainIndexColumn
private int mainIndexColumn
-
-
Constructor Details
-
MVPrimaryIndex
public MVPrimaryIndex(Database db, MVTable table, int id, IndexColumn[] columns, IndexType indexType)
-
-
Method Details
-
getCreateSQL
Description copied from class:DbObject
Construct the CREATE ... SQL statement for this object.- Overrides:
getCreateSQL
in classIndex
- Returns:
- the SQL statement
-
getPlanSQL
Description copied from class:Index
Get the message to show in a EXPLAIN statement.- Overrides:
getPlanSQL
in classIndex
- Returns:
- the plan
-
setMainIndexColumn
public void setMainIndexColumn(int mainIndexColumn) -
getMainIndexColumn
public int getMainIndexColumn() -
close
Description copied from class:Index
Close this index. -
add
Description copied from class:Index
Add a row to the index. -
remove
Description copied from class:Index
Remove a row from the index. -
update
Description copied from class:Index
Update index after row change. -
lockRow
Lock a single row.- Parameters:
session
- database sessionrow
- to lock- Returns:
- row object if it exists
-
lockRow
-
find
Description copied from class:Index
Find a row or a list of rows and create a cursor to iterate over the result. -
extractPKFromRow
-
getTable
Description copied from class:Index
Get the table on which this index is based. -
getRow
Description copied from class:Index
Get the row with the given key. -
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 classIndex
- Parameters:
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 columns- Returns:
- the estimated cost
-
getColumnIndex
Description copied from class:Index
Get the index of a column in the list of index columns- Overrides:
getColumnIndex
in classIndex
- Parameters:
col
- the column- Returns:
- the index (0 meaning first column)
-
isFirstColumn
Description copied from class:Index
Check if the given column is the first for this index- Overrides:
isFirstColumn
in classIndex
- Parameters:
column
- the column- Returns:
- true if the given columns is the first
-
remove
Description copied from class:Index
Remove the index. -
truncate
Description copied from class:Index
Remove all rows from the index. -
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 classIndex
- Returns:
- true if it can
-
findFirstOrLast
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 classIndex
- Parameters:
session
- the sessionfirst
- 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 classIndex
- Returns:
- true if a rebuild is required.
-
getRowCount
Description copied from class:Index
Get the row count of this table, for the given session.- Specified by:
getRowCount
in classIndex
- Parameters:
session
- the session- Returns:
- the row count
-
getRowCountMax
public long getRowCountMax()The maximum number of rows, including uncommitted rows of any session.- Returns:
- the maximum number of rows
-
getRowCountApproximation
Description copied from class:Index
Get the approximated row count for this table.- Specified by:
getRowCountApproximation
in classIndex
- Parameters:
session
- the session- Returns:
- the approximated row count
-
getDiskSpaceUsed
public long getDiskSpaceUsed()Description copied from class:Index
Get the used disk space for this index.- Overrides:
getDiskSpaceUsed
in classIndex
- Returns:
- the estimated number of bytes
-
getMapName
-
addRowsToBuffer
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 classMVIndex<Long,
SearchRow> - Parameters:
rows
- the rowsbufferName
- the name of the temporary storage
-
addBufferedRows
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 classMVIndex<Long,
SearchRow> - Parameters:
bufferNames
- the names of the temporary storage
-
find
-
isRowIdIndex
public boolean isRowIdIndex()Description copied from class:Index
Does this index support lookup by row id?- Overrides:
isRowIdIndex
in classIndex
- Returns:
- true if it does
-
getMap
Get the map to store the data.- Parameters:
session
- the session- Returns:
- the map
-
getMVMap
-
setRowKey
-