Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

skip indices which require sorting for distinct SERVER-2135

  • Loading branch information...
commit a3b7bb6b8339433b7926477307f0c3c185beb48f 1 parent 54dc72c
gregs authored
View
2  db/commands/distinct.cpp
@@ -78,7 +78,7 @@ namespace mongo {
if ( idx.inKeyPattern( key ) ) {
cursor = bestGuessCursor( ns.c_str() , BSONObj() , idx.keyPattern() );
- break;
+ if( cursor.get() ) break;
}
}
View
19 db/queryoptimizer.cpp
@@ -523,17 +523,16 @@ namespace mongo {
return _plans[i];
}
- stringstream ss;
- ss << "best guess plan requested, but scan and order required:";
- ss << " query: " << _frs->simplifiedQuery();
- ss << " order: " << _order;
- ss << " choices: ";
- for ( unsigned i=0; i<_plans.size(); i++ ) {
- ss << _plans[i]->indexKey() << " ";
- }
+ warning() << "best guess query plan requested, but scan and order are required for all plans "
+ << " query: " << _frs->simplifiedQuery()
+ << " order: " << _order
+ << " choices: ";
+
+ for ( unsigned i=0; i<_plans.size(); i++ )
+ warning() << _plans[i]->indexKey() << " ";
+ warning() << endl;
- string s = ss.str();
- msgassertedNoTrace( 13284, s.c_str() );
+ return QueryPlanPtr();
}
return _plans[0];
}
View
13 db/queryoptimizer.h
@@ -146,7 +146,7 @@ namespace mongo {
ExceptionInfo exception() const { return _exception; }
const QueryPlan &qp() const { return *_qp; }
// To be called by QueryPlanSet::Runner only.
- void setQueryPlan( const QueryPlan *qp ) { _qp = qp; }
+ void setQueryPlan( const QueryPlan *qp ) { _qp = qp; assert( _qp != NULL ); }
void setException( const DBException &e ) {
_error = true;
_exception = e.getInfo();
@@ -441,6 +441,9 @@ namespace mongo {
}
// matcher() will always work on the returned cursor
+ // It is possible no cursor is returned if the sort is not supported by an index. Clients are responsible
+ // for checking this if they are not sure an index for a sort exists, and defaulting to a non-sort if
+ // no suitable indices exist.
inline shared_ptr< Cursor > bestGuessCursor( const char *ns, const BSONObj &query, const BSONObj &sort ) {
if( !query.getField( "$or" ).eoo() ) {
return shared_ptr< Cursor >( new MultiCursor( ns, query, sort ) );
@@ -448,7 +451,13 @@ namespace mongo {
else {
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns, query ) );
auto_ptr< FieldRangeSet > origFrs( new FieldRangeSet( *frs ) );
- shared_ptr< Cursor > ret = QueryPlanSet( ns, frs, origFrs, query, sort ).getBestGuess()->newCursor();
+
+ QueryPlanSet qps( ns, frs, origFrs, query, sort );
+ QueryPlanSet::QueryPlanPtr qpp = qps.getBestGuess();
+ if( ! qpp.get() ) return shared_ptr< Cursor >();
+
+ shared_ptr< Cursor > ret = qpp->newCursor();
+
// If we don't already have a matcher, supply one.
if ( !query.isEmpty() && ! ret->matcher() ) {
shared_ptr< CoveredIndexMatcher > matcher( new CoveredIndexMatcher( query, ret->indexKeyPattern() ) );
View
16 jstests/geo_distinct.js
@@ -0,0 +1,16 @@
+// Test distinct with geo queries SERVER-2135
+
+t = db.commits
+t.drop()
+
+t.save( { _id : ObjectId( "4ce63ec2f360622431000013" ), loc : [ 55.59664, 13.00156 ], author : "FredrikL" } )
+
+printjson( db.runCommand( { distinct : 'commits', key : 'loc' } ) )
+assert.isnull( db.getLastError() )
+
+t.ensureIndex( { loc : '2d' } )
+
+printjson( t.getIndexes() )
+
+printjson( db.runCommand( { distinct : 'commits', key : 'loc' } ) )
+assert.isnull( db.getLastError() )
Please sign in to comment.
Something went wrong with that request. Please try again.