Skip to content

Narrow queried indices based on __typename filters#1229

Merged
marcdaniels-toast merged 1 commit into
block:mainfrom
marcdaniels-toast:mdaniels/typename-index-narrowing
Jun 12, 2026
Merged

Narrow queried indices based on __typename filters#1229
marcdaniels-toast merged 1 commit into
block:mainfrom
marcdaniels-toast:mdaniels/typename-index-narrowing

Conversation

@marcdaniels-toast

@marcdaniels-toast marcdaniels-toast commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Closes #1179

When a query on an abstract type filters on __typename, we can skip any index that contains none of the requested concrete types. For example, querying DistributionChannel with __typename: {equal_to_any_of: [PhysicalStore]} only needs to hit physical_stores, not distribution_channels.

TypenameFilter (in the Filtering namespace) extracts the set of type names satisfying the __typename filter, using FilterValueSetExtractor.for_equality from #1239 for full set-algebra support across not, any_of, and all_of combinators. DatastoreQuery uses this via narrowed_search_index_definitions, which intersects initial_search_index_definitions with only the indices that could contain the filtered types.

Note: the rename of search_index_definitionsinitial_search_index_definitions was split into a separate prep PR (#1253) to ease review.

Doc check

I wanted to be sure the YARD documentation of initial_search_index_definitions worked properly. Here's a screenshot:
image

@myronmarston myronmarston left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @marcdaniels-toast! Left some suggestions.

Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema/type.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/datastore_query.rb
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/datastore_query.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/datastore_query.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/filtering/typename_filter.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/datastore_query.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/filtering/typename_filter.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/filtering/typename_filter.rb Outdated
myronmarston pushed a commit that referenced this pull request Jun 12, 2026
…x_definitions (#1253)

## Summary

Spun out of #1229 to ease review. This is just a rename; there are
intentionally no behavior changes.

Renames the `DatastoreQuery` field `search_index_definitions` to
`initial_search_index_definitions` across all callers and tests, and
adds a YARD doc describing it as "the index definitions as provided at
construction, before any subsequent adjustments."

The new name sets up a clear contrast with
`narrowed_search_index_definitions` introduced in #1229, which derives a
refined set based on query filters.

> [!NOTE]  
> This could be a breaking change for ElasticGraph application
maintainers, if their
> application has any query interceptors that reference
`query.search_index_definitions`.
> The next release will need to be minor version bump (`v1.3.0`) and
this should be
> called out in the upgrade section of the release notes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
When a query on an abstract type filters on `__typename`, we can skip
any index that contains none of the requested concrete types. For example,
querying `DistributionChannel` with `__typename: {equal_to_any_of: [PhysicalStore]}`
only needs to hit `physical_stores`, not `distribution_channels`.

`TypenameFilter` determines the subset of type names satisfying the
`__typename` filter using full set-algebra support across `not`, `any_of`,
and `all_of` combinators. `DatastoreQuery` uses this via
`narrowed_search_index_definitions`, which intersects
`initial_search_index_definitions` with only the indices that could
contain the filtered types.

Closes #1179

Generated with Claude Code
@marcdaniels-toast marcdaniels-toast force-pushed the mdaniels/typename-index-narrowing branch from 223ddf6 to 0b041fc Compare June 12, 2026 21:07
@marcdaniels-toast marcdaniels-toast changed the title Narrow queried indices based on _typename filters Narrow queried indices based on __typename filters Jun 12, 2026

@myronmarston myronmarston left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@marcdaniels-toast marcdaniels-toast merged commit b3d6b71 into block:main Jun 12, 2026
19 checks passed
@marcdaniels-toast marcdaniels-toast deleted the mdaniels/typename-index-narrowing branch June 12, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize __typename filtering: narrow queried indices

2 participants