Skip to content

Optimize __typename filtering: narrow queried indices #1179

@myronmarston

Description

@myronmarston

In #1169, we added support for filtering abstract types on their __typename via a _typename filter field. There's an additional query optimization we should implement: we can narrow down the list of searched indices based on the given __typename. For example, consider this type hierarchy:

# The DistributionChannel hierarchy has two branches:
#   DistributionChannel (index: distribution_channels)
#   ├── Wholesale            (interface, inherits distribution_channels)
#   │   ├── DirectWholesaler (concrete, distribution_channels index)
#   │   └── BrokerWholesaler (concrete, distribution_channels index)
#   └── Retail               (interface, inherits distribution_channels)
#       └── Store            (interface, inherits distribution_channels)
#           ├── OnlineStore  (concrete, distribution_channels index)
#           └── PhysicalStore (concrete, physical_stores index)

Given a query like:

distribution_channels(filter: {
  _typename: {equal_to_any_of: ["PhysicalStore"]}
}) {
  # ...
}

...we know that matching documents can only live in the physical_stores index, but, as currently implemented, we'll also query the distribution_channels index. It would be more optimal to only query the physical_stores index.

One thing to bear in mind: supporting this requires proper set algebra so that it works if a _typename filter is under not, any_of, etc. Most of the set algebra logic already exists and can be reused. It's implemented in FilterValueSetExtractor which is used by the RoutingPicker and IndexExpressionBuilder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions