[SERVER-47223] geoNear/$geoNear does not apply index hints Created: 01/Apr/20 Updated: 29/Oct/23 Resolved: 22/Jun/20 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework, Querying |
| Affects Version/s: | 4.2.3, 4.0.17 |
| Fix Version/s: | 4.0.20, 4.4.0-rc11, 4.2.9, 4.7.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Alex Bevilacqua | Assignee: | Mihai Andrei |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||
| Operating System: | ALL | ||||||||
| Backport Requested: |
v4.4, v4.2, v4.0
|
||||||||
| Sprint: | Query 2020-04-20, Query 2020-05-04, Query 2020-05-18, Query 2020-06-01, Query 2020-06-15, Query 2020-06-29 | ||||||||
| Participants: | |||||||||
| Description |
|
Prior to MongoDB 4.2 (4.1.1 specifically) the $geoNear aggregation stage was internally issuing a geoNear command through the MongoDB 4.0.17
Given the two log lines shared you can see that the initial geoNear command has chosen a different index than what was hinted to the pipeline. This appears to be due to how the call from DocumentSourceGeoNear::runCommand() is building the command (see DocumentSourceGeoNear::buildGeoNearCmd()). The underlying geoNear command does not appear to take the hint from the pipeline when it is constructed so the query planner has to decide which index to use. This bug affects the geoNear command as well when it is invoked directly. MongoDB 4.2.5
Even once the geoNear command is no longer in use (MongoDB 4.2) the pipeline stage still discards the hint (it is not logged either). Note that this behavior can be reproduced as follows:
|
| Comments |
| Comment by Githook User [ 25/Jun/20 ] |
|
Author: {'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}Message: (cherry picked from commit e1d82874e90ed0cb7fd6898edc54d47c1a42b97c) |
| Comment by Githook User [ 22/Jun/20 ] |
|
Author: {'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}Message: (cherry picked from commit e1d82874e90ed0cb7fd6898edc54d47c1a42b97c) |
| Comment by Githook User [ 22/Jun/20 ] |
|
Author: {'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}Message: (cherry picked from commit e1d82874e90ed0cb7fd6898edc54d47c1a42b97c) |
| Comment by Githook User [ 22/Jun/20 ] |
|
Author: {'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}Message: |
| Comment by Justin Seyster [ 01/Apr/20 ] |
|
Yes, definitely a bug, and one that probably affects master. Actually, it looks like it's three distinct bugs. In 4.0, a $geoNear DocumentSource operates by dispatching a geoNear command, but it neglects to forward its hint. Furthermore, the geoNear command- Unfortunately, that new code path also seems to have an error (that we have not yet diagnosed) that prevents it from using its hint, meaning that this bug also affects 4.2 and probably 4.4 and master as well. We will probably want to schedule this for 4.5 and backport to 4.4 and 4.2. If we wanted to correct this behavior on 4.0, we would need to write a new fix. |
| Comment by Asya Kamsky [ 01/Apr/20 ] |
|
Isn’t it a bug that we discard incompatible hint? Generally we either use the index hinted or error. |