From 91c4607f7697ee2d5e7c10d65e8ba340aaf5478c Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 6 Apr 2009 17:32:40 -0400 Subject: [PATCH] make simple find faster --- db/btree.h | 2 ++ db/btreecursor.cpp | 8 +++++--- db/query.cpp | 7 +++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/db/btree.h b/db/btree.h index 5413b270d78..fddfd3fcee8 100644 --- a/db/btree.h +++ b/db/btree.h @@ -274,6 +274,8 @@ namespace mongo { return prettyKey( endKey ); } + void forgetEndKey() { endKey = BSONObj(); } + private: /* Our btrees may (rarely) have "unused" keys when items are deleted. Skip past them. diff --git a/db/btreecursor.cpp b/db/btreecursor.cpp index f2bf8546697..7665fb40962 100644 --- a/db/btreecursor.cpp +++ b/db/btreecursor.cpp @@ -82,9 +82,11 @@ namespace mongo { void BtreeCursor::checkEnd() { if ( bucket.isNull() ) return; - int cmp = sgn( endKey.woCompare( currKey(), order ) ); - if ( cmp != 0 && cmp != direction ) - bucket = DiskLoc(); + if ( !endKey.isEmpty() ) { + int cmp = sgn( endKey.woCompare( currKey(), order ) ); + if ( cmp != 0 && cmp != direction ) + bucket = DiskLoc(); + } } bool BtreeCursor::advance() { diff --git a/db/query.cpp b/db/query.cpp index 5164ba629b7..54b6db7845c 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -857,10 +857,13 @@ namespace mongo { query_ = spec_.getObjectField( "query" ); spec_.getObjectField( "fields" ).getFieldNames( fields_ ); c_ = qp().newCursor(); - if ( qp().exactKeyMatch() && fields_.empty() ) + if ( qp().exactKeyMatch() && fields_.empty() ) { bc_ = dynamic_cast< BtreeCursor* >( c_.get() ); - else + bc_->forgetEndKey(); + } + else { matcher_.reset( new JSMatcher( query_ ) ); + } } virtual void next() { if ( !c_->ok() ) {