class MergeSort extends java.lang.Object implements Sort
Modifier and Type | Field and Description |
---|---|
protected boolean |
alreadyInOrder
Whether the rows are expected to be in order on insert,
as passed in on create.
|
protected ColumnOrdering[] |
columnOrdering
The column ordering as passed in on create.
|
protected boolean[] |
columnOrderingAscendingMap
A lookup table to speed up lookup of Ascending state of a column,
|
protected int[] |
columnOrderingMap
A lookup table to speed up lookup of a column associated with the i'th
column to compare.
|
protected boolean[] |
columnOrderingNullsLowMap
A lookup table to speed up lookup of nulls-low ordering of a column,
|
private MergeInserter |
inserter
The inserter that's being used to insert rows into the sort.
|
private java.util.Vector<java.lang.Long> |
mergeRuns
A vector of merge runs, produced by the MergeInserter.
|
(package private) static java.util.Properties |
properties
Properties for mergeSort
|
private Scan |
scan
The scan that's being used to return rows from the sort.
|
private SortBuffer |
sortBuffer
An ordered set of the leftover rows that didn't go
in the last merge run (might be all the rows if there
are no merge runs).
|
(package private) int |
sortBufferMax
The maximum number of entries a sort buffer can hold.
|
(package private) int |
sortBufferMin
The minimum number of entries a sort buffer can hold.
|
(package private) SortObserver |
sortObserver
The sort observer.
|
private int |
state
Maintains the current state of the sort as defined in
the preceding values.
|
private static int |
STATE_CLOSED |
private static int |
STATE_DONE_INSERTING |
private static int |
STATE_DONE_SCANNING |
private static int |
STATE_INITIALIZED |
private static int |
STATE_INSERTING |
private static int |
STATE_SCANNING |
protected DataValueDescriptor[] |
template
The template as passed in on create.
|
Constructor and Description |
---|
MergeSort() |
Modifier and Type | Method and Description |
---|---|
private boolean |
checkColumnOrdering(DataValueDescriptor[] template,
ColumnOrdering[] columnOrdering)
Check the column ordering against the template, making sure that each
column is present in the template, is not mentioned more than once, and
that the columns isn't
null . |
(package private) void |
checkColumnTypes(DataValueDescriptor[] row)
Check that the columns in the row agree with the columns
in the template, both in number and in type.
|
protected int |
compare(DataValueDescriptor[] r1,
DataValueDescriptor[] r2) |
(package private) long |
createMergeRun(TransactionManager tran,
SortBuffer sortBuffer)
Remove all the rows from the sort buffer and store them
in a temporary conglomerate.
|
(package private) void |
doneInserting(MergeInserter inserter,
SortBuffer sortBuffer,
java.util.Vector<java.lang.Long> mergeRuns)
An inserter is closing.
|
(package private) void |
doneScanning(Scan scan,
SortBuffer sortBuffer) |
(package private) void |
doneScanning(Scan scan,
SortBuffer sortBuffer,
java.util.Vector<java.lang.Long> mergeRuns) |
void |
drop(TransactionController tran)
Drop the sort.
|
(package private) void |
dropMergeRuns(TransactionManager tran)
Get rid of the merge runs, if there are any.
|
void |
initialize(DataValueDescriptor[] template,
ColumnOrdering[] columnOrdering,
SortObserver sortObserver,
boolean alreadyInOrder,
long estimatedRows,
int sortBufferMax)
Go from the CLOSED to the INITIALIZED state.
|
private void |
multiStageMerge(TransactionManager tran) |
SortController |
open(TransactionManager tran)
Open a sort controller.
|
ScanControllerRowSource |
openSortRowSource(TransactionManager tran)
Open a row source to get rows out of the sorter.
|
ScanManager |
openSortScan(TransactionManager tran,
boolean hold)
Open a scan controller.
|
private static final int STATE_CLOSED
private static final int STATE_INITIALIZED
private static final int STATE_INSERTING
private static final int STATE_DONE_INSERTING
private static final int STATE_SCANNING
private static final int STATE_DONE_SCANNING
private int state
protected DataValueDescriptor[] template
protected ColumnOrdering[] columnOrdering
protected int[] columnOrderingMap
protected boolean[] columnOrderingAscendingMap
protected boolean[] columnOrderingNullsLowMap
SortObserver sortObserver
protected boolean alreadyInOrder
private MergeInserter inserter
private Scan scan
private java.util.Vector<java.lang.Long> mergeRuns
private SortBuffer sortBuffer
int sortBufferMax
int sortBufferMin
static java.util.Properties properties
public SortController open(TransactionManager tran) throws StandardException
This implementation only supports a single sort controller per sort.
open
in interface Sort
StandardException
- Standard exception policy.Sort.open(org.apache.derby.iapi.store.access.conglomerate.TransactionManager)
public ScanManager openSortScan(TransactionManager tran, boolean hold) throws StandardException
openSortScan
in interface Sort
StandardException
- Standard exception policy.Sort.openSortScan(org.apache.derby.iapi.store.access.conglomerate.TransactionManager, boolean)
public ScanControllerRowSource openSortRowSource(TransactionManager tran) throws StandardException
openSortRowSource
in interface Sort
StandardException
- Standard exception policy.Sort.openSortRowSource(org.apache.derby.iapi.store.access.conglomerate.TransactionManager)
public void drop(TransactionController tran) throws StandardException
drop
in interface Sort
StandardException
Sort.drop(org.apache.derby.iapi.store.access.TransactionController)
private boolean checkColumnOrdering(DataValueDescriptor[] template, ColumnOrdering[] columnOrdering)
null
.
Intended to be called as part of a sanity check. All columns are
orderable, since DataValueDescriptor
extends Orderable
.
true
if the ordering is valid, false
if not.void checkColumnTypes(DataValueDescriptor[] row) throws StandardException
XXX (nat) Currently checks that the classes implementing each column are the same -- is this right?
StandardException
protected int compare(DataValueDescriptor[] r1, DataValueDescriptor[] r2) throws StandardException
StandardException
public void initialize(DataValueDescriptor[] template, ColumnOrdering[] columnOrdering, SortObserver sortObserver, boolean alreadyInOrder, long estimatedRows, int sortBufferMax) throws StandardException
StandardException
void doneInserting(MergeInserter inserter, SortBuffer sortBuffer, java.util.Vector<java.lang.Long> mergeRuns)
void doneScanning(Scan scan, SortBuffer sortBuffer)
void doneScanning(Scan scan, SortBuffer sortBuffer, java.util.Vector<java.lang.Long> mergeRuns)
void dropMergeRuns(TransactionManager tran)
private void multiStageMerge(TransactionManager tran) throws StandardException
StandardException
long createMergeRun(TransactionManager tran, SortBuffer sortBuffer) throws StandardException
StandardException
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.