Package org.h2.mvstore.db
Class MVPrimaryIndex
- java.lang.Object
-
- org.h2.engine.DbObject
-
- org.h2.schema.SchemaObject
-
- org.h2.index.Index
-
- org.h2.mvstore.db.MVIndex<java.lang.Long,SearchRow>
-
- org.h2.mvstore.db.MVPrimaryIndex
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classMVPrimaryIndex.MVStoreCursorA cursor.
-
Field Summary
Fields Modifier and Type Field Description private TransactionMap<java.lang.Long,SearchRow>dataMapprivate java.util.concurrent.atomic.AtomicLonglastKeyprivate intmainIndexColumnprivate java.lang.StringmapNameprivate MVTablemvTable-
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 MVPrimaryIndex(Database db, MVTable table, int id, IndexColumn[] columns, IndexType indexType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(SessionLocal session, Row row)Add a row to the index.voidaddBufferedRows(java.util.List<java.lang.String> bufferNames)Add all the index data from the buffers to the index.voidaddRowsToBuffer(java.util.List<Row> rows, java.lang.String bufferName)Add the rows to a temporary storage (not to the index yet).booleancanGetFirstOrLast()Check if the index can directly look up the lowest or highest value of a column.voidclose(SessionLocal session)Close this index.private longextractPKFromRow(SearchRow row, long defaultValue)private Cursorfind(SessionLocal session, java.lang.Long first, java.lang.Long last)Cursorfind(SessionLocal session, SearchRow first, SearchRow last)Find a row or a list of rows and create a cursor to iterate over the result.CursorfindFirstOrLast(SessionLocal session, boolean first)Find the first (or last) value of this index.intgetColumnIndex(Column col)Get the index of a column in the list of index columnsdoublegetCost(SessionLocal session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, AllColumnsForPlan allColumnsSet)Estimate the cost to search for rows given the search mask.java.lang.StringgetCreateSQL()Construct the CREATE ...longgetDiskSpaceUsed()Get the used disk space for this index.intgetMainIndexColumn()(package private) TransactionMap<java.lang.Long,SearchRow>getMap(SessionLocal session)Get the map to store the data.java.lang.StringgetMapName()MVMap<java.lang.Long,VersionedValue<SearchRow>>getMVMap()java.lang.StringgetPlanSQL()Get the message to show in a EXPLAIN statement.RowgetRow(SessionLocal session, long key)Get the row with the given key.longgetRowCount(SessionLocal session)Get the row count of this table, for the given session.longgetRowCountApproximation(SessionLocal session)Get the approximated row count for this table.longgetRowCountMax()The maximum number of rows, including uncommitted rows of any session.MVTablegetTable()Get the table on which this index is based.booleanisFirstColumn(Column column)Check if the given column is the first for this indexbooleanisRowIdIndex()Does this index support lookup by row id?(package private) RowlockRow(SessionLocal session, Row row)Lock a single row.private RowlockRow(TransactionMap<java.lang.Long,SearchRow> map, long key)booleanneedRebuild()Check if the index needs to be rebuilt.voidremove(SessionLocal session)Remove the index.voidremove(SessionLocal session, Row row)Remove a row from the index.voidsetMainIndexColumn(int mainIndexColumn)private static RowsetRowKey(Row row, long key)voidtruncate(SessionLocal session)Remove all rows from the index.voidupdate(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 Detail
-
mvTable
private final MVTable mvTable
-
mapName
private final java.lang.String mapName
-
dataMap
private final TransactionMap<java.lang.Long,SearchRow> dataMap
-
lastKey
private final java.util.concurrent.atomic.AtomicLong lastKey
-
mainIndexColumn
private int mainIndexColumn
-
-
Constructor Detail
-
MVPrimaryIndex
public MVPrimaryIndex(Database db, MVTable table, int id, IndexColumn[] columns, IndexType indexType)
-
-
Method Detail
-
getCreateSQL
public java.lang.String getCreateSQL()
Description copied from class:DbObjectConstruct the CREATE ... SQL statement for this object.- Overrides:
getCreateSQLin classIndex- Returns:
- the SQL statement
-
getPlanSQL
public java.lang.String getPlanSQL()
Description copied from class:IndexGet the message to show in a EXPLAIN statement.- Overrides:
getPlanSQLin classIndex- Returns:
- the plan
-
setMainIndexColumn
public void setMainIndexColumn(int mainIndexColumn)
-
getMainIndexColumn
public int getMainIndexColumn()
-
close
public void close(SessionLocal session)
Description copied from class:IndexClose this index.
-
add
public void add(SessionLocal session, Row row)
Description copied from class:IndexAdd a row to the index.
-
remove
public void remove(SessionLocal session, Row row)
Description copied from class:IndexRemove a row from the index.
-
update
public void update(SessionLocal session, Row oldRow, Row newRow)
Description copied from class:IndexUpdate index after row change.
-
lockRow
Row lockRow(SessionLocal session, Row row)
Lock a single row.- Parameters:
session- database sessionrow- to lock- Returns:
- row object if it exists
-
lockRow
private Row lockRow(TransactionMap<java.lang.Long,SearchRow> map, long key)
-
find
public Cursor find(SessionLocal session, SearchRow first, SearchRow last)
Description copied from class:IndexFind a row or a list of rows and create a cursor to iterate over the result.
-
extractPKFromRow
private long extractPKFromRow(SearchRow row, long defaultValue)
-
getTable
public MVTable getTable()
Description copied from class:IndexGet the table on which this index is based.
-
getRow
public Row getRow(SessionLocal session, long key)
Description copied from class:IndexGet 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:IndexEstimate 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:
getCostin 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
public int getColumnIndex(Column col)
Description copied from class:IndexGet the index of a column in the list of index columns- Overrides:
getColumnIndexin classIndex- Parameters:
col- the column- Returns:
- the index (0 meaning first column)
-
isFirstColumn
public boolean isFirstColumn(Column column)
Description copied from class:IndexCheck if the given column is the first for this index- Overrides:
isFirstColumnin classIndex- Parameters:
column- the column- Returns:
- true if the given columns is the first
-
remove
public void remove(SessionLocal session)
Description copied from class:IndexRemove the index.
-
truncate
public void truncate(SessionLocal session)
Description copied from class:IndexRemove all rows from the index.
-
canGetFirstOrLast
public boolean canGetFirstOrLast()
Description copied from class:IndexCheck if the index can directly look up the lowest or highest value of a column.- Overrides:
canGetFirstOrLastin classIndex- Returns:
- true if it can
-
findFirstOrLast
public Cursor findFirstOrLast(SessionLocal session, boolean first)
Description copied from class:IndexFind 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:
findFirstOrLastin 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:IndexCheck if the index needs to be rebuilt. This method is called after opening an index.- Specified by:
needRebuildin classIndex- Returns:
- true if a rebuild is required.
-
getRowCount
public long getRowCount(SessionLocal session)
Description copied from class:IndexGet the row count of this table, for the given session.- Specified by:
getRowCountin 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
public long getRowCountApproximation(SessionLocal session)
Description copied from class:IndexGet the approximated row count for this table.- Specified by:
getRowCountApproximationin classIndex- Parameters:
session- the session- Returns:
- the approximated row count
-
getDiskSpaceUsed
public long getDiskSpaceUsed()
Description copied from class:IndexGet the used disk space for this index.- Overrides:
getDiskSpaceUsedin classIndex- Returns:
- the estimated number of bytes
-
getMapName
public java.lang.String getMapName()
-
addRowsToBuffer
public void addRowsToBuffer(java.util.List<Row> rows, java.lang.String bufferName)
Description copied from class:MVIndexAdd 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:
addRowsToBufferin classMVIndex<java.lang.Long,SearchRow>- Parameters:
rows- the rowsbufferName- the name of the temporary storage
-
addBufferedRows
public void addBufferedRows(java.util.List<java.lang.String> bufferNames)
Description copied from class:MVIndexAdd 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:
addBufferedRowsin classMVIndex<java.lang.Long,SearchRow>- Parameters:
bufferNames- the names of the temporary storage
-
find
private Cursor find(SessionLocal session, java.lang.Long first, java.lang.Long last)
-
isRowIdIndex
public boolean isRowIdIndex()
Description copied from class:IndexDoes this index support lookup by row id?- Overrides:
isRowIdIndexin classIndex- Returns:
- true if it does
-
getMap
TransactionMap<java.lang.Long,SearchRow> getMap(SessionLocal session)
Get the map to store the data.- Parameters:
session- the session- Returns:
- the map
-
getMVMap
public MVMap<java.lang.Long,VersionedValue<SearchRow>> getMVMap()
-
-