Class MVPrimaryIndex

All Implemented Interfaces:
HasSQL

public class MVPrimaryIndex extends MVIndex<Long,SearchRow>
A table stored in a MVStore.
  • Field Details

  • Constructor Details

  • Method Details

    • getCreateSQL

      public String getCreateSQL()
      Description copied from class: DbObject
      Construct the CREATE ... SQL statement for this object.
      Overrides:
      getCreateSQL in class Index
      Returns:
      the SQL statement
    • getPlanSQL

      public String getPlanSQL()
      Description copied from class: Index
      Get the message to show in a EXPLAIN statement.
      Overrides:
      getPlanSQL in class Index
      Returns:
      the plan
    • setMainIndexColumn

      public void setMainIndexColumn(int mainIndexColumn)
    • getMainIndexColumn

      public int getMainIndexColumn()
    • 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
    • lockRow

      Row lockRow(SessionLocal session, Row row)
      Lock a single row.
      Parameters:
      session - database session
      row - to lock
      Returns:
      row object if it exists
    • lockRow

      private Row lockRow(TransactionMap<Long,SearchRow> map, long key)
    • find

      public Cursor find(SessionLocal session, SearchRow first, SearchRow last)
      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
      Returns:
      the cursor to iterate over the results
    • extractPKFromRow

      private long extractPKFromRow(SearchRow row, long defaultValue)
    • 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
    • getRow

      public Row getRow(SessionLocal session, long key)
      Description copied from class: Index
      Get the row with the given key.
      Overrides:
      getRow in class Index
      Parameters:
      session - the session
      key - the unique key
      Returns:
      the row
    • 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
    • getColumnIndex

      public int getColumnIndex(Column col)
      Description copied from class: Index
      Get the index of a column in the list of index columns
      Overrides:
      getColumnIndex in class Index
      Parameters:
      col - the column
      Returns:
      the index (0 meaning first column)
    • isFirstColumn

      public boolean isFirstColumn(Column column)
      Description copied from class: Index
      Check if the given column is the first for this index
      Overrides:
      isFirstColumn in class Index
      Parameters:
      column - the column
      Returns:
      true if the given columns is the first
    • 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
    • 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: Index
      Get the approximated row count for this table.
      Specified by:
      getRowCountApproximation in class Index
      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 class Index
      Returns:
      the estimated number of bytes
    • getMapName

      public String getMapName()
    • 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<Long,SearchRow>
      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<Long,SearchRow>
      Parameters:
      bufferNames - the names of the temporary storage
    • find

      private Cursor find(SessionLocal session, Long first, Long last)
    • isRowIdIndex

      public boolean isRowIdIndex()
      Description copied from class: Index
      Does this index support lookup by row id?
      Overrides:
      isRowIdIndex in class Index
      Returns:
      true if it does
    • getMap

      Get the map to store the data.
      Parameters:
      session - the session
      Returns:
      the map
    • getMVMap

      public MVMap<Long,VersionedValue<SearchRow>> getMVMap()
      Specified by:
      getMVMap in class MVIndex<Long,SearchRow>
    • setRowKey

      private static Row setRowKey(Row row, long key)