Skip to content

Commit d6fa261

Browse files
author
dalyd
committed
Merge branch 'develop'
2 parents 6140701 + d209c50 commit d6fa261

File tree

1 file changed

+76
-17
lines changed

1 file changed

+76
-17
lines changed

testcases/simple_query.js

+76-17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ if (typeof(tests) !== "object") {
22
tests = [];
33
}
44

5+
Random.setRandomSeed(258);
6+
57
/**
68
* Sets up a collection and/or a view with the appropriate documents and indexes.
79
*
@@ -422,53 +424,110 @@ addTestCase({
422424
});
423425

424426
/**
425-
* Large array used for large $in queries in UnindexedLargeInMatching and
426-
* UnindexedLargeInNonMatching containing all even integers in the range [0, 2000).
427+
* Large arrays used for $in queries in the subsequent test cases.
427428
*/
428-
var largeArray = [];
429-
for (var i = 0; i < 1000; i++) {
430-
largeArray.push(i * 2);
429+
var nLargeArrayElements = 1000;
430+
var largeArrayRandom = [];
431+
for (var i = 0; i < nLargeArrayElements; i++) {
432+
largeArrayRandom.push(Random.randInt(nLargeArrayElements));
433+
}
434+
435+
var largeArraySorted = [];
436+
for (var i = 0; i < nLargeArrayElements; i++) {
437+
largeArraySorted.push(i * 2);
431438
}
432439

433440
/**
434441
* Setup: Create a collection and insert a small number of documents with a random even integer
435-
* field x in the range [0, 2000).
442+
* field x in the range [0, nLargeArrayElements * 2).
436443
*
437444
* Test: Issue queries that must perform a collection scan, filtering the documents with an $in
438445
* predicate with a large number of elements. All documents will match the predicate, since the $in
446+
* array contains all even integers in the range [0, nLargeArrayElements * 2).
447+
*/
448+
function addInTestCase({name, largeInArray}) {
449+
addTestCase({
450+
name: name,
451+
tags: ["regression"],
452+
nDocs: 10,
453+
docs: function(i) {
454+
return {x: 2 * Random.randInt(largeInArray.length)};
455+
},
456+
op: {
457+
op: "find",
458+
query: {x: {$in: largeInArray}}
459+
}
460+
});
461+
};
462+
463+
addInTestCase({
464+
name: "UnindexedLargeInMatching",
465+
largeInArray: largeArraySorted,
466+
});
467+
468+
addInTestCase({
469+
name: "UnindexedLargeInUnsortedMatching",
470+
largeInArray: largeArrayRandom,
471+
});
472+
473+
/**
474+
* Repeat the same test as above, increasing the number of elements in the $in array to 10000.
475+
*/
476+
var nVeryLargeArrayElements = 10000;
477+
var veryLargeArrayRandom = [];
478+
for (var i = 0; i < nVeryLargeArrayElements; i++) {
479+
veryLargeArrayRandom.push(Random.randInt(nVeryLargeArrayElements));
480+
}
481+
482+
var veryLargeArraySorted = [];
483+
for (var i = 0; i < nVeryLargeArrayElements; i++) {
484+
veryLargeArraySorted.push(i * 2);
485+
}
486+
487+
addInTestCase({
488+
name: "UnindexedVeryLargeInSortedMatching",
489+
largeInArray: veryLargeArraySorted,
490+
});
491+
492+
addInTestCase({
493+
name: "UnindexedVeryLargeInUnsortedMatching",
494+
largeInArray: veryLargeArrayRandom,
495+
});
496+
497+
/**
498+
* Setup: Create a collection and insert a small number of documents with a random odd integer
499+
* field x in the range [0, 2000).
500+
*
501+
* Test: Issue queries that must perform a collection scan, filtering the documents with an $in
502+
* predicate with a large number of elements. No documents will match the predicate, since the $in
439503
* array contains all even integers in the range [0, 2000).
440504
*/
441505
addTestCase({
442-
name: "UnindexedLargeInMatching",
506+
name: "UnindexedLargeInNonMatching",
443507
tags: ["regression"],
444508
nDocs: 10,
445509
docs: function(i) {
446-
return {x: 2 * Random.randInt(1000)};
510+
return {x: 2 * Random.randInt(1000) + 1};
447511
},
448512
op: {
449513
op: "find",
450-
query: {x: {$in: largeArray}}
514+
query: {x: {$in: largeArraySorted}}
451515
}
452516
});
453517

454518
/**
455-
* Setup: Create a collection and insert a small number of documents with a random odd integer
456-
* field x in the range [0, 2000).
457-
*
458-
* Test: Issue queries that must perform a collection scan, filtering the documents with an $in
459-
* predicate with a large number of elements. No documents will match the predicate, since the $in
460-
* array contains all even integers in the range [0, 2000).
519+
* Repeat the same test as above, except using the $in array of unsorted elements.
461520
*/
462521
addTestCase({
463-
name: "UnindexedLargeInNonMatching",
522+
name: "UnindexedLargeInUnsortedNonMatching",
464523
tags: ["regression"],
465524
nDocs: 10,
466525
docs: function(i) {
467526
return {x: 2 * Random.randInt(1000) + 1};
468527
},
469528
op: {
470529
op: "find",
471-
query: {x: {$in: largeArray}}
530+
query: {x: {$in: largeArrayRandom}}
472531
}
473532
});
474533

0 commit comments

Comments
 (0)