Native query: centralize the is-native gate decision into a single predicate (Route + vector-search + lookup-streamability)

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Dotnet Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Internal refactor / architecture follow-up from the EF-332 external review (native LINQ query provider program, epic EF-322). Not a bug; no behavior change intended.

      Problem

      EF-332 collapsed the mutable IsNativeRepresentable flag into a single computed MongoSelectDefinition.Route (NativeRoute

      { Fallback, WholeEntity, Projection }

      ) that the compile-time gate reads. The intent was "one authoritative is-native decision." In practice the decision is not fully centralized: MongoShapedQueryCompilingExpressionVisitor reads Route and two side-channel conditions whose state does not live on MongoSelectDefinition:

      1. Vector searchContainsVectorSearch(mongoQueryExpression.CapturedExpression) scans the captured method chain. The VectorSearch(...) call is lifted out of the tree by MongoQueryTranslationPreprocessor (VectorSearchExtractor) and sits at the root, so it never reaches NativeSlotPopulator's catch-all — hence the separate scan.
      2. $lookup streamabilityAllPendingLookupsAreStreamableReferences(mongoQueryExpression) reads the pending-lookup state that EF-330 deliberately kept on MongoQueryExpression (entangled with the fallback shaper; slated to move/clean under EF-317), not on MongoSelectDefinition.

      So the "single Route predicate" abstraction leaks: a reader must know to also consult two other signals, and that will erode further as SP4+ adds more native shapes.

      Why not a quick fix

      The EF-332 review suggested "fold vector-search detection into Route at population time." That is not straightforward:

      • Vector search isn't present at slot-population time (extracted pre-QMTEV, root-positioned), so marking it on Route needs explicit root handling.
      • Lookup state lives on MongoQueryExpression by an EF-330 design decision; moving it onto MongoSelectDefinition overlaps EF-317.

      This needs a small design pass, not a blind fixer — hence a separate ticket rather than folding into EF-332.

      Scope

      • Decide the shape of a single authoritative gate predicate (e.g. a method on the gate, or an enriched Route that the QMTEV/preprocessor feed vector-search and lookup signals into at population time).
      • Have all gate sites consult exactly that one predicate; Route (or its successor) becomes the true single source of truth.
      • Coordinate with EF-317 (which owns the $lookup-state placement) so the lookup-streamability signal lands in the right layer.
      • Best sequenced as SP4 preparation, alongside / after the native Include work, since it touches the lookup-state boundary.

      Already done in EF-332 (partial)

      The AGENTS.md wording was corrected from "the gate reads Route and nothing else" to accurately describe the two side-channel conditions and reference this ticket. The triplicated NativeOnly-forbids-fallback throw was consolidated into one ThrowIfNativeOnlyForbidsFallback helper. This ticket covers the remaining structural consolidation of the is-native signals themselves.

      Epic: EF-322.

            Assignee:
            Unassigned
            Reporter:
            Arthur Vickers
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: