diff options
author | Benety Goh <benety@mongodb.com> | 2021-05-22 20:54:15 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-11 09:41:56 +0000 |
commit | ccae69efa20d3ed011718c54a2523ae63def0936 (patch) | |
tree | f885db4a6cbe2624ee704cf1adf78c8a9e588710 | |
parent | 08bd2e4a83e711cba3938684a32c3544b56a61dd (diff) | |
download | mongo-ccae69efa20d3ed011718c54a2523ae63def0936.tar.gz |
SERVER-57178 add js test for verifying in-memory paths for compound multikey index
This test updates multikey paths for multiple indexed fields in a compound index
using different documents inserted within the same storage transaction, before
running a full validation to ensure the in-memory paths are correctly updated to
provided the necessary coverage for queries.
(cherry picked from commit de1fa178269c8cc55ad2012a786074c1d32109a9)
-rw-r--r-- | jstests/noPassthrough/validate_multikey_compound_batch.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/jstests/noPassthrough/validate_multikey_compound_batch.js b/jstests/noPassthrough/validate_multikey_compound_batch.js new file mode 100644 index 00000000000..2a36cafb4a9 --- /dev/null +++ b/jstests/noPassthrough/validate_multikey_compound_batch.js @@ -0,0 +1,53 @@ +/** + * Validates multikey compound index in a collection with a single insert command + * containing documents that update different paths in the multikey index. + * + * @tags: [ + * requires_replication, + * ] + */ +(function() { +'use strict'; + +const rst = new ReplSetTest({nodes: 1}); +rst.startSet(); +rst.initiate(); + +let primary = rst.getPrimary(); +let testColl = primary.getCollection('test.validate_multikey_compound_batch'); + +assert.commandWorked(testColl.getDB().createCollection(testColl.getName())); + +assert.commandWorked(testColl.createIndex({a: 1, b: 1})); + +// Insert 2 documents. Only the first and last documents are valid. +assert.commandWorked( + testColl.insert([{_id: 0, a: [1, 2, 3], b: 'abc'}, {_id: 1, a: 456, b: ['d', 'e', 'f']}])); + +jsTestLog('Checking documents in collection'); +let docs = testColl.find().sort({_id: 1}).toArray(); +assert.eq(2, docs.length, 'too many docs in collection: ' + tojson(docs)); +assert.eq(0, docs[0]._id, 'unexpected document content in collection: ' + tojson(docs)); +assert.eq(1, docs[1]._id, 'unexpected document content in collection: ' + tojson(docs)); + +jsTestLog('Validating collection'); +const result = assert.commandWorked(testColl.validate({full: true})); + +jsTestLog('Validation result: ' + tojson(result)); +assert.eq(testColl.getFullName(), result.ns, tojson(result)); +assert.eq(0, result.nInvalidDocuments, tojson(result)); +assert.eq(2, result.nrecords, tojson(result)); +assert.eq(2, result.nIndexes, tojson(result)); + +// Check non-multikey indexes. +assert.eq(2, result.keysPerIndex._id_, tojson(result)); +assert(result.indexDetails._id_.valid, tojson(result)); + +// Check multikey index. +assert.eq(6, result.keysPerIndex.a_1_b_1, tojson(result)); +assert(result.indexDetails.a_1_b_1.valid, tojson(result)); + +assert(result.valid, tojson(result)); + +rst.stopSet(); +})(); |