defradb icon indicating copy to clipboard operation
defradb copied to clipboard

Sec. index: enable indexing of related objects

Open islamaliev opened this issue 9 months ago • 0 comments

At the moment with requests like:

query {
  Device(filter: {
    owner: {name: {_eq: "Keenan"}}
  }) {
    model
  }
}

and schema:

type User {
  name: String @index
  devices: [Device]
} 

type Device {
  model: String 
  owner: User
}

the index will find and fetch the owner right away but having no reference to secondary objects (devices) we have to do full scan of devices to see which of them have corresponding owner_id.

The use cases from the following (potentially others as well) tests suffer from not utilizing indexes on related objects. TestQueryWithIndexOnOneToOnePrimaryRelation_IfFilterOnIndexedFieldOfRelation_ShouldFilter TestQueryWithIndexOnOneToOnePrimaryRelation_IfFilterOnIndexedRelationWhileIndexedForeignField_ShouldFilter TestQueryWithIndexOnOneToMany_IfFilterOnIndexedRelation_ShouldFilterWithExplain TestQueryWithIndexOnOneToOne_IfFilterOnIndexedRelation_ShouldFilter TestQueryWithIndexOnManyToOne_IfFilterOnIndexedRelation_ShouldFilterWithExplain

This task potentially covers #2578

islamaliev avatar May 08 '24 21:05 islamaliev