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.
In #1169, we added support for filtering abstract types on their
__typenamevia a_typenamefilter 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:Given a query like:
...we know that matching documents can only live in the
physical_storesindex, but, as currently implemented, we'll also query thedistribution_channelsindex. It would be more optimal to only query thephysical_storesindex.One thing to bear in mind: supporting this requires proper set algebra so that it works if a
_typenamefilter is undernot,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.