forked from mongodb/mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexp.js
58 lines (49 loc) · 1.42 KB
/
indexp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Check recording and playback of good query plans with different index types SERVER-958.
t = db.jstests_indexp;
t.drop();
function expectRecordedPlan( query, idx ) {
assert.eq( "BtreeCursor " + idx, t.find( query ).explain( true ).oldPlan.cursor );
}
function expectNoRecordedPlan( query ) {
assert.isnull( t.find( query ).explain( true ).oldPlan );
}
// Basic test
t.drop();
t.ensureIndex( {a:1} );
t.save( {a:1} );
t.find( {a:1} ).itcount();
expectRecordedPlan( {a:1}, "a_1" );
// Index type changes
t.drop();
t.ensureIndex( {a:1} );
t.save( {a:1} );
t.find( {a:1} ).itcount();
t.save( {a:[1,2]} );
expectRecordedPlan( {a:1}, "a_1" );
// Multi key QueryPattern reuses index
t.drop();
t.ensureIndex( {a:1} );
t.save( {a:[1,2]} );
t.find( {a:{$gt:0}} ).itcount();
expectRecordedPlan( {a:{$gt:0,$lt:5}}, "a_1" );
// Single key QueryPattern can still be used to find best plan - at least for now.
t.drop();
t.ensureIndex( {a:1} );
t.save( {a:1} );
t.find( {a:{$gt:0,$lt:5}} ).itcount();
t.save( {a:[1,2]} );
expectRecordedPlan( {a:{$gt:0,$lt:5}}, "a_1" );
// Invalid query with only valid fields used
if ( 0 ) { // SERVER-2864
t.drop();
t.ensureIndex( {a:1} );
t.save( {a:1} );
t.find( {a:1,b:{$gt:5,$lt:0}} ).itcount();
expectRecordedPlan( {a:{$gt:0,$lt:5}}, "a_1" );
}
// Dummy query plan not stored
t.drop();
t.ensureIndex( {a:1} );
t.save( {a:1} );
t.find( {a:{$gt:5,$lt:0}} ).itcount();
expectNoRecordedPlan( {a:{$gt:5,$lt:0}} );