Skip to content

Commit edc96ac

Browse files
committed
SERVER-32755 Expand unique index microbenchmark coverage
1 parent 1c2adce commit edc96ac

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

testcases/simple_insert.js

+73
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,76 @@ tests.push( { name: "Insert.LargeDocVector",
260260
doc: docs }
261261
] } );
262262

263+
/*
264+
* Setup: Create an empty collection and a unique index on a field.
265+
* Test: Insert documents into collection using sequential int for the indexed
266+
* field.
267+
* Notes: Let mongod create missing _id field
268+
*
269+
*/
270+
tests.push( { name: "Insert.UniqueIndex",
271+
tags: ['insert','uniqueidx', 'regression'],
272+
pre: function( collection ) {
273+
var testDB = collection.getDB();
274+
var collName = collection.getName();
275+
collection.drop();
276+
testDB.createCollection( collName );
277+
collection.ensureIndex( { a: 1 }, { unique: true } );
278+
},
279+
ops: [
280+
{ op: "insert",
281+
doc:
282+
{ a: { "#SEQ_INT":
283+
{ seq_id: 0, start: 0, step: 1, unique: true } } } }
284+
] } );
285+
286+
/*
287+
* Setup: Create an empty collection and a unique compound index on two fields.
288+
* Test: Insert documents into collection using sequential int for the indexed
289+
* fields.
290+
* Notes: Let mongod create missing _id field
291+
*
292+
*/
293+
tests.push( { name: "Insert.UniqueIndexCompound",
294+
tags: ['insert','uniqueidx','regression'],
295+
pre: function( collection ) {
296+
var testDB = collection.getDB();
297+
var collName = collection.getName();
298+
collection.drop();
299+
testDB.createCollection( collName );
300+
collection.ensureIndex( { a: 1, b: 1 }, { unique: true } );
301+
},
302+
ops: [
303+
{ op: "insert",
304+
doc:
305+
{ a: { "#SEQ_INT":
306+
{ seq_id: 0, start: 0, step: 1, unique: true } },
307+
b: { "#SEQ_INT":
308+
{ seq_id: 0, start: 0, step: 1, unique: true } } } }
309+
] } );
310+
311+
/*
312+
* Setup: Create an empty collection and a unique compound index on two fields,
313+
* with different ordering for both the fields.
314+
* Test: Insert documents into collection using sequential int for the indexed
315+
* fields.
316+
* Notes: Let mongod create missing _id field
317+
*
318+
*/
319+
tests.push( { name: "Insert.UniqueIndexCompoundReverse",
320+
tags: ['insert','uniqueidx','regression'],
321+
pre: function( collection ) {
322+
var testDB = collection.getDB();
323+
var collName = collection.getName();
324+
collection.drop();
325+
testDB.createCollection( collName );
326+
collection.ensureIndex( { a: 1, b: -1 }, { unique: true } );
327+
},
328+
ops: [
329+
{ op: "insert",
330+
doc:
331+
{ a: { "#SEQ_INT":
332+
{ seq_id: 0, start: 0, step: 1, unique: true } },
333+
b: { "#SEQ_INT":
334+
{ seq_id: 0, start: 0, step: 1, unique: true } } } }
335+
] } );

testcases/simple_remove.js

+26
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,29 @@ tests.push( { name: "Remove.IntNonIdIndex",
7575
{ op: "insert",
7676
doc: { x : { "#VARIABLE" : "x" } } },
7777
] } );
78+
79+
/*
80+
* Setup: Populate a collection with an integer field of unique values
81+
* Create a unique index on the integer field
82+
* Test: Each thread works in a range of 100 documents; remove (and re-insert)
83+
* a random document in its range based on the indexed integer field
84+
*/
85+
tests.push( { name: "Remove.IntNonIdUniqueIndex",
86+
tags: ['remove','uniqueidx','regression'],
87+
pre: function( collection ) {
88+
collection.drop();
89+
var docs = [];
90+
for ( var i = 0; i < 4800; i++ ) {
91+
docs.push( { x : i } );
92+
}
93+
collection.insert(docs);
94+
collection.getDB().getLastError();
95+
collection.ensureIndex( { x : 1 }, { unique: true } );
96+
},
97+
ops: [
98+
{ op: "let", target: "x", value: {"#RAND_INT_PLUS_THREAD": [0,100]}},
99+
{ op: "remove",
100+
query: { x : { "#VARIABLE" : "x" } } },
101+
{ op: "insert",
102+
doc: { x : { "#VARIABLE" : "x" } } },
103+
] } );

testcases/simple_update.js

+49
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,52 @@ tests.push( { name: "Update.MatchedElementWithinArray",
407407
}}
408408
},
409409
] } );
410+
411+
/**
412+
* Setup: Populate a collection with an integer field X set to 0 and an
413+
* incrementing integer field A. Create a unique index on A.
414+
* Test: Each thread works in a range of 100 documents; randomly selects a
415+
* document using field A and increments X.
416+
*/
417+
tests.push( { name: "Update.UniqueIndex",
418+
tags: ['update','uniqueidx','regression'],
419+
pre: function( collection ) {
420+
collection.drop();
421+
var docs = [];
422+
for ( var i = 0; i < 4800; i++ ) {
423+
docs.push( { a : i, x : 0 } );
424+
}
425+
collection.insert(docs);
426+
collection.getDB().getLastError();
427+
collection.ensureIndex( { a: 1 }, { unique: true } );
428+
},
429+
ops: [
430+
{ op: "update",
431+
query: { a : { "#RAND_INT_PLUS_THREAD" : [ 0, 100 ] } },
432+
update: { $inc : { x : 1 } } },
433+
] } );
434+
435+
/**
436+
* Setup: Populate a collection with an integer field X set to 0 and two
437+
* incrementing integer fields A, B. Create a unique compound index on
438+
* fields A and B, with reverse ordering for A than B.
439+
* Test: Each thread works in a range of 100 documents; randomly selects a
440+
* document using field A and increments X.
441+
*/
442+
tests.push( { name: "Update.UniqueIndexCompoundReverse",
443+
tags: ['update','uniqueidx','regression'],
444+
pre: function( collection ) {
445+
collection.drop();
446+
var docs = [];
447+
for ( var i = 0; i < 4800; i++ ) {
448+
docs.push( { a : i, b : i, x : 0 } );
449+
}
450+
collection.insert(docs);
451+
collection.getDB().getLastError();
452+
collection.ensureIndex( { a: -1, b: 1 }, { unique: true } );
453+
},
454+
ops: [
455+
{ op: "update",
456+
query: { a : { "#RAND_INT_PLUS_THREAD" : [ 0, 100 ] } },
457+
update: { $inc : { x : 1 } } },
458+
] } );

0 commit comments

Comments
 (0)