diff options
author | Louis Williams <louis.williams@mongodb.com> | 2020-12-07 11:26:21 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-09 14:49:41 +0000 |
commit | 2faadd670bd54e7112c4fec6f6abc011d38b912c (patch) | |
tree | fe25e361dbfb57abdb84d30d89f103fad2f3c477 /jstests | |
parent | 0dd2f47fe508e2ada51aa5090b705c2a2b43ea23 (diff) | |
download | mongo-2faadd670bd54e7112c4fec6f6abc011d38b912c.tar.gz |
SERVER-52929 Correctly handle compound indexes with 32 keys
(cherry picked from commit 957ddd678dbd49a96318a13e8f669567e4eba3ab)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/compound_index_max_fields.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/jstests/core/compound_index_max_fields.js b/jstests/core/compound_index_max_fields.js new file mode 100644 index 00000000000..63cd9224dff --- /dev/null +++ b/jstests/core/compound_index_max_fields.js @@ -0,0 +1,57 @@ +/** + * Tests operations on indexes with the maximum number of compound index fields, 32. + * + * @tags: [ + * assumes_unsharded_collection, + * multiversion_incompatible, + * requires_non_retryable_writes, + * ] + */ +(function() { + +const collName = jsTestName(); +const coll = db[collName]; +coll.drop(); + +// Create a spec with alternating ascending and descending fields to keep things interesting. +let spec = {}; +for (let i = 0; i < 32; i++) { + spec["f" + i] = (i % 2 == 0) ? 1 : -1; +} + +assert.commandWorked(coll.createIndex(spec)); +assert.commandWorked(coll.insert({_id: 0})); +for (let i = 0; i < 32; i++) { + assert.commandWorked(coll.update({_id: 0}, { + $set: {['f' + i]: 1}, + })); +} + +for (let i = 0; i < 32; i++) { + assert.eq(1, coll.find({['f' + i]: 1}).hint(spec).itcount()); +} + +// Create an index that has one too many fields. +let bigSpec = Object.extend({'f32': -1}, spec); +assert.commandFailedWithCode(coll.createIndex(bigSpec), 13103); + +coll.drop(); + +// Create a unique version of the same index from before. +assert.commandWorked(coll.createIndex(spec, {unique: true})); + +let doc = {}; +let doc2 = {}; +for (let i = 0; i < 32; i++) { + doc['f' + i] = 1; + doc2['f' + i] = 2; +} + +assert.commandWorked(coll.insert(doc)); +assert.commandWorked(coll.insert(doc2)); + +for (let i = 0; i < 32; i++) { + let query = {['f' + i]: 1}; + assert.eq(2, coll.find().hint(spec).itcount(), "failed on query: " + tojson(query)); +} +})(); |