Class MVSortedTempResult

java.lang.Object
org.h2.mvstore.db.MVTempResult
org.h2.mvstore.db.MVSortedTempResult
All Implemented Interfaces:
ResultExternal

class MVSortedTempResult extends MVTempResult
Sorted temporary result.

This result is used for distinct and/or sorted results.

  • Field Details

    • distinct

      private final boolean distinct
      Whether this result is a standard distinct result.
    • distinctIndexes

      private final int[] distinctIndexes
      Distinct indexes for DISTINCT ON results.
    • indexes

      private final int[] indexes
      Mapping of indexes of columns to its positions in the store, or null if columns are not reordered.
    • map

      private final MVMap<ValueRow,Long> map
      Map with rows as keys and counts of duplicate rows as values. If this map is distinct all values are 1.
    • index

      private MVMap<ValueRow,Value> index
      Optional index. This index is created only if result is distinct and columnCount != distinctColumnCount or if contains(Value[]) method is invoked. Only the root result should have an index if required.
    • orderedDistinctOnType

      private ValueDataType orderedDistinctOnType
      Used for DISTINCT ON in presence of ORDER BY.
    • cursor

      private Cursor<ValueRow,Long> cursor
      Cursor for the next() method.
    • current

      private Value[] current
      Current value for the next() method. Used in non-distinct results with duplicate rows.
    • valueCount

      private long valueCount
      Count of remaining duplicate rows for the next() method. Used in non-distinct results.
  • Constructor Details

    • MVSortedTempResult

      private MVSortedTempResult(MVSortedTempResult parent)
      Creates a shallow copy of the result.
      Parameters:
      parent - parent result
    • MVSortedTempResult

      MVSortedTempResult(Database database, Expression[] expressions, boolean distinct, int[] distinctIndexes, int visibleColumnCount, int resultColumnCount, SortOrder sort)
      Creates a new sorted temporary result.
      Parameters:
      database - database
      expressions - column expressions
      distinct - whether this result should be distinct
      distinctIndexes - indexes of distinct columns for DISTINCT ON results
      visibleColumnCount - count of visible columns
      resultColumnCount - the number of columns including visible columns and additional virtual columns for ORDER BY and DISTINCT ON clauses
      sort - sort order, or null if this result does not need any sorting
  • Method Details

    • addRow

      public int addRow(Value[] values)
      Description copied from interface: ResultExternal
      Add a row to this object.
      Parameters:
      values - the row to add
      Returns:
      the new number of rows in this object
    • contains

      public boolean contains(Value[] values)
      Description copied from interface: ResultExternal
      Check if the given row exists in this object.
      Parameters:
      values - the row
      Returns:
      true if it exists
    • createShallowCopy

      public ResultExternal createShallowCopy()
      Description copied from interface: ResultExternal
      Create a shallow copy of this object if possible.
      Returns:
      the shallow copy, or null
    • getKey

      private ValueRow getKey(Value[] values)
      Reorder values if required and convert them into ValueRow.
      Parameters:
      values - values
      Returns:
      ValueRow for maps
    • getValue

      private Value[] getValue(Value[] key)
      Reorder values back if required.
      Parameters:
      key - reordered values
      Returns:
      original values
    • next

      public Value[] next()
      Description copied from interface: ResultExternal
      Get the next row from the result.
      Returns:
      the next row or null
    • removeRow

      public int removeRow(Value[] values)
      Description copied from interface: ResultExternal
      Remove the row with the given values from this object if such a row exists.
      Parameters:
      values - the row
      Returns:
      the new row count
    • reset

      public void reset()
      Description copied from interface: ResultExternal
      Reset the current position of this object.