Index


Model

The Hilang model of person in the cousin's sample is a good example of the use of indexes. Each person has a reference to their mother and father, together with extension properties to mother's children and father's children. To support navigation from a person to their children indexes are created in the generated code for fast indexed access.

entity Cousins.Person
    = Node (),
      Edge  (From = this,   To = Mother, Name = Name, TypeName = "Mother"),
      Edge2 (From = this,   To = Father, Name = Name, TypeName = "Father"),
      Edge3 (From = Father, To = this,   Name = Name, TypeName = "Child"),
      Edge4 (From = Mother, To = this,   Name = Name, TypeName = "Child")
(
    Name        : String
)
{
    Gender      : Cousins.Gender,

    Mother      : Cousins.Person,
    Father      : Cousins.Person
}
[
    TypeName    = "Person",

    FatherChild : Cousins.Person (Father = this),  /* navigation creates an index */
    MotherChild : Cousins.Person (Mother = this),  /* navigation creates an index */
    @Once
    Relatives   = relation (this)
];

Sample family tree

When the graph is added to the CousinsSpace, Person key/value pairs are created for the data and Index key/value pairs for indexed access.

Type │ Key │ Value
Person │ Name : Eve │ Gender : Female
... │ ... │ ...
Person │ Name :Jane │ Gender : Female, Mother : Eve
MotherChild │ Mother : Eve, Name Jane │ Name : Jane
... │ ... │ ...
Person │ Name :Adam │ Gender : Male, Father : Jack
FatherChild │ Father : Jack, Name : Adam │ Name : Adam
... │ ... │ ...
Person │ Name :Lucy │ Gender : Female, Mother : Mary, Father : John
MotherChild │ Mother : Mary, Name : Lucy │ Name : Lucy
FatherChild │ Father : John, Name : Lucy │ Name : Lucy
... │ ... │ ...
Person │ Name : Mark │ Gender : Male, Mother : Mary, Father : John
MotherChild │ Mother : Mary, Name : Mark │ Name : Mark
FatherChild │ Father : John, Name : Mark │ Name : Mark
... │ ... │ ...

NB {Person, Name, Mother,Father, Gender, Female, Male, MotherChild, FatherChild} are not stored (as they would for JSON encoding), just the tag number from meta-model.

When we search a SetSpace ( like CousinSpace.Persons), a rule-based-optimizer is used:

  1. Use the KeyPath if it is Sargable (At least the first field of the Key has a value).
  2. Use the first Index that is Sargable (At least the first field of the Index Key has a value).
  3. Scan all items of the type.
  • Search for Person { Name = "Lucy"} will access the Person directly in Hiperspace
  • Search for Person { Name = "Lucy", Mother: "Mary", Father: "John"} will access the Person directly in Hiperspace
  • Search for Person { Mother = "Mary"} will use the 1st index MotherChild to return 'Lucy' and 'Mark'
  • Search for Person { Father = "John"} will use the 2nd index FatherChild to return 'Lucy' and 'Mark'
  • Search for Person { Mother = "Mary", Father = "John"} will use the 1st index MotherChild to return 'Lucy' and 'Mark'
Copyright © Cepheis 2024