mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
$hint+$explain fix
This commit is contained in:
parent
7ce45ce381
commit
20c1d67ee9
44
db/query.cpp
44
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();
|
||||
|
@ -98,6 +98,8 @@ public:
|
||||
dir = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int size() const { return best.size(); }
|
||||
|
||||
void add(BSONObj o) {
|
||||
BSONObj k = order.getKeyFromObject(o);
|
||||
|
Loading…
Reference in New Issue
Block a user