summaryrefslogtreecommitdiff
path: root/db/queryoptimizer.cpp
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-02-17 15:53:19 -0500
committerAaron <aaron@10gen.com>2009-02-17 15:53:19 -0500
commit0e38bc5a8fbb78cfd7897be34f0a9adf3746e4fc (patch)
tree46da4e4e8fd0160b12a259d07e4b5b9b22c2fd3b /db/queryoptimizer.cpp
parenta11da1eaa7decb5722fc21fb7999a20c4c3a5c77 (diff)
downloadmongo-0e38bc5a8fbb78cfd7897be34f0a9adf3746e4fc.tar.gz
FieldBound work
Diffstat (limited to 'db/queryoptimizer.cpp')
-rw-r--r--db/queryoptimizer.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/db/queryoptimizer.cpp b/db/queryoptimizer.cpp
index 456afe92bc8..08c29b0ac36 100644
--- a/db/queryoptimizer.cpp
+++ b/db/queryoptimizer.cpp
@@ -32,6 +32,83 @@
namespace mongo {
+ FieldBound::FieldBound( BSONElement e ) :
+ lower_( minKey.firstElement() ),
+ upper_( maxKey.firstElement() ) {
+ if ( e.eoo() )
+ return;
+ if ( e.type() == RegEx ) {
+ const char *r = e.simpleRegex();
+ cout << "r: " << r << endl;
+ if ( r ) {
+ lower_ = addObj( BSON( "" << r ) ).firstElement();
+ upper_ = addObj( BSON( "" << simpleRegexEnd( r ) ) ).firstElement();
+ cout << "lower_: " << lower_ << endl;
+ cout << "upper_: " << upper_ << endl;
+ }
+ return;
+ }
+ switch( e.getGtLtOp() ) {
+ case JSMatcher::Equality:
+ lower_ = e;
+ upper_ = e;
+ break;
+ case JSMatcher::LT:
+ case JSMatcher::LTE:
+ upper_ = e;
+ break;
+ case JSMatcher::GT:
+ case JSMatcher::GTE:
+ lower_ = e;
+ break;
+ default:
+ break;
+ }
+ cout << "lower_: " << lower_ << endl;
+ cout << "upper_: " << upper_ << endl;
+ }
+
+ FieldBound &FieldBound::operator&=( const FieldBound &other ) {
+ if ( other.upper_.woCompare( upper_, false ) < 0 )
+ upper_ = other.upper_;
+ if ( other.lower_.woCompare( lower_, false ) > 0 )
+ lower_ = other.lower_;
+ massert( "Invalid bounds", lower_.woCompare( upper_, false ) <= 0 );
+ return *this;
+ }
+
+ string FieldBound::simpleRegexEnd( string regex ) {
+ ++regex[ regex.length() - 1 ];
+ return regex;
+ }
+
+ BSONObj FieldBound::addObj( BSONObj o ) {
+ cout << "o: " << o.toString() << endl;
+ objData_.push_back( o );
+ return o;
+ }
+
+ FieldBoundSet::FieldBoundSet( BSONObj query ) :
+ query_( query.copy() ) {
+ BSONObjIterator i( query_ );
+ while( i.more() ) {
+ BSONElement e = i.next();
+ if ( e.eoo() )
+ break;
+ if ( getGtLtOp( e ) == JSMatcher::Equality )
+ bounds_[ e.fieldName() ] &= FieldBound( e );
+ else {
+ BSONObjIterator i( e.embeddedObject() );
+ while( i.more() ) {
+ BSONElement f = i.next();
+ if ( f.eoo() )
+ break;
+ bounds_[ e.fieldName() ] &= FieldBound( f );
+ }
+ }
+ }
+ }
+
QueryPlan QueryOptimizer::getPlan(
const char *ns,
BSONObj* query,