在图形数据库中使用标签而不是属性有什么好处?

时间:2021-06-09 18:04:42

I am learning graph databases using Neo4J and my first approach to categorize my nodes was creating an attribute type in all nodes.

我正在使用Neo4J学习图形数据库,我对节点进行分类的第一种方法是在所有节点中创建属性类型。

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?

使用属性或标签之间有什么区别吗?

2 个解决方案

#1


Yes, Labels is a grouping mechanism for nodes. For faster retrieval of the data we should use labels instead of property to the node.

是的,Labels是节点的分组机制。为了更快地检索数据,我们应该使用标签而不是节点的属性。

Here is the some difference in the performance of implementation of the both labels and property

以下是标签和属性的实现性能的一些差异

http://graphaware.com/neo4j/2015/01/16/neo4j-graph-model-design-labels-versus-indexed-properties.html

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

示例 - 如果您的图表有1000个节点并且其中包含100个节点且包含学生信息,那么您已将type = student设置为这些节点

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.

此查询将检查所有1000个节点并将结果返回给您。

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.

此查询将仅在100个节点中传输并返回结果。

Conclusion- It is better to use labels to the node rather than type property.

结论 - 最好在节点上使用标签而不是类型属性。

#2


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).

主要区别在于属性是键值对。标签更像是标签(想想在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.

标签也直接与节点一起存储(除非每个节点使用过多标签)。访问属性是第二次I / O(或缓存)访问。

#1


Yes, Labels is a grouping mechanism for nodes. For faster retrieval of the data we should use labels instead of property to the node.

是的,Labels是节点的分组机制。为了更快地检索数据,我们应该使用标签而不是节点的属性。

Here is the some difference in the performance of implementation of the both labels and property

以下是标签和属性的实现性能的一些差异

http://graphaware.com/neo4j/2015/01/16/neo4j-graph-model-design-labels-versus-indexed-properties.html

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

示例 - 如果您的图表有1000个节点并且其中包含100个节点且包含学生信息,那么您已将type = student设置为这些节点

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.

此查询将检查所有1000个节点并将结果返回给您。

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.

此查询将仅在100个节点中传输并返回结果。

Conclusion- It is better to use labels to the node rather than type property.

结论 - 最好在节点上使用标签而不是类型属性。

#2


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).

主要区别在于属性是键值对。标签更像是标签(想想在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.

标签也直接与节点一起存储(除非每个节点使用过多标签)。访问属性是第二次I / O(或缓存)访问。