Package org.h2.mvstore.db
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 Summary
Fields Modifier and Type Field Description private Value[]
current
Current value for thenext()
method.private Cursor<ValueRow,java.lang.Long>
cursor
Cursor for thenext()
method.private boolean
distinct
Whether this result is a standard distinct result.private int[]
distinctIndexes
Distinct indexes for DISTINCT ON results.private MVMap<ValueRow,Value>
index
Optional index.private int[]
indexes
Mapping of indexes of columns to its positions in the store, ornull
if columns are not reordered.private MVMap<ValueRow,java.lang.Long>
map
Map with rows as keys and counts of duplicate rows as values.private ValueDataType
orderedDistinctOnType
Used for DISTINCT ON in presence of ORDER BY.private long
valueCount
Count of remaining duplicate rows for thenext()
method.-
Fields inherited from class org.h2.mvstore.db.MVTempResult
childCount, closed, expressions, parent, resultColumnCount, rowCount, store, visibleColumnCount
-
-
Constructor Summary
Constructors Modifier Constructor Description (package private)
MVSortedTempResult(Database database, Expression[] expressions, boolean distinct, int[] distinctIndexes, int visibleColumnCount, int resultColumnCount, SortOrder sort)
Creates a new sorted temporary result.private
MVSortedTempResult(MVSortedTempResult parent)
Creates a shallow copy of the result.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addRow(Value[] values)
Add a row to this object.boolean
contains(Value[] values)
Check if the given row exists in this object.ResultExternal
createShallowCopy()
Create a shallow copy of this object if possible.private ValueRow
getKey(Value[] values)
Reorder values if required and convert them intoValueRow
.private Value[]
getValue(Value[] key)
Reorder values back if required.Value[]
next()
Get the next row from the result.int
removeRow(Value[] values)
Remove the row with the given values from this object if such a row exists.void
reset()
Reset the current position of this object.-
Methods inherited from class org.h2.mvstore.db.MVTempResult
addRows, close, of
-
-
-
-
Field Detail
-
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, ornull
if columns are not reordered.
-
map
private final MVMap<ValueRow,java.lang.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 andcolumnCount != distinctColumnCount
or ifcontains(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.
-
current
private Value[] current
Current value for thenext()
method. Used in non-distinct results with duplicate rows.
-
valueCount
private long valueCount
Count of remaining duplicate rows for thenext()
method. Used in non-distinct results.
-
-
Constructor Detail
-
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
- databaseexpressions
- column expressionsdistinct
- whether this result should be distinctdistinctIndexes
- indexes of distinct columns for DISTINCT ON resultsvisibleColumnCount
- count of visible columnsresultColumnCount
- the number of columns including visible columns and additional virtual columns for ORDER BY and DISTINCT ON clausessort
- sort order, ornull
if this result does not need any sorting
-
-
Method Detail
-
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 intoValueRow
.- 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.
-
-