cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Will the index be used on the generated columns?

kanth909
Node Clone

Will the index be used on the generated columns? if not, how can I request for this feature? It exists is all RDBMS.

For example:

say I have

CREATE INDEX ON :Label1(some_column) and
CREATE INDEX ON :Label2(some_other_column)

say in my WHERE clause I want to do

WHERE f(some_column) = "hello"
or
WHERE f(some_column) = g(some_other_column)

f,g are some functions available in Cypher let's say.

3 REPLIES 3

These currently aren't available.

I believe in other RDBMS's it isn't dynamic, you need to explicitly create the index or column with the expression/functions that it should support, so the simple indexes you cited here would not be enough to trigger the functionality if we supported it, you would need to provide much more explicit information when creating the indexes.

This does seem like a useful feature. Please add a request for it on our github.

yes it isn't dynamic but I would be happy to provide the expression that I want the index on. similar to this. And yes will add a request to GitHub.

The way RDBMS handles this is by applying f before adding the value to the index. You can accomplish a similar behavior in Neo4j in several ways:

1) Duplicate the column

Not ideal, but much more flexible as every Node would have both before and after values usable.
There are some apoc trigger prodedures that could automate updating a.some_column_Fidx whenever some_column changes.

CREATE INDEX ON :Label1(some_column_Fidx)

MATCH (a:Label1) 
WHERE EXISTS a.some_column
SET a.some_column_Fidx = f(a.some_column)

2) Build your own meta-index

Create meta-nodes for storing index properties, and keep a single rel to each node indexed.

CREATE INDEX ON :Label1Index(some_column_f)

MATCH (a:Label1) 
WHERE EXISTS a.some_column
MERGE (b:Label1Index {some_column_f: f(a.some_column) })<-[:INDEX]-(a)

// then your problems disappear 😉 , and let you store multiple variations for any Node, without mutating the Node
MATCH (ai:Label1Index)-[:INDEX]->(a:Label1)-[]-(b:Label2)
WHERE ai.some_column_f = g(b.some_other_column)

3) Build a plugin

I'm on that path myself right now, and it's no small feat, but you can then do anything you want with indexing, and make it more performant because it need only do what you need.