[SERVER-84207] Comparisons on timeField in time-series could sometimes be optimized away Created: 14/Dec/23  Updated: 03/Feb/24  Resolved: 03/Feb/24

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Irina Yatsenko (Inactive) Assignee: Backlog - Query Integration
Resolution: Won't Do Votes: 0
Labels: qi-timeseries
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-86196 Complete TODO listed in SERVER-84207 Needs Scheduling
Assigned Teams:
Query Integration
Participants:

 Description   

The time field is required to be present and be of type Date. Comparisons on the time field that use non-Date types for the constant would be either trivially false (e.g. in the case of type-bracketing) or trivially true (in some cases without type-bracketing).

Currently, we don't optimize such comparisons out and always create $_internalUnpackBucket stage with an eventFilter:

> db.ts.explain().find({t: 42}) // "t" is the timeField in this collection
{
        "explainVersion" : "1",
        "stages" : [
                {
                        "$cursor" : {
                                "queryPlanner" : {
                                        "namespace" : "my.system.buckets.ts",
                                        "indexFilterSet" : false,
                                        "parsedQuery" : {
 
                                        },
                                        "queryHash" : "FCBE9F38",
                                        "planCacheKey" : "64E90EFC",
                                        "maxIndexedOrSolutionsReached" : false,
                                        "maxIndexedAndSolutionsReached" : false,
                                        "maxScansToExplodeReached" : false,
                                        "winningPlan" : {
                                                "stage" : "COLLSCAN",
                                                "direction" : "forward"
                                        },
                                        "rejectedPlans" : [ ]
                                }
                        }
                },
                {
                        "$_internalUnpackBucket" : {
                                "exclude" : [ ],
                                "timeField" : "t",
                                "metaField" : "m",
                                "bucketMaxSpanSeconds" : 3600,
                                "assumeNoMixedSchemaData" : true,
                                "eventFilter" : {
                                        "t" : {
                                                "$eq" : 42
                                        }
                                }
                        }
                }
        ],


Generated at Thu Feb 08 06:54:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.