Skip to content

Instantly share code, notes, and snippets.

@FranckPachot
Created March 4, 2026 23:39
Show Gist options
  • Select an option

  • Save FranckPachot/00d5c272226935cb3d77489d84d95437 to your computer and use it in GitHub Desktop.

Select an option

Save FranckPachot/00d5c272226935cb3d77489d84d95437 to your computer and use it in GitHub Desktop.
db.test.drop();
db.test.createIndex({A:1, B:1})
const letters = "abcdefghijklmnopqrstuvwxyz".split("");
const total=0; for (let i = 0; i < 1000; i++) {
const result = db.test.insertMany(
Array.from({ length: 10000 }, () => ({
A: Math.floor(Math.random() * 5) + 1,
B: letters[Math.floor(Math.random() * letters.length)]
}))
);
total=total+Object.keys(result.insertedIds).length;
print(`Total: ${total/1e6} million`);
}
db.test.find({
A: { $gte: 1, $lte: 3 },
B: { $in: ["x", "y", "z"] }
},{A:1, B:1, _id:0}
).explain("executionStats").executionStats.executionStages.inputStage
;
{
stage: 'IXSCAN',
nReturned: 692735,
executionTimeMillisEstimate: 340,
works: 692738,
advanced: 692735,
needTime: 2,
needYield: 0,
saveState: 29,
restoreState: 29,
isEOF: 1,
keyPattern: { A: 1, B: 1 },
indexName: 'A_1_B_1',
isMultiKey: false,
multiKeyPaths: { A: [], B: [] },
isUnique: false,
isSparse: false,
isPartial: false,
indexVersion: 2,
direction: 'forward',
indexBounds: { A: [ '[1, 3]' ], B: [ '["x", "x"]', '["y", "y"]', '["z", "z"]' ] },
keysExamined: 692738,
seeks: 3,
dupsTested: 0,
dupsDropped: 0
}
db.test.find({
A: { $in: [1, 2, 3] },
B: { $in: ["x", "y", "z"] }
},{A:1, B:1, _id:0}
).explain("executionStats").executionStats.executionStages.inputStage
{
stage: 'IXSCAN',
nReturned: 692735,
executionTimeMillisEstimate: 371,
works: 692738,
advanced: 692735,
needTime: 2,
needYield: 0,
saveState: 25,
restoreState: 25,
isEOF: 1,
keyPattern: { A: 1, B: 1 },
indexName: 'A_1_B_1',
isMultiKey: false,
multiKeyPaths: { A: [], B: [] },
isUnique: false,
isSparse: false,
isPartial: false,
indexVersion: 2,
direction: 'forward',
indexBounds: {
A: [ '[1, 1]', '[2, 2]', '[3, 3]' ],
B: [ '["x", "x"]', '["y", "y"]', '["z", "z"]' ]
},
keysExamined: 692738,
seeks: 3,
dupsTested: 0,
dupsDropped: 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment