Understanding "IN" operator

I need help in understanding the IN operator

In my following example:

MATCH (a1:Author)-[co:COAUTHOR]-(a2:Author) WHERE co.year IN [2017,2018,2019,2020] RETURN a1,co,a2

The operator tests every year every time in array to compute a MATCH OR tests each year in array by index (starting from 2017 THEN going to 2018 ... 2020)

Im in doubt if need to use some logic to iterate the array of years, in this example, to compute the required MATCH.

For relationship there is no index, so it gets all relationships first and then checks if the year is in the list provided.

If you try profiling you will see a DB scan.

Say if the year is an attribute on Author node and you have index on year then it would use index based look up similar to

year=2017 or year=2018 or year=2019 or year=2020.

Hope that makes it clear.

1 Like

Thanks for explanation, now i understand better.