[SERVER-40810] Optimized $group/DISTINCT_SCAN does not respect hint Created: 24/Apr/19  Updated: 29/Oct/23  Resolved: 11/Jun/19

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 4.1.10
Fix Version/s: 4.2.0-rc3, 4.3.1

Type: Bug Priority: Major - P3
Reporter: Ian Boros Assignee: Mikhail Ivkov (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
related to SERVER-41458 $natural hint overrides index filters Closed
related to SERVER-14227 add index hint support for distinct c... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.2
Sprint: Query 2019-06-17
Participants:

 Description   

> db.c.createIndex({a:1})
> db.c.insert({a:1})
WriteResult({ "nInserted" : 1 })
> db.c.aggregate({$group: {_id: "$a"}})
{ "_id" : 1 }
> db.c.explain().aggregate({$group: {_id: "$a"}})
// Distinct scan!
> db.c.explain().aggregate([{$group: {_id: "$a"}}], {hint: {$natural: 1}})
// Still distinct scan

This is probably because of the special codepath here which doesn't consider the hint.



 Comments   
Comment by Githook User [ 01/Jul/19 ]

Author:

{'name': 'Misha Ivkov', 'email': 'misha.ivkov@10gen.com'}

Message: SERVER-40810 give precedence index filter > hint > index on DISTINCT_SCAN

(cherry picked from commit 95975c0e9c725ef86ef2fe6a8f5372e8a3f219d3)
Branch: v4.2
https://github.com/mongodb/mongo/commit/9f53a6359f72bd3b21fdeb29267a775e9c3e976a

Comment by Githook User [ 11/Jun/19 ]

Author:

{'name': 'Misha Ivkov', 'email': 'misha.ivkov@10gen.com'}

Message: SERVER-40810 give precedence index filter > hint > index on DISTINCT_SCAN
Branch: master
https://github.com/mongodb/mongo/commit/95975c0e9c725ef86ef2fe6a8f5372e8a3f219d3

Comment by Asya Kamsky [ 03/Jun/19 ]

It ignores all hints, not just $natural, so hinting "_id" index also gets ignored.

Generated at Thu Feb 08 04:56:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.