Avoid per-event resume token parsing in change stream updateLookup by reusing the collectionUUID event field

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • QE 2026-06-22, QE 2026-07-06
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      When a change stream runs with fullDocument: updateLookup and the internal matchCollectionUUIDForUpdateLookup flag (set by mongos for sharded update lookups, and used by Atlas Search), the updateLookup stage parses the event's resume token (ResumeToken::parse, a full KeyString decode) for every update event, only to recover the collection UUID. This is a measurable hot-path cost: the UUID is already available upstream in the event transform, which builds the resume token from it.

      Eliminate the parse by emitting the existing collectionUUID event field conditionally and consuming it in the updateLookup stage:

      • Add a shared helper shouldEmitCollectionUUIDForChangeEvent(spec) in change_stream_helpers.h / change_stream_helpers.cpp that returns true iff showExpandedEvents is set. It is the single source of truth for whether collectionUUID is a user-visible field of change events.
      • In change_stream_event_transform.cpp, emit collectionUUID on an event when shouldEmitCollectionUUIDForChangeEvent(...) is true (existing behaviour) or when the event is an update, a post-image was requested, and matchCollectionUUIDForUpdateLookup is set.
      • In change_stream_update_lookup_stage.cpp, read the UUID from the collectionUUID field instead of parsing the resume token, and remove the field from the output event when shouldEmitCollectionUUIDForChangeEvent(...) is false, following the same internal producer/consumer pattern as rawOplogUpdateSpec and preImageId. The transform and the updateLookup stage always run in the same pipeline on the same node, so a missing field while the match flag is set is a programming error (tassert), not a compatibility case.
      • Declare the field in DocumentSourceChangeStreamAddPostImage::getDependencies() for updateLookup mode so dependency analysis cannot strip it before the lookup stage.

      The user-visible event shape is unchanged: without showExpandedEvents the field is stripped before the event is emitted; with showExpandedEvents it is already part of the event. The change is behaviour-preserving, requires no feature flag, and benefits both the legacy aggregation lookup path and the optimized lookup executors.

            Assignee:
            Denis Grebennicov
            Reporter:
            Denis Grebennicov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: