Reputation: 36696
I am learning graph databases using Neo4J and my first approach to categorize my nodes was creating an attribute type
in all nodes.
After some research, I found that I can use labels
to categorize the nodes, but I did not found if there is an advantage of using labels to this task.
Are there any differences between using an attribute or a label?
Upvotes: 0
Views: 613
Reputation: 2996
Yes, Labels is a grouping mechanism for nodes. For faster retrieval of the data we should use labels instead of property to the node.
Here is the some difference in the performance of implementation of the both labels and property
Example - If your graph has 1000 nodes and in which 100 nodes and containing information of student, so you have set type = student to those nodes
Now while searching for particular student you need to execute query like this
MATCH (n)
WHERE n.type='student'and n.student_name = 'satish'
return n
This query will check all 1000 nodes and return results to you.
But if you apply labels while creating the node then
MATCH (n:student)
WHERE n.student_name = 'satish'
return n
This query will travel with in only 100 nodes and return the result.
Conclusion- It is better to use labels to the node rather than type property.
Upvotes: 1
Reputation: 39915
The main difference is that a property is a key-value-pair. Labels are more like a tag (think of tagging an email in Gmail).
Labels are self-indexed, getting an iterator over all nodes carrying a certain label is a cheap operation.
Also labels are stored directly with the node (unless you use too much labels per node). Accessing a property instead is a second I/O (or cache) access.
Upvotes: 1