From 2273889eebfcda349c1aa9d444bbf442b88feff6 Mon Sep 17 00:00:00 2001 From: Alberto Massari Date: Tue, 6 Feb 2024 21:30:13 +0100 Subject: [PATCH] SERVER-86224 Preserve bitmap slot when clearing non-requested fields (#18714) GitOrigin-RevId: 8f6c489e72b413b3daaee5bec56c5dfb345262b9 --- .../core/timeseries/timeseries_computed_field.js | 14 ++++++++++++++ src/mongo/db/query/sbe_stage_builder.cpp | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/jstests/core/timeseries/timeseries_computed_field.js b/jstests/core/timeseries/timeseries_computed_field.js index 3eabc3ef966f6..18275ddadba2d 100644 --- a/jstests/core/timeseries/timeseries_computed_field.js +++ b/jstests/core/timeseries/timeseries_computed_field.js @@ -331,6 +331,20 @@ TimeseriesTest.run((insert) => { assert.eq(res[2], {"obj": {}}, res); } + { + // Try a replaceRoot stage which remove all fields. + const res = coll.aggregate([ + {$match: {"time": {$gte: new Date(datePrefix + 200)}}}, + {$addFields: {}}, + {$project: {"measurement0": {$floor: "$topLevelScalar"}}}, + {$replaceRoot: {newRoot: {}}} + ]) + .toArray(); + assert.eq(res.length, 2, res); + assert.eq(res[0], {}, res); + assert.eq(res[1], {}, res); + } + { const res = coll.aggregate([{ "$project": { diff --git a/src/mongo/db/query/sbe_stage_builder.cpp b/src/mongo/db/query/sbe_stage_builder.cpp index d5b193a77972d..a8858cc59a11b 100644 --- a/src/mongo/db/query/sbe_stage_builder.cpp +++ b/src/mongo/db/query/sbe_stage_builder.cpp @@ -496,6 +496,12 @@ std::vector PlanStageSlots::getRequiredNamesInOrd std::vector names(reqs._data->slotNameSet.begin(), reqs._data->slotNameSet.end()); + // Always treat as required, if it present, the slot holding the bitmap with the filtered items + // of block values. + if (has(kBlockSelectivityBitmap)) { + names.emplace_back(kBlockSelectivityBitmap); + } + // If this PlanStageSlots has ResultInfo and 'reqs.hasResult()' is true, then we need // to get the list of changed fields and add them to 'names'. if (reqs.hasResult() && hasResultInfo()) {