Subject: bug#6643: [PATCH] sort: fix a bug with sort -u and xmemcoll0, and tune keycompare

From: Chen Guo <[email-masked]>
Date: Fri, 16 Jul 2010 03:07:12 -0700

> Chen, can you please verify that "sort -u" does not access the same
> line from multiple threads, even saved lines?  If it does, then even this patch
> is not enough: we would need to alter write_bytes so that it does not
> modify its argument at all.

I just went over the code, pretty big nostalgia trip :-)

write_unique's saved line has already worked its way up to the root node
of the tree; that's to say whatever sorting is to be done on it has already
been done. Thus, none of the merging threads will ever call compare on
it, since they would only do work on remaining un-fully-sorted, yet-to-be-
output lines. Also, only one call to write_unique will ever occur at one
time on one buffer.

The external merge process also makes use of a saved line, but that part
is sequential I believe. Joey's external merge patch might play some games
with it, but I've only skimmed their code. We'll have to cross that bridge
when we get there.