Skip to content

Support TVFs which return arbitrary, un-modeled (but fixed) structural types #36775

Closed as not planned

Description

@roji

We have several examples of TVFs which return some arbitrary, fixed "table", usually adding some column(s) to an actual table:

  • The experimental SQL Server VECTOR_SEARCH() function accepts a table name as a parameter, and returns that table, augmented with a distance column containing the similarity distance.
  • The full-text search functions CONTAINSTABLE() and FREETEXTTABLE() seems to work in a similar way (confirm).
  • There are apparently similar mechanisms in other databases (e.g. MongoDB, /cc @ajcvickers).

Right now, we aren't set up to properly support these. Blockers include:

  • Navigation expansion throws for any unknown top-level (queryable) operator. This was likely done to avoid letting unknown operators through but without actually processing their lambda arguments; but specifically the functions above have no lambda arguments, so don't really need nav expansion processing. A possibly better way to handle this would be to open nav expansion up to provider extension, so that these provider-specific operators can be handled.
  • We don't currently have a way to have a structural type that represents the wrapper returned by e.g. VECTOR_SEARCH(), and which would contain the actual user entity (representing the real table in the database).
    • An actual structural type (RelationalStructuralTypeShaperExpression) is needed so that e.g. the user can bind to its properties in query (and also possibly even project it out of the database).
    • This wrapper type would likely be outside of the model, at which point we have the interesting situation of a type outside the model somehow referencing a type inside the model (see e.g. liftable constant note below).
    • We're also lacking the concept of an "association" that would represent the referencing of the user's entity type from this wrapper type. It isn't a navigation since there's no foreign key, and it's not a complex property since it points to an entity type. If feels like we might be missing an association type that just models simple containment - not unlike complex properties but that can point at an entity type.
  • In the shaper, we have the "liftable constant" mechanism as a way to support precompiled queries; any structural type that's closed over in the shaper must be resolvable from the model. But if the structural type for the wrapper returned by the TVF isn't the model, that fails.

/cc @AndriySvyryd @ajcvickers

Activity

  1. added this to the 11.0.0 milestone on Sep 13, 2025
  2. added theissue type on Sep 13, 2025
  3. roji commented on Jan 19, 2026

    @roji
    MemberAuthor

    I was thinking about this all wrong - we already support this quite well in the query pipeline; specifically, we allow queries such as the following:

    _ = await context.Blogs
        .Select(b => new Wrapper
        {
            Value = b,
            Distance = 8
        })
        .ToListAsync();

    Wrapper here is an un-modeled structural type that's "instantiated" within the query and then projected out of the database.

  4. removed this from the 11.0.0 milestone on Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions