Creating a Composite Index on a Node Property

Performance improvement needed

In our Movie data model, we have identified this query as important and one that we need to make as fast as possible for our users. Here is an example where we have hard-coded the test values.

cypher
MATCH (m:Movie)
WHERE  1990 <= m.year < 2000 AND m.imdbRating >= 8
RETURN m.title, m.year, m.imdbRating

Step 1:

Profile this query and note the number of total db hits. It uses a RANGE index for the title property of the Movie nodes which is not helpful.

Step 2:

Create a Composite index that will make this query faster.

Step 3:

Repeat the query with a profile. Was your newly-created Composite index used? Are the number of total db hits reduced?

Validate Results

Once you have completed the three steps of this Challenge, click the Check Indexes button and we will check the database for you.

Hint

Index names, label names, and property key names are all case-sensitive.

What properties are used in the predicate? Those properties should be used to create the composite index. You can type SHOW INDEXES after you have created the index to confirm that it created the RANGE index.

If you mess up, you can reload this Challenge page and you should be where you need to be at the beginning of this challenge.

Then you would need to perform the steps of this Challenge again.

Solution

Here is the statement to create the Composite index:

cypher
CREATE INDEX Movie_year_imdbRating IF NOT EXISTS FOR (x:Movie) ON (x.year, x.imdbRating)

Summary

In this Challenge, you demonstrated that you can create a Composite index in the graph to improve the performance of a query. In the next lesson, you will learn how to create a TEXT index.