- 
    Type:Task 
- 
    Resolution: Fixed
- 
    Priority:Major - P3 
- 
    Affects Version/s: None
- 
    Component/s: None
- 
        Query Optimization
- 
        Fully Compatible
- 
        QO 2024-11-25, QO 2024-12-09, QO 2024-12-23
- 
        200
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
In `constructCoveredDistinctScan`, we construct a DISTINCT_SCAN plan by hand and then call `analyzeDataAccess` to finalize it. This seems risky, since we might end up constructing a distinct scan even when some properties of the index make it unsuitable for a DISTINCT_SCAN (we perform more checks in `turnIxScanIntoDistinctScan` than in `getDistinctNodeIndex`). A safer approach would be to construct an INDEX_SCAN on the desired index, let `analyzeDataAccess` convert it to a DISTINCT_SCAN, and return nullptr if plan couldn't be converted. If this approach leads to test failures, we should then update `getDistinctNodeIndex` accordingly.
Example query where this happens:
distinct("a", undefined) over [ { "a" : [ ] } ] with index { "a" : 1 }
- duplicates
- 
                    SERVER-97011 Add golden distinct tests on $group with non-shard-key _id -         
- Closed
 
-         
- is related to
- 
                    SERVER-97239 getUniqueResults() in pretty_md should unwind arrays -         
- Closed
 
-         
- related to
- 
                    SERVER-97238 $group with $first/$last to distinct scan optimization might incorrectly unwind arrays -         
- Closed
 
-