[SERVER-43816] Push $text and $sort with $meta in the sort pattern into the PlanStage layer Created: 03/Oct/19 Updated: 29/Oct/23 Resolved: 18/Dec/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework, Querying |
| Affects Version/s: | None |
| Fix Version/s: | 4.3.3 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | David Storch | Assignee: | David Storch |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Backwards Compatibility: | Minor Change | ||||||||||||||||||||||||||||
| Sprint: | Query 2019-12-16, Query 2019-12-30 | ||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||
| Description |
|
When a $sort stage is at the beginning of the pipeline, or close to the beginning, the aggregation subsystem attempts to execute it using the underlying PlanStage query execution tree. We are trying to push increasingly more execution into the PlanStage layer in order to move towards having a single, unified execution engine which will be easier to extend and maintain. There is a special case where we don't push down $sort if it has "textScore" or "randVal" $meta expressions: see https://github.com/mongodb/mongo/blob/8ccaacce937ae51deef27c41e977aca0511fb338/src/mongo/db/pipeline/pipeline_d.cpp#L102-L120. For "textScore", this restriction stems from the fact that the find and agg systems have different validity rules for $meta sort by text score. The agg subsystem permits $meta:textScore with no matching $meta projection:
The find subsystem, on the other hand, requires a matching "textScore" $meta projection:
We should eliminate this restriction, which would allow us to always push down "textScore" $meta sort. The situation for "randVal" needs some investigation, but note |
| Comments |
| Comment by Githook User [ 18/Dec/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}Message: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by David Storch [ 18/Dec/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Included in the changes for this ticket are several behavior changes related to the $meta and $natural operators. First, this change tightens the validation for $natural sort and $natural hint. Previous versions of the server would permit $natural in a compound key pattern or compound sort pattern. However, it is not meaningful to combine $natural with another non-$natural field. After this change, this will result in an error with an appropriate error message:
Second, this change removes the restriction that $natural sort cannot be used in a find command against a view. Previous versions would require such an operation to be specified as a $natural hint when querying a view. As of this change, both $natural sort and $natural hint will work as expected against a view:
Third, this change tightens the logic for producing errors when a $meta:"textScore" expression is present, but the predicate does not include $text. In previous versions, a find command specifying a "textScore" $meta-sort and "textScore" $meta projection would not raise an error if the $text search predicate was absent. Now, the server correctly returns an error with an appropriate error message:
Finally, there are changes which relax the validation around "textScore" $meta projection and "textScore" $meta-sort for the find command. Previous versions of the server required a "textScore" $meta projection on the same field as a "textScore" $meta-sort whenever the $meta-sort is specified. The changes under this ticket relax this requirement. Find commands can now specify $meta-sort and $meta-projection with different field names, can specify $meta-sort without $meta projection, can specify $meta projection without $meta-sort, and can sort on the same field that is $meta-projected:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 18/Dec/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}Message: This change involves unifying the behavior of find and In addition:
|