The performance of external sorting using merge sort is highly dependent on the length of the runs generated. One of the most commonly used run generation strategies is Replacement Selection (RS) because, on average, it generates runs that are twice the size of the memory available. However, the length of the runs generated by RS is downsized for data with certain characteristics, like inputs sorted inversely with respect to the desired output order. The goal of this paper is to propose and analyze two-way replacement selection (2WRS), which is a generalization of RS obtained by implementing two heaps instead of the single heap implemented by RS. The appropriate management of these two heaps allows generating runs larger than the memory available in a stable way, i.e. independent from the characteristics of the datasets. Depending on the changing characteristics of the input dataset, 2WRS assigns a new data record to one or the other heap, and grows or shrinks each heap, accommodating to the growing or decreasing tendency of the dataset. On average, 2WRS creates runs of at least the length generated by RS, and longer for datasets that combine increasing and decreasing data subsets. We tested both algorithms on large datasets with different characteristics and 2WRS achieves speedups at least similar to RS, and over 2.5 when RS fails to generate large runs.
[1]
Margaret J. Robertson,et al.
Design and Analysis of Experiments
,
2006,
Handbook of statistics.
[2]
Dominguez-SalDavid,et al.
Two-way replacement selection
,
2010,
VLDB 2010.
[3]
M. V. Wilkes,et al.
The Art of Computer Programming, Volume 3, Sorting and Searching
,
1974
.
[4]
Goetz Graefe,et al.
Memory management during run generation in external sorting
,
1998,
SIGMOD '98.
[5]
Michael Stonebraker,et al.
A measure of transaction processing power
,
1985
.
[6]
Stratis Viglas,et al.
Sorting hierarchical data in external memory for archiving
,
2008,
Proc. VLDB Endow..
[7]
Justin Zobel,et al.
Compression techniques for fast external sorting
,
2006,
The VLDB Journal.
[8]
Martin A. Goetz,et al.
Internal and tape sorting using the replacement-selection technique
,
1963,
CACM.
[9]
Per-Åke Larson,et al.
External Sorting: Run Formation Revisited
,
2003,
IEEE Trans. Knowl. Data Eng..
[10]
Goetz Graefe,et al.
Implementing sorting in database systems
,
2006,
CSUR.
[11]
Donald E. Knuth,et al.
The art of computer programming, volume 3: (2nd ed.) sorting and searching
,
1998
.
[12]
Donald Ervin Knuth,et al.
The Art of Computer Programming
,
1968
.
[13]
Per-Åke Larson,et al.
Speeding up External Mergesort
,
1996,
IEEE Trans. Knowl. Data Eng..