dgraph
dgraph copied to clipboard
[Feature Request] Composite indexes / primary keys
https://discuss.dgraph.io/t/id-as-the-combination-of-two-things-composite-index/16441 https://discuss.dgraph.io/t/support-for-composite-primary-keys/15940 https://discuss.dgraph.io/t/support-composite-indexes/8755 old issue: https://github.com/dgraph-io/dgraph/issues/2660
Expected:
- Being able to identify a node by N identifiers specified simultaneously
- Being able to filter nodes by
- Bonus: @id directive is not intuitive and is not really an id, could be replaced by @unique
Suggestion example (by @jdgamble but a bit adapted by myself to add also the @unique thing)
type Application @id(person, job) {
id: ID!
person: Person!
job: Job!
applicationCode: String! @Unique
...
}
query {
getApplication(person: '0x1', job: '0x2') {
...
}
}
📝Why @unique vs @id?
- Uniqueness is a necessary condition for an Id, but something can require being unique and not necessarily be the main/conceptual identifier of that node
- In this example, an application is conceptually defined by Job AND candidate
- Also UNIQUE is a pretty standard term for this (SQL, mongo...)
- Edit: Another case are unique fields that are not mandatory, for example an email address that we would like to be unique but maybe some users don't have it, so we need @unique without imposing it to be String!
📝 Why N indexes?
- Most edges with data (we are using a node but is maybe more close to an edge with facets) are conceptually defined by 2 elements. However, sometimes we will need more indexes to define something
- An example would be for this case to have "Job AND candidate AND try" where try would be 1, 2, 3... counting the number of times the candidate has applied to that job position. Each one of those combinations will hold different information (for example, interviews that happened during the second time the candidate applied to the same position). So we would need to filter the results using the 3 indexes in order to find the right one