Class MergeSort

java.lang.Object
org.apache.derby.impl.store.access.sort.MergeSort
All Implemented Interfaces:
Sort
Direct Known Subclasses:
UniqueWithDuplicateNullsMergeSort

class MergeSort extends Object implements Sort
A sort implementation which does the sort in-memory if it can, but which can do an external merge sort so that it can sort an arbitrary number of rows.
  • Field Details

    • STATE_CLOSED

      private static final int STATE_CLOSED
      See Also:
    • STATE_INITIALIZED

      private static final int STATE_INITIALIZED
      See Also:
    • STATE_INSERTING

      private static final int STATE_INSERTING
      See Also:
    • STATE_DONE_INSERTING

      private static final int STATE_DONE_INSERTING
      See Also:
    • STATE_SCANNING

      private static final int STATE_SCANNING
      See Also:
    • STATE_DONE_SCANNING

      private static final int STATE_DONE_SCANNING
      See Also:
    • state

      private int state
      Maintains the current state of the sort as defined in the preceding values. Sorts start off and end up closed.
    • template

      protected DataValueDescriptor[] template
      The template as passed in on create. Valid when the state is INITIALIZED through SCANNING, null otherwise.
    • columnOrdering

      protected ColumnOrdering[] columnOrdering
      The column ordering as passed in on create. Valid when the state is INITIALIZED through SCANNING, null otherwise. May be null if there is no column ordering - this means that all rows are considered to be duplicates, and the sort will only emit a single row.
    • columnOrderingMap

      protected int[] columnOrderingMap
      A lookup table to speed up lookup of a column associated with the i'th column to compare. To find the column id to compare as the i'th column look in columnOrderingMap[i].
    • columnOrderingAscendingMap

      protected boolean[] columnOrderingAscendingMap
      A lookup table to speed up lookup of Ascending state of a column,
    • columnOrderingNullsLowMap

      protected boolean[] columnOrderingNullsLowMap
      A lookup table to speed up lookup of nulls-low ordering of a column,
    • sortObserver

      SortObserver sortObserver
      The sort observer. May be null. Used as a callback.
    • alreadyInOrder

      protected boolean alreadyInOrder
      Whether the rows are expected to be in order on insert, as passed in on create.
    • inserter

      private MergeInserter inserter
      The inserter that's being used to insert rows into the sort. This field is only valid when the state is INSERTING.
    • scan

      private Scan scan
      The scan that's being used to return rows from the sort. This field is only valid when the state is SCANNING.
    • mergeRuns

      private Vector<Long> mergeRuns
      A vector of merge runs, produced by the MergeInserter. Might be null if no merge runs were produced. It is a vector of container ids.
    • sortBuffer

      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).
    • sortBufferMax

      int sortBufferMax
      The maximum number of entries a sort buffer can hold.
    • sortBufferMin

      int sortBufferMin
      The minimum number of entries a sort buffer can hold.
    • properties

      static Properties properties
      Properties for mergeSort
  • Constructor Details

    • MergeSort

      MergeSort()
  • Method Details