[SERVER-56017] Fix invariant failure in SlotBasedStageBuilder::buildSort() Created: 11/Apr/21  Updated: 29/Oct/23  Resolved: 26/Apr/21

Status: Closed
Project: Core Server
Component/s: Query Execution
Affects Version/s: None
Fix Version/s: 5.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Drew Paroski Assignee: Nikita Lapkov (Inactive)
Resolution: Fixed Votes: 0
Labels: qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Open the mongo shell and run the following commands:

> db.coll.createIndex({y: 1, x: 1})
> db.coll.find({y: {$gt: 0}, x: {$gte: 20}}, {_id: 0, y: 1, x: 1}).sort({x:-1}).limit(2)

Sprint: Query Execution 2021-04-19, Query Execution 2021-05-03
Participants:

 Description   

Around line 829 of "src/mongo/db/query/sbe_stage_builder.cpp", there is an invariant at the top of the buildSort() method.

Here is a valid plan that can cause this invariant() to fail:

> db.coll.createIndex({y: 1, x: 1})
> db.coll.find({y: {$gt: 0}, x: {$gte: 20}}, {_id: 0, y: 1, x: 1}).sort({x:-1}).limit(2)

The "limit(2)" in the query above forces the QueryPlanner to generate a PROJECTION_COVERED / SORT / IXSCAN plan, where the input to sort stage is coming directly from the index keys.



 Comments   
Comment by Githook User [ 26/Apr/21 ]

Author:

{'name': 'Nikita Lapkov', 'email': 'nikita.lapkov@mongodb.com', 'username': 'laplab'}

Message: SERVER-56017 Support sort in covered queries in SBE
Branch: master
https://github.com/mongodb/mongo/commit/92ba6ed48bc6fbc80556f10455b8560aabab4329

Comment by David Storch [ 12/Apr/21 ]

We should remove the sbe_incompatible tag from jstests/aggregation/optimize_away_pipeline.js as part of this ticket.

Generated at Thu Feb 08 05:38:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.