Files
mongo/jstests/aggregation/sources/setWindowFields/avoid_express_path.js
Ted Tuckman 50f2f21b74 SERVER-105665 Prevent queries that need metadata from taking the express path (#36956)
GitOrigin-RevId: 2cb34afd4b387e07dd69b5106f26711c062bca8b
2025-06-20 15:35:19 +00:00

33 lines
989 B
JavaScript

/**
* Test that when $setWindowFields requires metadata, it does not take the express path
* even if the desugared query would otherwise be eligible.
* @tags: [requires_fcv_82]
*/
import {getQueryPlanner, planHasStage} from "jstests/libs/query/analyze_plan.js";
const coll = db[jsTestName()];
coll.drop();
const documents = [{
_id: 31,
date: 2,
}];
assert.commandWorked(coll.insert(documents));
// We need a sort key, but the point _id query would normally take the express path.
let q = [
{"$match": {"_id": 31}},
{
"$setWindowFields":
{"sortBy": {"date": 1}, "partitionBy": "$array", "output": {"x": {"$denseRank": {}}}}
}
];
// This query should return one successfully ranked document.
let result = coll.aggregate(q).toArray();
assert.eq(result, [{_id: 31, date: 2, x: 1}]);
let explain = coll.explain().aggregate(q);
let planner = getQueryPlanner(explain);
assert(planHasStage(db, planner.winningPlan, "SORT_KEY_GENERATOR"), planner);