[SERVER-48993] explodeForSort can produce incorrect query plan Created: 19/Jun/20 Updated: 29/Oct/23 Resolved: 13/Jul/20 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 3.6.18, 4.0.19, 4.2.8, 4.4.0-rc10 |
| Fix Version/s: | 4.0.20, 4.2.9, 4.4.1, 3.6.20, 4.7.0 |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Mindaugas Malinauskas | Assignee: | Mindaugas Malinauskas |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | qexec-team | ||
| 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, v3.6
|
|||||||||||||||||||||||||||||||||||
| Steps To Reproduce: |
|
|||||||||||||||||||||||||||||||||||
| Sprint: | Query 2020-06-29, Query 2020-07-13, Query 2020-07-27 | |||||||||||||||||||||||||||||||||||
| Participants: | ||||||||||||||||||||||||||||||||||||
| Linked BF Score: | 8 | |||||||||||||||||||||||||||||||||||
| Description |
|
Given a compound index with a non-simple collation, a point-query on a prefix field together with a sort on a suffix field can result in a IXSCAN query plan that incorrectly sorts according to the collation. This issue has existed at least since version 3.6. The attached reproduction script describes the problem. A query which does not specify a collation (or which explicitly specifies a different collation) may still use an index which has a non-matching collation if the query predicates are non-string values. We then call QueryPlannerAnalysis::analyzeSort to determine whether we need to perform an in-memory sort. As part of this process we call QueryPlannerAnalysis::explodeForSort to see whether the plan can be rewritten as a SORT_MERGE. Unfortunately, this method does not enforce the constraint that an index with a different collation than the query cannot provide a sort. Incorrect execution plan example:
Incorrect output example. Note that the results are sorted on case-insensitive value of field "b".
|
| Comments |
| Comment by Githook User [ 07/Aug/20 ] |
|
Author: {'name': 'Mindaugas Malinauskas', 'email': 'mindaugas.malinauskas@mongodb.com'}Message: (cherry picked from commit 7dd37622622362d0ef689b91de565c8c053c838e) |
| Comment by Githook User [ 07/Aug/20 ] |
|
Author: {'name': 'Justin Seyster', 'email': 'justin.seyster@mongodb.com', 'username': 'jseyster'}Message: |
| Comment by Githook User [ 07/Aug/20 ] |
|
Author: {'name': 'Mindaugas Malinauskas', 'email': 'mindaugas.malinauskas@mongodb.com'}Message: (cherry picked from commit 7dd37622622362d0ef689b91de565c8c053c838e) |
| Comment by Githook User [ 04/Aug/20 ] |
|
Author: {'name': 'Mindaugas Malinauskas', 'email': 'mindaugas.malinauskas@mongodb.com'}Message: (cherry picked from commit 7dd37622622362d0ef689b91de565c8c053c838e) |
| Comment by Githook User [ 04/Aug/20 ] |
|
Author: {'name': 'Mindaugas Malinauskas', 'email': 'mindaugas.malinauskas@mongodb.com'}Message: |
| Comment by Githook User [ 13/Jul/20 ] |
|
Author: {'name': 'Mindaugas Malinauskas', 'email': 'mindaugas.malinauskas@mongodb.com'}Message: |