In our graph , we are planning to run queries like this one :
g.V().hasLabel("customer").has("id","123").outE("has_phone").has("creat_ts","2019-10-18T21:21:21Z")
We are also planning to implement a "time machine" similar to how is explained here : https://www.datastax.com/blog/2016/09/gremlins-time-machine. In a few words , we need to find support "phone edges" that do not have "end_ts" (end_ts is stored in the edge)
I noticed that building an index or not building one , generates a similar query :
SELECT * FROM "label"."label_e" WHERE "id" = ? AND "partition_key" = ? AND "~~edge_label_id" = ? AND "~creat_ts" = ? LIMIT ? ALLOW FILTERING; with params (java.lang.String) xxx, (java.lang.String) fc768f6eebd170e0fc81e6516001510fb78c0b8f, (java.lang.Integer) 67726, (java.time.Instant) 2019-10-18T21:21:21Z, (java.lang.Integer) 50000
SELECT * FROM "graph_name"."label_e_OUT_search_by_ts_e" WHERE "id" = ? AND "partition_key" = ? AND "~~edge_label_id" = ? AND "~creat_ts" = ? LIMIT ? ALLOW FILTERING; with params (java.lang.String) xx, (java.lang.String) fc768f6eebd170e0fc81e6516001510fb78c0b8f, (java.lang.Integer) 67726, (java.time.Instant) 2019-10-18T21:21:21Z, (java.lang.Integer) 50000
From the documentation[1], you recommend that we should create different type of indexes depending on the cardinality :
Index type | Use |
---|---|
Materialized view | Most efficient index for high cardinality, high selectivity vertex properties and equality predicates. |
Secondary index | Efficient index for low cardinality, low selectivity vertex properties and equality predicates. |
Search index | Efficient and versatile index for vertex properties with a wide range of cardinality and selectivity. A search index supports a variety of predicates:
|
Considering that timestamps are variables of high cardinality , do we need an index?
We are also planning to run queries like this :
g.V().hasLabel("label").has("id","123").outE("has_address").has("type","home")
Where address type's cardinality is low. The number of values are > 3. Do we need an index there?
We noticed that queries do not fail with or without index (unlike vertices) , so that makes us wonder if there is any impact or need to have edge indexes.
Lastly , It does not seem that we can set the type of index for edges and the documentation does not match what we found experimenting. According to our interpretation of the documentation , edge indexes are secondary views, but inspecting the tables we only see secondary views. Could you please clarify?
[1] https://docs.datastax.com/en/dse/6.0/dse-dev/datastax_enterprise/graph/using/indexing.html