Fix invariant failure in SlotBasedStageBuilder::buildSort()

XMLWordPrintableJSON

    • Fully Compatible
    • ALL
    • Hide

      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)

      Show
      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)
    • Query Execution 2021-04-19, Query Execution 2021-05-03
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

              Assignee:
              Nikita Lapkov (Inactive)
              Reporter:
              Drew Paroski
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: