@@ -123,6 +123,7 @@ function ahuacatlShardIdsOptimizationTestSuite() {
123
123
const shardKey = "value" ;
124
124
const shardKey1 = "value" ;
125
125
const shardKey2 = "value" ;
126
+ const extraKey = "extra" ;
126
127
const numberOfShards = 9 ;
127
128
128
129
const tearDown = ( ) => {
@@ -182,7 +183,7 @@ function ahuacatlShardIdsOptimizationTestSuite() {
182
183
let docs = [ ] ;
183
184
184
185
for ( let i = 0 ; i < 100 ; ++ i ) {
185
- docs . push ( { "value" : i % 25 , "joinValue" : i % 5 } ) ;
186
+ docs . push ( { "value" : i % 25 , "joinValue" : i % 5 , "extra" : true } ) ;
186
187
}
187
188
188
189
collection . save ( docs ) ;
@@ -428,6 +429,90 @@ function ahuacatlShardIdsOptimizationTestSuite() {
428
429
}
429
430
} ,
430
431
432
+ testMultipleKeysSameFilter : function ( ) {
433
+ dropIndexes ( collectionByKey ) ;
434
+ collectionByKey . ensureHashIndex ( shardKey ) ;
435
+
436
+ for ( let i = 0 ; i < 24 ; ++ i ) {
437
+ const query = `
438
+ FOR doc IN ${ cnKey }
439
+ FILTER doc.${ shardKey } == ${ i } && doc.${ extraKey } == true
440
+ RETURN doc
441
+ ` ;
442
+ validatePlan ( query , "IndexNode" , collectionByKey ) ;
443
+
444
+ let res = db . _query ( query , { } , disableSingleDocOp ) . toArray ( ) ;
445
+ assertEqual ( 4 , res . length ) ;
446
+ for ( let doc of res ) {
447
+ assertTrue ( i === doc . value ) ;
448
+ assertTrue ( true === doc . extra ) ;
449
+ }
450
+ }
451
+ } ,
452
+
453
+ testMultipleKeysSameFilterNoIndex : function ( ) {
454
+ dropIndexes ( collectionByKey ) ;
455
+
456
+ for ( let i = 0 ; i < 24 ; ++ i ) {
457
+ const query = `
458
+ FOR doc IN ${ cnKey }
459
+ FILTER doc.${ shardKey } == ${ i } && doc.${ extraKey } == true
460
+ RETURN doc
461
+ ` ;
462
+ validatePlan ( query , "EnumerateCollectionNode" , collectionByKey ) ;
463
+
464
+ let res = db . _query ( query , { } , disableSingleDocOp ) . toArray ( ) ;
465
+ assertEqual ( 4 , res . length ) ;
466
+ for ( let doc of res ) {
467
+ assertTrue ( i === doc . value ) ;
468
+ assertTrue ( true === doc . extra ) ;
469
+ }
470
+ }
471
+ } ,
472
+
473
+ testMultipleKeysDifferentFilter : function ( ) {
474
+ dropIndexes ( collectionByKey ) ;
475
+ collectionByKey . ensureHashIndex ( shardKey ) ;
476
+
477
+ for ( let i = 0 ; i < 24 ; ++ i ) {
478
+ const query = `
479
+ FOR doc IN ${ cnKey }
480
+ FILTER doc.${ shardKey } == ${ i }
481
+ FILTER doc.${ extraKey } == true
482
+ RETURN doc
483
+ ` ;
484
+ validatePlan ( query , "IndexNode" , collectionByKey ) ;
485
+
486
+ let res = db . _query ( query , { } , disableSingleDocOp ) . toArray ( ) ;
487
+ assertEqual ( 4 , res . length ) ;
488
+ for ( let doc of res ) {
489
+ assertTrue ( i === doc . value ) ;
490
+ assertTrue ( true === doc . extra ) ;
491
+ }
492
+ }
493
+ } ,
494
+
495
+ testMultipleKeysDifferentFilterNoIndex : function ( ) {
496
+ dropIndexes ( collectionByKey ) ;
497
+
498
+ for ( let i = 0 ; i < 24 ; ++ i ) {
499
+ const query = `
500
+ FOR doc IN ${ cnKey }
501
+ FILTER doc.${ shardKey } == ${ i }
502
+ FILTER doc.${ extraKey } == true
503
+ RETURN doc
504
+ ` ;
505
+ validatePlan ( query , "EnumerateCollectionNode" , collectionByKey ) ;
506
+
507
+ let res = db . _query ( query , { } , disableSingleDocOp ) . toArray ( ) ;
508
+ assertEqual ( 4 , res . length ) ;
509
+ for ( let doc of res ) {
510
+ assertTrue ( i === doc . value ) ;
511
+ assertTrue ( true === doc . extra ) ;
512
+ }
513
+ }
514
+ } ,
515
+
431
516
testMultipleShardsOr : function ( ) {
432
517
dropIndexes ( collectionByKey ) ;
433
518
collectionByKey . ensureHashIndex ( shardKey ) ;
0 commit comments