Consider a graph, such as found in the semantic library where nodes and links can be ascribed a type.
Suppose in a graph there is a node that has several outgoing links of different types – e.g. my_business_contact, could be one of them, and that these are stored as so:
link(my_business_contact, node_1, node_2).
where node_1 happens to represent me and node_2 a business contact.
Suppose i want to find all of my business contacts – this can be accomplished by a findall/3 as so:
findall(Contact, link(my_business_contact, node1, Contact), Outgoing_Contacts).
I now wonder how lookup and (compound?) indexing in this case works, what is the lookup pattern for forall/3, as it backtracks over link/3, and finds all Outgoing_Contacts.
Suppose the case that:
- There are many nodes and links in the system.
- That for each source node (node1) there are typically less than 10 outgoing typed links,such as business contacts, but could be many more
- That there are less than 10 link types such as business_contacts, close_friends, etc.
An additional case would be to identify all incoming link types such as so:
findall(Contact, link(my_business_contact, Contact, node2), Incoming_Contacts).
In this case, the metrics could be different – a node could have many more incoming link types, but some could have less.
Overall my question is: in what relational structure, a forall/2 lookup + indexing would be most performant.