(function() {
|
|
"use strict";
|
|
load("jstests/libs/sbe_util.js"); // For 'checkSBEEnabled()'.
|
load("jstests/libs/analyze_plan.js"); // For 'getAggPlanStages()' and 'hasRejectedPlans()'
|
|
const JoinAlgorithm = {
|
Classic: 0,
|
NLJ: 1,
|
INLJ: 2,
|
};
|
|
///////////// Parameters
|
const enableSBE = true;
|
let joinAlgo = JoinAlgorithm.INLJ
|
|
///////////// Implementation
|
let dbName = 'explain_test';
|
|
const conn = MongoRunner.runMongod(enableSBE ? {
|
setParameter: {featureFlagSBELookupPushdown: true, featureFlagSBELookupPushdownIndexJoin: true}
|
} : {});
|
|
try{
|
|
assert.neq(null, conn, "mongod was unable to start up");
|
|
var db = conn.getDB(dbName);
|
assert.commandWorked(db.dropDatabase());
|
db = conn.getDB(dbName);
|
|
if (enableSBE && !checkSBEEnabled(db, ["featureFlagSBELookupPushdown"])) {
|
jsTestLog("Skipping test because either the sbe lookup pushdown feature flag is disabled or" +
|
" sbe itself is disabled");
|
MongoRunner.stopMongod(conn);
|
return;
|
}
|
|
assert.commandWorked(db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: !enableSBE}));
|
|
db.orders.insertMany( [
|
{ "_id" : 1, "item" : "almonds", "price" : 12, "quantity" : 2 },
|
{ "_id" : 2, "item" : "pecans", "price" : 20, "quantity" : 1 },
|
{ "_id" : 4, "item" : "almonds", "price" : 14, "quantity" : 2 },
|
{ "_id" : 5, "item" : "pecans", "price" : 22, "quantity" : 1 },
|
{ "_id" : 6, "item" : "cashews", "price" : 24, "quantity" : 1 },
|
] );
|
|
db.inventory.insertMany( [
|
{ "_id" : 1, "sku" : "almonds", "description": "product 1", "instock" : 120 },
|
{ "_id" : 2, "sku" : "bread", "description": "product 2", "instock" : 80 },
|
{ "_id" : 3, "sku" : "cashews", "description": "product 3", "instock" : 60 },
|
{ "_id" : 4, "sku" : "pecans", "description": "product 4", "instock" : 70 },
|
{ "_id" : 5, "sku": "nuts", "description": "Incomplete" },
|
{ "_id" : 6 }
|
] )
|
|
assert.commandWorked(db.inventory.dropIndexes());
|
if(joinAlgo == JoinAlgorithm.NLJ) {
|
assert.commandWorked(db.inventory.createIndex({'$**': 1}));
|
} else if(joinAlgo == JoinAlgorithm.INLJ) {
|
assert.commandWorked(db.inventory.createIndex({'sku': 1}));
|
} else {
|
// no index
|
}
|
|
let lookupExpRes = db.orders.explain('executionStats')
|
.aggregate( [
|
{
|
$lookup:
|
{
|
from: "inventory",
|
localField: "item",
|
foreignField: "sku",
|
as: "inventory_docs"
|
}
|
}
|
] );
|
|
function flip(dict){
|
var ret = {};
|
for(var key in dict){
|
ret[dict[key]] = key;
|
}
|
return ret;
|
}
|
|
print("lookupExpRes (with SBE: " + (enableSBE?"enabled":"disabled") + " and joinAlgo: " + flip(JoinAlgorithm)[joinAlgo] + "):");
|
printjson(lookupExpRes);
|
|
} finally {
|
MongoRunner.stopMongod(conn);
|
}
|
|
print("Finished.");
|
|
}());
|