mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
don't use any files for external sort if its in 1 chunk
This commit is contained in:
parent
ab135dd2f4
commit
c2c136a3f2
@ -56,6 +56,10 @@ namespace mongo {
|
||||
|
||||
_sorted = true;
|
||||
|
||||
if ( _map && _files.size() == 0 ){
|
||||
return;
|
||||
}
|
||||
|
||||
if ( _map ){
|
||||
finishMap();
|
||||
}
|
||||
@ -120,11 +124,20 @@ namespace mongo {
|
||||
|
||||
// ---------------------------------
|
||||
|
||||
BSONObjExternalSorter::Iterator::Iterator( BSONObjExternalSorter * sorter ) : _cmp( sorter->_order ){
|
||||
BSONObjExternalSorter::Iterator::Iterator( BSONObjExternalSorter * sorter ) :
|
||||
_cmp( sorter->_order ) , _in( 0 ){
|
||||
|
||||
for ( list<string>::iterator i=sorter->_files.begin(); i!=sorter->_files.end(); i++ ){
|
||||
_files.push_back( new FileIterator( *i ) );
|
||||
_stash.push_back( pair<Data,bool>( Data( BSONObj() , DiskLoc() ) , false ) );
|
||||
}
|
||||
|
||||
if ( _files.size() == 0 && sorter->_map ){
|
||||
_in = sorter->_map;
|
||||
_it = sorter->_map->begin();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
BSONObjExternalSorter::Iterator::~Iterator(){
|
||||
@ -134,6 +147,10 @@ namespace mongo {
|
||||
}
|
||||
|
||||
bool BSONObjExternalSorter::Iterator::more(){
|
||||
|
||||
if ( _in )
|
||||
return _it != _in->end();
|
||||
|
||||
for ( vector<FileIterator*>::iterator i=_files.begin(); i!=_files.end(); i++ )
|
||||
if ( (*i)->more() )
|
||||
return true;
|
||||
@ -144,6 +161,11 @@ namespace mongo {
|
||||
}
|
||||
|
||||
pair<BSONObj,DiskLoc> BSONObjExternalSorter::Iterator::next(){
|
||||
|
||||
if ( _in ){
|
||||
return *(_it++);
|
||||
}
|
||||
|
||||
Data best;
|
||||
int slot = -1;
|
||||
|
||||
|
@ -77,6 +77,10 @@ namespace mongo {
|
||||
MyCmp _cmp;
|
||||
vector<FileIterator*> _files;
|
||||
vector< pair<Data,bool> > _stash;
|
||||
|
||||
InMemory * _in;
|
||||
InMemory::iterator _it;
|
||||
|
||||
};
|
||||
|
||||
BSONObjExternalSorter( const BSONObj & order = BSONObj() , long maxFileSize = 1024 * 1024 * 100 );
|
||||
@ -95,6 +99,10 @@ namespace mongo {
|
||||
return auto_ptr<Iterator>( new Iterator( this ) );
|
||||
}
|
||||
|
||||
int numFiles(){
|
||||
return _files.size();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void sort( string file );
|
||||
|
@ -827,6 +827,8 @@ namespace JsobjTests {
|
||||
num++;
|
||||
}
|
||||
|
||||
|
||||
ASSERT_EQUALS( 0 , sorter.numFiles() );
|
||||
}
|
||||
};
|
||||
|
||||
@ -956,6 +958,7 @@ namespace JsobjTests {
|
||||
prev = cur;
|
||||
}
|
||||
assert( num == total );
|
||||
ASSERT( sorter.numFiles() > 2 );
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user