summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-11-17 16:22:01 -0500
committerDwight <dmerriman@gmail.com>2008-11-17 16:22:01 -0500
commit20c1d67ee97199dea32960dbe1c5b610baa90a36 (patch)
treed0d3858281891297394420f63c8a2124d404547c
parent7ce45ce381a4e6078a4700a978645a52f53adc78 (diff)
downloadmongo-20c1d67ee97199dea32960dbe1c5b610baa90a36.tar.gz
$hint+$explain fix
-rw-r--r--db/query.cpp44
-rw-r--r--db/scanandorder.h2
2 files changed, 24 insertions, 22 deletions
diff --git a/db/query.cpp b/db/query.cpp
index 0d5dd735a81..4cefff1755d 100644
--- a/db/query.cpp
+++ b/db/query.cpp
@@ -58,9 +58,24 @@ auto_ptr<Cursor> getIndexCursor(const char *ns, BSONObj& query, BSONObj& order,
NamespaceDetails *d = nsdetails(ns);
if( d == 0 ) return auto_ptr<Cursor>();
- // queryFields, e.g. { 'name' }
- set<string> queryFields;
- query.getFieldNames(queryFields);
+ if( hint && !hint->empty() ) {
+ /* todo: more work needed. doesn't handle $lt & $gt for example.
+ waiting for query optimizer rewrite (see queryoptimizer.h) before finishing the work.
+ */
+ for(int i = 0; i < d->nIndexes; i++ ) {
+ IndexDetails& ii = d->indexes[i];
+ if( ii.indexName() == *hint ) {
+ BSONObj startKey = ii.getKeyFromQuery(query);
+ int direction = 1;
+ bool stopMiss = true;
+ if( simpleKeyMatch )
+ *simpleKeyMatch = query.nFields() == startKey.nFields();
+ if( isSorted ) *isSorted = false;
+ return auto_ptr<Cursor>(
+ new BtreeCursor(ii, startKey, direction, stopMiss));
+ }
+ }
+ }
if( !order.isEmpty() ) {
set<string> orderFields;
@@ -87,24 +102,9 @@ auto_ptr<Cursor> getIndexCursor(const char *ns, BSONObj& query, BSONObj& order,
}
}
- if( hint && !hint->empty() ) {
- /* todo: more work needed. doesn't handle $lt & $gt for example.
- waiting for query optimizer rewrite (see queryoptimizer.h) before finishing the work.
- */
- for(int i = 0; i < d->nIndexes; i++ ) {
- IndexDetails& ii = d->indexes[i];
- if( ii.indexName() == *hint ) {
- BSONObj startKey = ii.getKeyFromQuery(query);
- int direction = 1;
- bool stopMiss = true;
- if( simpleKeyMatch )
- *simpleKeyMatch = query.nFields() == startKey.nFields();
- if( isSorted ) *isSorted = false;
- return auto_ptr<Cursor>(
- new BtreeCursor(ii, startKey, direction, stopMiss));
- }
- }
- }
+ // queryFields, e.g. { 'name' }
+ set<string> queryFields;
+ query.getFieldNames(queryFields);
// regular query without order by
for(int i = 0; i < d->nIndexes; i++ ) {
@@ -736,7 +736,7 @@ QueryResult* runQuery(Message& message, const char *ns, int ntoskip, int _ntoret
BSONObjBuilder builder;
builder.append("cursor", c->toString());
builder.append("nscanned", nscanned);
- builder.append("n", n);
+ builder.append("n", ordering ? so->size() : n);
if( ordering )
builder.append("scanAndOrder", true);
BSONObj obj = builder.done();
diff --git a/db/scanandorder.h b/db/scanandorder.h
index f046b6cc925..a3f2a613313 100644
--- a/db/scanandorder.h
+++ b/db/scanandorder.h
@@ -98,6 +98,8 @@ public:
dir = -1;
}
}
+
+ int size() const { return best.size(); }
void add(BSONObj o) {
BSONObj k = order.getKeyFromObject(o);