summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2014-06-05 14:57:34 -0400
committerGreg Studer <greg@10gen.com>2014-06-10 17:06:53 -0400
commit6537dc777512d093a489cb1db99e8db8cf50b914 (patch)
treec1513b2afeb44a500d57a8316e3b65139b56f7f4 /src/mongo/db/matcher
parente191494d5092181e222c022fe44741951af91a2f (diff)
downloadmongo-6537dc777512d093a489cb1db99e8db8cf50b914.tar.gz
SERVER-5800 convert 2d predicate queries into covered index scans
Diffstat (limited to 'src/mongo/db/matcher')
-rw-r--r--src/mongo/db/matcher/expression_geo.cpp15
-rw-r--r--src/mongo/db/matcher/expression_geo.h10
-rw-r--r--src/mongo/db/matcher/expression_geo_test.cpp6
-rw-r--r--src/mongo/db/matcher/expression_parser_geo.cpp6
4 files changed, 21 insertions, 16 deletions
diff --git a/src/mongo/db/matcher/expression_geo.cpp b/src/mongo/db/matcher/expression_geo.cpp
index 2289fb19c56..c701d0916dc 100644
--- a/src/mongo/db/matcher/expression_geo.cpp
+++ b/src/mongo/db/matcher/expression_geo.cpp
@@ -37,9 +37,9 @@ namespace mongo {
// Geo queries we don't need an index to answer: geoWithin and geoIntersects
//
- Status GeoMatchExpression::init( const StringData& path, const GeoQuery& query,
+ Status GeoMatchExpression::init( const StringData& path, const GeoQuery* query,
const BSONObj& rawObj ) {
- _query = query;
+ _query.reset(query);
_rawObj = rawObj;
return initPath( path );
}
@@ -52,12 +52,12 @@ namespace mongo {
if ( !geometry.parseFrom( e.Obj() ) )
return false;
- if (GeoQuery::WITHIN == _query.getPred()) {
- return _query.getGeometry().contains(geometry);
+ if (GeoQuery::WITHIN == _query->getPred()) {
+ return _query->getGeometry().contains(geometry);
}
else {
- verify(GeoQuery::INTERSECT == _query.getPred());
- return _query.getGeometry().intersects(geometry);
+ verify(GeoQuery::INTERSECT == _query->getPred());
+ return _query->getGeometry().intersects(geometry);
}
}
@@ -88,7 +88,8 @@ namespace mongo {
LeafMatchExpression* GeoMatchExpression::shallowClone() const {
GeoMatchExpression* next = new GeoMatchExpression();
- next->init( path(), _query, _rawObj);
+ next->init( path(), NULL, _rawObj);
+ next->_query = _query;
if (getTag()) {
next->setTag(getTag()->clone());
}
diff --git a/src/mongo/db/matcher/expression_geo.h b/src/mongo/db/matcher/expression_geo.h
index d67edc91919..3a3121a728a 100644
--- a/src/mongo/db/matcher/expression_geo.h
+++ b/src/mongo/db/matcher/expression_geo.h
@@ -42,7 +42,10 @@ namespace mongo {
GeoMatchExpression() : LeafMatchExpression( GEO ){}
virtual ~GeoMatchExpression(){}
- Status init( const StringData& path, const GeoQuery& query, const BSONObj& rawObj );
+ /**
+ * Takes ownership of the passed-in GeoQuery.
+ */
+ Status init( const StringData& path, const GeoQuery* query, const BSONObj& rawObj );
virtual bool matchesSingleElement( const BSONElement& e ) const;
@@ -52,12 +55,13 @@ namespace mongo {
virtual LeafMatchExpression* shallowClone() const;
- const GeoQuery& getGeoQuery() const { return _query; }
+ const GeoQuery& getGeoQuery() const { return *_query; }
const BSONObj getRawObj() const { return _rawObj; }
private:
BSONObj _rawObj;
- GeoQuery _query;
+ // Share ownership of our query with all of our clones
+ shared_ptr<const GeoQuery> _query;
};
class GeoNearMatchExpression : public LeafMatchExpression {
diff --git a/src/mongo/db/matcher/expression_geo_test.cpp b/src/mongo/db/matcher/expression_geo_test.cpp
index 6f22f47c20f..7fe244d555a 100644
--- a/src/mongo/db/matcher/expression_geo_test.cpp
+++ b/src/mongo/db/matcher/expression_geo_test.cpp
@@ -43,11 +43,11 @@ namespace mongo {
TEST( ExpressionGeoTest, Geo1 ) {
BSONObj query = fromjson("{loc:{$within:{$box:[{x: 4, y:4},[6,6]]}}}");
- GeoQuery gq;
- ASSERT( gq.parseFrom( query["loc"].Obj() ) );
+ auto_ptr<GeoQuery> gq(new GeoQuery);
+ ASSERT( gq->parseFrom( query["loc"].Obj() ) );
GeoMatchExpression ge;
- ASSERT( ge.init("a", gq, query ).isOK() );
+ ASSERT( ge.init("a", gq.release(), query ).isOK() );
ASSERT(!ge.matchesBSON(fromjson("{a: [3,4]}")));
ASSERT(ge.matchesBSON(fromjson("{a: [4,4]}")));
diff --git a/src/mongo/db/matcher/expression_parser_geo.cpp b/src/mongo/db/matcher/expression_parser_geo.cpp
index ae238b500ff..ccbfa10dd22 100644
--- a/src/mongo/db/matcher/expression_parser_geo.cpp
+++ b/src/mongo/db/matcher/expression_parser_geo.cpp
@@ -42,8 +42,8 @@ namespace mongo {
int type,
const BSONObj& section ) {
if (BSONObj::opWITHIN == type || BSONObj::opGEO_INTERSECTS == type) {
- GeoQuery gq(name);
- if ( !gq.parseFrom( section ) )
+ auto_ptr<GeoQuery> gq(new GeoQuery(name));
+ if ( !gq->parseFrom( section ) )
return StatusWithMatchExpression( ErrorCodes::BadValue, "bad geo query" );
auto_ptr<GeoMatchExpression> e( new GeoMatchExpression() );
@@ -53,7 +53,7 @@ namespace mongo {
// layer.
BSONObjBuilder bob;
bob.append(name, section);
- Status s = e->init( name, gq, bob.obj() );
+ Status s = e->init( name, gq.release(), bob.obj() );
if ( !s.isOK() )
return StatusWithMatchExpression( s );
return StatusWithMatchExpression( e.release() );