From 657c78a08f83125a9d8c4d113b15ce74a9394d06 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 9 Feb 2009 11:42:39 -0500 Subject: [PATCH] Hints don't clobber sort ordering spec --- db/query.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/db/query.cpp b/db/query.cpp index c103f10abf7..c506be69319 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -93,13 +93,17 @@ namespace mongo { for (int i = 0; i < d->nIndexes; i++ ) { IndexDetails& ii = d->indexes[i]; if ( ii.indexName() == hintstr ) { + int direction = matchDirection( ii.keyPattern(), order ); + if ( isSorted ) *isSorted = ( direction != 0 ); + if ( direction == 0 ) + direction = 1; + // NOTE This startKey is incorrect, preserving for the moment so + // we can preserve simpleKeyMatch behavior. BSONObj startKey = ii.getKeyFromQuery(query); - int direction = 1; if ( simpleKeyMatch ) *simpleKeyMatch = query.nFields() == startKey.nFields(); - if ( isSorted ) *isSorted = false; return auto_ptr( - new BtreeCursor(ii, startKey, direction, query)); + new BtreeCursor(ii, emptyObj, direction, query)); } } } @@ -108,13 +112,17 @@ namespace mongo { for (int i = 0; i < d->nIndexes; i++ ) { IndexDetails& ii = d->indexes[i]; if( ii.keyPattern().woCompare(hintobj) == 0 ) { + int direction = matchDirection( ii.keyPattern(), order ); + if ( isSorted ) *isSorted = ( direction != 0 ); + if ( direction == 0 ) + direction = 1; + // NOTE This startKey is incorrect, preserving for the moment so + // we can preserve simpleKeyMatch behavior. BSONObj startKey = ii.getKeyFromQuery(query); - int direction = 1; if ( simpleKeyMatch ) *simpleKeyMatch = query.nFields() == startKey.nFields(); - if ( isSorted ) *isSorted = false; return auto_ptr( - new BtreeCursor(ii, startKey, direction, query)); + new BtreeCursor(ii, emptyObj, direction, query)); } } }