Creating a RANGE 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 are testing the string "Austin" in all names of Person nodes.

cypher
PROFILE MATCH (p:Person)
WHERE p.name STARTS WITH "Austin"
RETURN p.name

Step 1:

Profile this query and note if an index is used. Also note the number of total db hits. It uses an index, RANGE index p:Person(name, url), the Node key constraint that you created earlier. We no longer want this constraint, but rather want to focus on just the name.

Step 2:

Drop the Person_name_url_nodekey constraint.

Step 3:

Repeat the query with the profile. It should show more total db hits.

Step 4:

Create a RANGE index for the name property of Person nodes.

  • index_name: Person_name

  • node_label: Person

  • property_key: name

Step 5:

Repeat the query with a profile. Was your newly-created RANGE index used? Is the elapsed time reduced?

Validate Results

Once you have completed the five 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.

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 are the statements to drop the constraint and create the RANGE index:

cypher
DROP CONSTRAINT Person_name_url_nodekey;
CREATE INDEX Person_name IF NOT EXISTS FOR (x:Person) ON (x.name)

Summary

In this Challenge, you demonstrated that you can create a RANGE single property index in the graph to improve the performance of a query. In the next Challenge, you will create a single property RANGE index on a relationship property.