@@ -2,6 +2,8 @@ if (typeof(tests) !== "object") {
2
2
tests = [ ] ;
3
3
}
4
4
5
+ Random . setRandomSeed ( 258 ) ;
6
+
5
7
/**
6
8
* Sets up a collection and/or a view with the appropriate documents and indexes.
7
9
*
@@ -422,53 +424,110 @@ addTestCase({
422
424
} ) ;
423
425
424
426
/**
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.
427
428
*/
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 ) ;
431
438
}
432
439
433
440
/**
434
441
* 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 ).
436
443
*
437
444
* Test: Issue queries that must perform a collection scan, filtering the documents with an $in
438
445
* 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
439
503
* array contains all even integers in the range [0, 2000).
440
504
*/
441
505
addTestCase ( {
442
- name : "UnindexedLargeInMatching " ,
506
+ name : "UnindexedLargeInNonMatching " ,
443
507
tags : [ "regression" ] ,
444
508
nDocs : 10 ,
445
509
docs : function ( i ) {
446
- return { x : 2 * Random . randInt ( 1000 ) } ;
510
+ return { x : 2 * Random . randInt ( 1000 ) + 1 } ;
447
511
} ,
448
512
op : {
449
513
op : "find" ,
450
- query : { x : { $in : largeArray } }
514
+ query : { x : { $in : largeArraySorted } }
451
515
}
452
516
} ) ;
453
517
454
518
/**
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.
461
520
*/
462
521
addTestCase ( {
463
- name : "UnindexedLargeInNonMatching " ,
522
+ name : "UnindexedLargeInUnsortedNonMatching " ,
464
523
tags : [ "regression" ] ,
465
524
nDocs : 10 ,
466
525
docs : function ( i ) {
467
526
return { x : 2 * Random . randInt ( 1000 ) + 1 } ;
468
527
} ,
469
528
op : {
470
529
op : "find" ,
471
- query : { x : { $in : largeArray } }
530
+ query : { x : { $in : largeArrayRandom } }
472
531
}
473
532
} ) ;
474
533
0 commit comments