Support composite indexes

Moved from GitHub dgraph/2660

Posted by pierreis:

Unless I missed some key information, it is not possible to create composite indexes in Dgraph. Supporting this feature would help some use-cases requiring filtering on multiple attributes of a tag.

Typical example of such feature would be a versioned graph, in which a node is associated with a name, a version number and some random parameters.
In that case, most queries would be a combination of a name, and a specific version number, range queries or simply the highest version to get fresh data.
With single-attribute indexes, the performance when the number of versions is high is hindered significantly compared to that of i.e. JanusGraph, which has this feature.

manishrjain commented :

It’s not clear what you’re looking for. Can you follow the format of an experience report? What is it that you want to do, what did you currently do to achieve it, and why that wasn’t ideal?

naivefun commented :

@manishrjain I think what @pierreis wants is quite clear, faster query on multi fields.

In dgrqph it is done by connecting multi filters, but I also doubt it’s comparable to composite index like this

Especially if 90% of your queries are composite index based the performance gap would be a concern I guess.

srfrog commented :

We don’t support composite indexes right now. To get similar functionality of composite indexes in Dgraph you need to create multiple indexes. I can appreciate that they are useful, and maybe they will get added to the roadmap.

aperotte commented :

One way to get something similar to composite indexes is to allow indexes on facets. This would be a sort of composite index on the (edge, facet) combination. It wouldn’t be as general as full composite indexes but it seems like this approach would also work well with the idea of sharding by predicate (along with its indexes).