Details
-
New Feature
-
Resolution: Fixed
-
Major - P3
-
None
-
None
-
None
-
Fully Compatible
-
178
Description
Implement the appropriate query rewrite the 2 remaining cases with {+-meta, +ts}. Assuming that we extend the indexes to both (min,max) and (max,min) the rewrites become:
For reference, here's the case we already did in Milestone :2
index({meta.sensorId: 1, meta.sensorId: -1})
|
|
|
db.telemetry.aggregate([
|
{$sort: {"metadata.sensorId": 1, "timestamp": -1}},
|
{$group: {
|
_id: "$metadata.sensorId",
|
ts: {$first: "$timestamp"},
|
temp: {$first: "$temp"}
|
}}
|
])
|
translates to:
db.system.buckets.telemetry.explain("executionStats").aggregate([
|
{$sort: {"meta.sensorId": 1, "control.max.timestamp": -1}},
|
{$group: {
|
_id: "$meta.sensorId",
|
bucket: {$first: "$_id"},
|
}},
|
{$lookup: {
|
from: "system.buckets.telemetry",
|
foreignField: "_id",
|
localField: "bucket",
|
as: "bucket_data",
|
pipeline:[
|
{$_internalUnpackBucket: {
|
timeField:"timestamp",
|
metaField:"tags",
|
bucketMaxSpanSeconds:NumberInt("60")
|
}},
|
{$sort: {"timestamp": -1}},
|
{$limit:1}
|
]
|
}},
|
{$unwind: "$bucket_data"},
|
{$replaceWith:{
|
_id: "$_id",
|
timestamp: "$bucket_data.timestamp",
|
temp: "$bucket_data.temp"
|
}}
|
]);
|
This is adapted as follows:
| milestone | user index | $sort | $group accumulator |
|---|---|---|---|
| 2 (done) | {meta:1, ts:-1} | {meta:1, control.max.timestamp:-1} | $first |
| 3 | {meta:-1, ts:-1} | {meta:-1, control.max.timestamp:-1} | $first |
| 3 | {meta:1, ts:1} | {meta:1, control.max.timestamp:1} | $last |
| 3 | {meta:-1, ts:1} | {meta:-1, control.max.timestamp:1} | $last |
This tickets covers the last two rows above.
Attachments
Issue Links
- related to
-
SERVER-61657 Last point TS Opt M3: Query rewrite for {meta: -1, ts: -1} case
-
- Closed
-