[SERVER-68596] [CQF] A SargableNode should be generated for an $elemMatch on a complex path Created: 05/Aug/22  Updated: 29/Oct/23  Resolved: 27/Oct/22

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

Type: Bug Priority: Major - P3
Reporter: Alya Berciu Assignee: David Percy
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-69025 [CQF] Performance-only partial schema... Closed
is depended on by SERVER-70511 Estimate PathObj intervals in Sargabl... Closed
Duplicate
is duplicated by SERVER-69024 [CQF] Handling of traverse with more ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QO 2022-10-03, QO 2022-10-17, QO 2022-10-31
Participants:

 Description   

The following predicate should generate a Sargable node after optimization:

{"a.histogram.path": {$elemMatch: {$eq: 42}}} 

However, this is the generated ABT:

Root []                                 
|   |   projections:                              
|   |       scan_0                                 
|   RefBlock:                                     
|       Variable [scan_0]                                            
Filter []                                          
|   EvalFilter []
|   |   Variable [scan_0]
|   PathGet [a]
|   PathTraverse [1]
|   PathGet [histogram]
|   PathTraverse [1]
|   PathGet [path]
|   PathComposeM []
|   |   PathArr []
|   PathTraverse [1]
|   PathCompare [Eq]
|   Const [42]
Scan [test]
    BindBlock:
        [scan_0]
            Source [] 

 

 



 Comments   
Comment by Githook User [ 26/Oct/22 ]

Author:

{'name': 'David Percy', 'email': 'david.percy@mongodb.com', 'username': 'dpercy'}

Message: SERVER-68596 [CQF] Convert dotted $elemMatch to SargableNode

The main change is to allow paths like Traverse (ComposeM ...) to
be Sargable. We add a Traverse to each conjunct as if the original
path were ComposeM (Traverse ...) (Traverse ...). This is an over-
approximation so we mark it perf-only and keep the original predicate.

A separate but related improvement: we now make use of more precise
index metadata to remove Traverse nodes. An index on a dotted path
such as

{'a.b': 1}

may have metadata telling us that 'b' is never
an array, even if 'a' is multikey.

Also, slightly improve lowerPartialSchemaRequirement's ability to
turn ranges back into PathArr / PathObj. This rewrite belongs in the
PartialSchemaReqLowerTransport so that we recognize these intervals
no matter where they occur in the BoolExpr.
Branch: master
https://github.com/mongodb/mongo/commit/136d831a284a5aa7277839c390588ff8f20ab179

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