0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

Support large count and nscanned

This commit is contained in:
Aaron 2009-03-24 12:12:04 -04:00
parent ca46791a7b
commit c27e290116
6 changed files with 21 additions and 21 deletions

View File

@ -571,8 +571,8 @@ namespace mongo {
virtual bool run(const char *_ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) { virtual bool run(const char *_ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
string ns = database->name + '.' + cmdObj.findElement(name).valuestr(); string ns = database->name + '.' + cmdObj.findElement(name).valuestr();
string err; string err;
int n = runCount(ns.c_str(), cmdObj, err); long long n = runCount(ns.c_str(), cmdObj, err);
int nn = n; long long nn = n;
bool ok = true; bool ok = true;
if ( n < 0 ) { if ( n < 0 ) {
ok = false; ok = false;

View File

@ -353,7 +353,7 @@ namespace mongo {
set<string> allIndexKeys; set<string> allIndexKeys;
void computeIndexKeys(); void computeIndexKeys();
int writeCount_; int writeCount_;
map< QueryPattern, pair< BSONObj, int > > queryCache_; map< QueryPattern, pair< BSONObj, long long > > queryCache_;
string logNS_; string logNS_;
bool logValid_; bool logValid_;
public: public:
@ -387,10 +387,10 @@ namespace mongo {
BSONObj indexForPattern( const QueryPattern &pattern ) { BSONObj indexForPattern( const QueryPattern &pattern ) {
return queryCache_[ pattern ].first; return queryCache_[ pattern ].first;
} }
int nScannedForPattern( const QueryPattern &pattern ) { long long nScannedForPattern( const QueryPattern &pattern ) {
return queryCache_[ pattern ].second; return queryCache_[ pattern ].second;
} }
void registerIndexForPattern( const QueryPattern &pattern, const BSONObj &indexKey, int nScanned ) { void registerIndexForPattern( const QueryPattern &pattern, const BSONObj &indexKey, long long nScanned ) {
queryCache_[ pattern ] = make_pair( indexKey, nScanned ); queryCache_[ pattern ] = make_pair( indexKey, nScanned );
} }

View File

@ -96,7 +96,7 @@ namespace mongo {
bool justOne_; bool justOne_;
int count_; int count_;
int &bestCount_; int &bestCount_;
int nScanned_; long long nScanned_;
auto_ptr< Cursor > c_; auto_ptr< Cursor > c_;
auto_ptr< KeyValJSMatcher > matcher_; auto_ptr< KeyValJSMatcher > matcher_;
}; };
@ -369,10 +369,10 @@ namespace mongo {
return new UpdateOp(); return new UpdateOp();
} }
auto_ptr< Cursor > c() { return c_; } auto_ptr< Cursor > c() { return c_; }
int nscanned() const { return nscanned_; } long long nscanned() const { return nscanned_; }
private: private:
auto_ptr< Cursor > c_; auto_ptr< Cursor > c_;
int nscanned_; long long nscanned_;
auto_ptr< KeyValJSMatcher > matcher_; auto_ptr< KeyValJSMatcher > matcher_;
}; };
@ -708,11 +708,11 @@ namespace mongo {
virtual QueryOp *clone() const { virtual QueryOp *clone() const {
return new CountOp( spec_ ); return new CountOp( spec_ );
} }
int count() const { return count_; } long long count() const { return count_; }
virtual bool mayRecordPlan() const { return true; } virtual bool mayRecordPlan() const { return true; }
private: private:
BSONObj spec_; BSONObj spec_;
int count_; long long count_;
auto_ptr< Cursor > c_; auto_ptr< Cursor > c_;
BSONObj query_; BSONObj query_;
set< string > fields_; set< string > fields_;
@ -724,7 +724,7 @@ namespace mongo {
/* { count: "collectionname"[, query: <query>] } /* { count: "collectionname"[, query: <query>] }
returns -1 on ns does not exist error. returns -1 on ns does not exist error.
*/ */
int runCount( const char *ns, const BSONObj &cmd, string &err ) { long long runCount( const char *ns, const BSONObj &cmd, string &err ) {
NamespaceDetails *d = nsdetails( ns ); NamespaceDetails *d = nsdetails( ns );
if ( !d ) { if ( !d ) {
err = "ns missing"; err = "ns missing";
@ -882,7 +882,7 @@ namespace mongo {
auto_ptr< Cursor > cursor() { return c_; } auto_ptr< Cursor > cursor() { return c_; }
auto_ptr< KeyValJSMatcher > matcher() { return matcher_; } auto_ptr< KeyValJSMatcher > matcher() { return matcher_; }
int n() const { return n_; } int n() const { return n_; }
int nscanned() const { return nscanned_; } long long nscanned() const { return nscanned_; }
bool saveClientCursor() const { return saveClientCursor_; } bool saveClientCursor() const { return saveClientCursor_; }
private: private:
BufBuilder b_; BufBuilder b_;
@ -894,7 +894,7 @@ namespace mongo {
set< string > *filter_; set< string > *filter_;
bool ordering_; bool ordering_;
auto_ptr< Cursor > c_; auto_ptr< Cursor > c_;
int nscanned_; long long nscanned_;
int queryOptions_; int queryOptions_;
auto_ptr< KeyValJSMatcher > matcher_; auto_ptr< KeyValJSMatcher > matcher_;
int n_; int n_;
@ -918,7 +918,7 @@ namespace mongo {
log(2) << "runQuery: " << ns << jsobj << endl; log(2) << "runQuery: " << ns << jsobj << endl;
int nscanned = 0; long long nscanned = 0;
bool wantMore = true; bool wantMore = true;
int ntoreturn = _ntoreturn; int ntoreturn = _ntoreturn;
if ( _ntoreturn < 0 ) { if ( _ntoreturn < 0 ) {
@ -1041,7 +1041,7 @@ namespace mongo {
builder.append("cursor", c->toString()); builder.append("cursor", c->toString());
builder.append("startKey", c->prettyStartKey()); builder.append("startKey", c->prettyStartKey());
builder.append("endKey", c->prettyEndKey()); builder.append("endKey", c->prettyEndKey());
builder.append("nscanned", dqo.nscanned()); builder.append("nscanned", double( dqo.nscanned() ) );
builder.append("n", n); builder.append("n", n);
if ( dqo.scanAndOrderRequired() ) if ( dqo.scanAndOrderRequired() )
builder.append("scanAndOrder", true); builder.append("scanAndOrder", true);

View File

@ -77,7 +77,7 @@ namespace mongo {
// If justOne is true, deletedId is set to the id of the deleted object. // If justOne is true, deletedId is set to the id of the deleted object.
int deleteObjects(const char *ns, BSONObj pattern, bool justOne, BSONObj *deletedId = 0, bool god=false); int deleteObjects(const char *ns, BSONObj pattern, bool justOne, BSONObj *deletedId = 0, bool god=false);
int runCount(const char *ns, const BSONObj& cmd, string& err); long long runCount(const char *ns, const BSONObj& cmd, string& err);
auto_ptr< QueryResult > runQuery(Message& m, stringstream& ss ); auto_ptr< QueryResult > runQuery(Message& m, stringstream& ss );

View File

@ -155,7 +155,7 @@ namespace mongo {
return index_->keyPattern(); return index_->keyPattern();
} }
void QueryPlan::registerSelf( int nScanned ) const { void QueryPlan::registerSelf( long long nScanned ) const {
NamespaceDetailsTransient::get( ns() ).registerIndexForPattern( fbs_.pattern( order_ ), indexKey(), nScanned ); NamespaceDetailsTransient::get( ns() ).registerIndexForPattern( fbs_.pattern( order_ ), indexKey(), nScanned );
} }
@ -322,8 +322,8 @@ namespace mongo {
return *i; return *i;
} }
int nScanned = 0; long long nScanned = 0;
int nScannedBackup = 0; long long nScannedBackup = 0;
while( 1 ) { while( 1 ) {
++nScanned; ++nScanned;
unsigned errCount = 0; unsigned errCount = 0;

View File

@ -51,7 +51,7 @@ namespace mongo {
const char *ns() const { return fbs_.ns(); } const char *ns() const { return fbs_.ns(); }
BSONObj query() const { return fbs_.query(); } BSONObj query() const { return fbs_.query(); }
const FieldBound &bound( const char *fieldName ) const { return fbs_.bound( fieldName ); } const FieldBound &bound( const char *fieldName ) const { return fbs_.bound( fieldName ); }
void registerSelf( int nScanned ) const; void registerSelf( long long nScanned ) const;
private: private:
const FieldBoundSet &fbs_; const FieldBoundSet &fbs_;
const BSONObj &order_; const BSONObj &order_;
@ -132,7 +132,7 @@ namespace mongo {
bool usingPrerecordedPlan_; bool usingPrerecordedPlan_;
BSONObj hint_; BSONObj hint_;
BSONObj order_; BSONObj order_;
int oldNScanned_; long long oldNScanned_;
bool honorRecordedPlan_; bool honorRecordedPlan_;
}; };