-
Notifications
You must be signed in to change notification settings - Fork 12
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
AlexicaWright
merged 2 commits into
neo4j-graph-examples:main
from
AlexicaWright:add-indexes-to-movies
May 15, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
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 | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.