Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-80772

Stage builders generate invalid plan for simple project after sort query

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 7.2.0-rc0, 7.0.2, 7.1.0-rc3
    • Affects Version/s: 7.0.0
    • Component/s: None
    • Labels:
      None
    • Query Execution
    • Fully Compatible
    • ALL
    • v7.1, v7.0
    • QE 2023-09-18
    • 160

      The stage builders generate a plan that assumes a "root" document is available when it is not. E.g.

      [j0:prim] [4] mkbson s16 [_id = s12, out = s15] true false
      [j0:prim] [4] project [s15 = getElement(s13, 0)]
      [j0:prim] [4] group [s12] [s13 = addToArrayCapped(s2, 104857600)] spillSlots[s14] mergingExprs[aggConcatArraysCapped(s14, 104857600)]
      [j0:prim] [4] project [s12 = (s11 ?: null)]
      [j0:prim] [4] project [s11 = traverseP(s10, lambda(l101.0) { getField(move(l101.0), "hostname") }, 1)]
      [j0:prim] [3] project [s10 = getField(s9, "tags")]
      [j0:prim] [3] mkbson s9 s4 [_id] keep [] true false
      [j0:prim] [2] sort [s7, s8] [desc, asc] [s2]
      [j0:prim] [2] project [s7 =
      [j0:prim]     if (isArray(s3) ?: false)
      [j0:prim]     then (_internalGreatest(s3) ?: undefined)
      [j0:prim]     else (s3 ?: null)
      [j0:prim] , s8 =
      [j0:prim]     if (isArray(s1) ?: false)
      [j0:prim]     then (_internalLeast(s1) ?: undefined)
      [j0:prim]     else (s1 ?: null)
      [j0:prim] ]
      [j0:prim] [2] project [s6 = (!((isArray(s3) ?: false)) || (!((isArray(s1) ?: false)) || fail(2, "cannot sort with keys that are parallel arrays")))]
      [j0:prim] [1] scan s4 s5 none none none none none none lowPriority [s1 = ExceededTimeLimit, s2 = _id, s3 = assertAlways] @"6f634a83-ec81-486b-a994-07d88e095f25" true false
      

      This assumes s4 is available after the sort when in fact, only the _id value was carried through the sort.

      The result is that the query fails due to a tassert.

            Assignee:
            ian.boros@mongodb.com Ian Boros
            Reporter:
            ian.boros@mongodb.com Ian Boros
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: