Skip to content

add indexes and constraints content #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions documentation/movies.workspace.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ image::movie-model.png[]

[source,cypher]
----
CREATE CONSTRAINT movie_title IF NOT EXISTS FOR (m:Movie) REQUIRE m.title IS UNIQUE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't change it, it needs to stay here. other wise the performance will be affected as each MERGE needs to do a full label-scan to find the relevant nodes.

CREATE CONSTRAINT person_name IF NOT EXISTS FOR (p:Person) REQUIRE p.name IS UNIQUE;

MERGE (TheMatrix:Movie {title:'The Matrix'}) ON CREATE SET TheMatrix.released=1999, TheMatrix.tagline='Welcome to the Real World'

MERGE (Keanu:Person {name:'Keanu Reeves'}) ON CREATE SET Keanu.born=1964
Expand Down Expand Up @@ -702,6 +699,22 @@ MATCH path = (person)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d)
RETURN path;
----

To aid query performance, you can add indexes to your data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either move this to the beginning, but we should ensure that people execute this cypher-block, or keep it in the MERGE statement.

(The dataset you create in this guide is very small, but it is good practice to use indexes as they can greatly improve query performance when the datasets are larger.)

In this small dataset, you are mainly interested in names of people and titles of movies.
Run the following to add indexes on these properties

[source,cypher]
----
CREATE INDEX person_name FOR (p:Person) ON (p.name);
CREATE INDEX movie_title FOR (m:Movie) ON (m.title)
----

Note that you can also add constraints to your data to ensure uniqueness for example.
Adding constraints automatically adds a correpsonding index.
See link:https://neo4j.com/docs/cypher-manual/current/constraints/[Cypher Manual -> Constraints^] for more information.

In the next step, you will look for nodes and their properties.

== Find nodes
Expand Down