summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2013-02-28 16:43:45 -0500
committerEliot Horowitz <eliot@10gen.com>2013-02-28 16:44:11 -0500
commit0c8ac1a52dcf0a93e6e1ab4d701215b2beb6cff6 (patch)
treef1322b1ec72f19e8f60297e8dc7a846038dff82c
parentdd142e8324f977197107c9bbec62f4af3670aebd (diff)
downloadmongo-0c8ac1a52dcf0a93e6e1ab4d701215b2beb6cff6.tar.gz
SERVER-8758 - IndexSet fix for ab vs a
-rw-r--r--src/mongo/db/index_set.cpp16
-rw-r--r--src/mongo/db/index_set.h3
-rw-r--r--src/mongo/db/index_set_test.cpp7
3 files changed, 24 insertions, 2 deletions
diff --git a/src/mongo/db/index_set.cpp b/src/mongo/db/index_set.cpp
index 4d7cb62a759..65f74ed54ea 100644
--- a/src/mongo/db/index_set.cpp
+++ b/src/mongo/db/index_set.cpp
@@ -47,16 +47,28 @@ namespace mongo {
StringData idx( *i );
- if ( use.startsWith( idx ) )
+ if ( _startsWith( use, idx ) )
return true;
- if ( idx.startsWith( use ) )
+ if ( _startsWith( idx, use ) )
return true;
}
return false;
}
+ bool IndexPathSet::_startsWith( const StringData& a, const StringData& b ) const {
+ if ( !a.startsWith( b ) )
+ return false;
+
+ // make sure there is a dot or EOL right after
+
+ if ( a.size() == b.size() )
+ return true;
+
+ return a[b.size()] == '.';
+ }
+
bool getCanonicalIndexField( const StringData& fullName, string* out ) {
// check if fieldName contains ".$" or ".###" substrings (#=digit) and skip them
// however do not skip the first field even if it meets these criteria
diff --git a/src/mongo/db/index_set.h b/src/mongo/db/index_set.h
index 24717750e9a..1ff99780f07 100644
--- a/src/mongo/db/index_set.h
+++ b/src/mongo/db/index_set.h
@@ -39,6 +39,9 @@ namespace mongo {
bool mightBeIndexed( const StringData& path ) const;
private:
+
+ bool _startsWith( const StringData& a, const StringData& b ) const;
+
std::set<std::string> _canonical;
};
diff --git a/src/mongo/db/index_set_test.cpp b/src/mongo/db/index_set_test.cpp
index aac5b43550b..28a1d9fe68e 100644
--- a/src/mongo/db/index_set_test.cpp
+++ b/src/mongo/db/index_set_test.cpp
@@ -33,6 +33,13 @@ namespace mongo {
ASSERT_FALSE( a.mightBeIndexed( "a.c" ) );
}
+ TEST( IndexPathSetTest, Simple2 ) {
+ IndexPathSet a;
+ a.addPath( "ab" );
+ ASSERT_FALSE( a.mightBeIndexed( "a" ) );
+ }
+
+
TEST( IndexPathSetTest, getCanonicalIndexField1 ) {
string x;