summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests
diff options
context:
space:
mode:
authorJames Wahlin <james@mongodb.com>2018-10-19 12:23:27 -0400
committerJames Wahlin <james@mongodb.com>2018-11-02 13:21:56 -0400
commit63317488e39d1eda2760f6e22654dcbffba152e3 (patch)
tree0c647d8a6df3b08712aca1343ffbfa3a33d410cc /src/mongo/dbtests
parent07b22e23018deef35d97045d97c354a65dd4d61f (diff)
downloadmongo-63317488e39d1eda2760f6e22654dcbffba152e3.tar.gz
SERVER-37593 Make wildcard index multikey path set retrieval more efficient
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r--src/mongo/dbtests/SConscript2
-rw-r--r--src/mongo/dbtests/wildcard_access_method_test.cpp74
-rw-r--r--src/mongo/dbtests/wildcard_multikey_persistence_test.cpp9
3 files changed, 82 insertions, 3 deletions
diff --git a/src/mongo/dbtests/SConscript b/src/mongo/dbtests/SConscript
index 60f08f368e4..3d45de4cafe 100644
--- a/src/mongo/dbtests/SConscript
+++ b/src/mongo/dbtests/SConscript
@@ -109,6 +109,7 @@ dbtest = env.Program(
'threadedtests.cpp',
'updatetests.cpp',
'validate_tests.cpp',
+ 'wildcard_access_method_test.cpp',
'wildcard_multikey_persistence_test.cpp',
],
LIBDEPS=[
@@ -119,6 +120,7 @@ dbtest = env.Program(
"$BUILD_DIR/mongo/db/commands/mongod",
"$BUILD_DIR/mongo/db/commands/test_commands_enabled",
"$BUILD_DIR/mongo/db/concurrency/deferred_writer",
+ "$BUILD_DIR/mongo/db/index/index_access_methods",
"$BUILD_DIR/mongo/db/logical_clock",
"$BUILD_DIR/mongo/db/logical_time_metadata_hook",
"$BUILD_DIR/mongo/db/pipeline/document_value_test_util",
diff --git a/src/mongo/dbtests/wildcard_access_method_test.cpp b/src/mongo/dbtests/wildcard_access_method_test.cpp
new file mode 100644
index 00000000000..2f24954378a
--- /dev/null
+++ b/src/mongo/dbtests/wildcard_access_method_test.cpp
@@ -0,0 +1,74 @@
+/**
+ * Copyright (C) 2018-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/bson/json.h"
+#include "mongo/db/index/wildcard_access_method.h"
+#include "mongo/db/query/query_planner_test_lib.h"
+#include "mongo/unittest/unittest.h"
+
+namespace mongo {
+namespace {
+
+void assertCorrectMultikeyMetadataPathBoundsGenerated(StringData field,
+ const BSONObj& expectedBounds) {
+ IndexBounds indexBounds;
+
+ OrderedIntervalList orderedIntervalList;
+ FieldRef fieldRef(field);
+ orderedIntervalList.intervals =
+ WildcardAccessMethod::getMultikeyPathIndexIntervalsForField(std::move(fieldRef));
+
+ indexBounds.fields.push_back(std::move(orderedIntervalList));
+
+ const bool kDoNotRelaxBoundsCheck = false;
+ ASSERT(QueryPlannerTestLib::boundsMatch(
+ expectedBounds, std::move(indexBounds), kDoNotRelaxBoundsCheck));
+}
+
+TEST(WildcardAccessMethodTest, FieldGeneratesExpectedMultikeyPathBounds) {
+ assertCorrectMultikeyMetadataPathBoundsGenerated("foo",
+ fromjson("{'': [['foo','foo',true,true]]}"));
+ assertCorrectMultikeyMetadataPathBoundsGenerated(
+ "foo.bar", fromjson("{'': [['foo','foo',true,true], ['foo.bar','foo.bar',true,true]]}"));
+ assertCorrectMultikeyMetadataPathBoundsGenerated(
+ "foo.0", fromjson("{'': [['foo','foo',true,true], ['foo.','foo/',true,false]]}"));
+ assertCorrectMultikeyMetadataPathBoundsGenerated(
+ "foo.0.bar", fromjson("{'': [['foo','foo',true,true], ['foo.','foo/',true,false]]}"));
+ assertCorrectMultikeyMetadataPathBoundsGenerated(
+ "foo.bar.0",
+ fromjson("{'': [['foo','foo',true,true], ['foo.bar','foo.bar',true,true], "
+ "['foo.bar.','foo.bar/',true,false]]}"));
+ assertCorrectMultikeyMetadataPathBoundsGenerated(
+ "foo.0.bar.1", fromjson("{'': [['foo','foo',true,true], ['foo.','foo/',true,false]]}"));
+}
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp b/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
index e7b48c4f98e..0c167e340f4 100644
--- a/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
+++ b/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
@@ -35,7 +35,9 @@
#include "mongo/db/catalog/multi_index_block.h"
#include "mongo/db/catalog/multi_index_block_impl.h"
#include "mongo/db/db_raii.h"
+#include "mongo/db/index/wildcard_access_method.h"
#include "mongo/db/repl/storage_interface_impl.h"
+#include "mongo/db/storage/sorted_data_interface.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -138,7 +140,8 @@ protected:
AutoGetCollectionForRead autoColl(opCtx(), nss);
auto collection = autoColl.getCollection();
auto indexAccessMethod = getIndex(collection, indexName);
- auto multikeyPathSet = indexAccessMethod->getMultikeyPathSet(opCtx());
+ MultikeyMetadataAccessStats stats;
+ auto multikeyPathSet = indexAccessMethod->getMultikeyPathSet(opCtx(), &stats);
ASSERT(expectedFieldRefs == multikeyPathSet);
}
@@ -218,11 +221,11 @@ protected:
return collection->getIndexCatalog()->findIndexByName(opCtx(), indexName);
}
- const IndexAccessMethod* getIndex(const Collection* collection, const StringData indexName) {
+ IndexAccessMethod* getIndex(Collection* collection, const StringData indexName) {
return collection->getIndexCatalog()->getIndex(getIndexDesc(collection, indexName));
}
- std::unique_ptr<SortedDataInterface::Cursor> getIndexCursor(const Collection* collection,
+ std::unique_ptr<SortedDataInterface::Cursor> getIndexCursor(Collection* collection,
const StringData indexName) {
return getIndex(collection, indexName)->newCursor(opCtx());
}