英文:
What's the time complexity of query a node in neo4j?
问题
我对neo4j查询的工作原理感到困惑。
如果我的图数据库中有10个节点(7个客户节点+3个产品节点)
现在,我想查询一个客户节点(例如:C1),时间复杂度是多少?
查询的工作原理是怎样的?像哈希表O(1)一样吗?还是像二分查找O(logN)一样?
英文:
I'm confused how neo4j query work.
If I have 10 nodes in my graph DB (7 Customer nodes + 3 Product nodes)
Now, I want to query a customer node(ex: C1), what's the time complexity?
And how the query work ? Like hash table O(1)? Or like binary search O(logN) ?
答案1
得分: 1
示例
MATCH (p:Person {name: '汤姆·汉克斯'})
RETURN p
结果
规划器成本
运行时流水线化
运行时版本 5.8
批处理大小 128
+------------------+----+------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| 操作符 | Id | 详细信息 | 预估行数 | 行数 | 数据库命中 | 内存(字节) | 页面缓存命中/未命中 | 时间(毫秒) | 流水线 |
+------------------+----+------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | 0 | p | 6 | 1 | 3 | | | | |
| | +----+------------------------+----------------+------+---------+----------------+ | | |
| +Filter | 1 | p.name = $autostring_0 | 6 | 1 | 250 | | | | |
| | +----+------------------------+----------------+------+---------+----------------+ | | |
| +NodeByLabelScan | 2 | p:Person | 125 | 125 | 126 | 120 | 3/0 | 0.772 | 在流水线 0 中合并 |
+------------------+----+------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
总数据库访问次数:379,总分配内存:184
1 行
正如您所见,当您搜索一个节点时,它将扫描所有节点,这意味着时间复杂度为 O(N)。
然而,您可以为节点创建索引,从而提高搜索速度。
更多信息:文档
英文:
Example
MATCH (p:Person {name: 'Tom Hanks'})
RETURN p
Result
Planner COST
Runtime PIPELINED
Runtime version 5.8
Batch size 128
+------------------+----+------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| Operator | Id | Details | Estimated Rows | Rows | DB Hits | Memory (Bytes) | Page Cache Hits/Misses | Time (ms) | Pipeline |
+------------------+----+------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
| +ProduceResults | 0 | p | 6 | 1 | 3 | | | | |
| | +----+------------------------+----------------+------+---------+----------------+ | | |
| +Filter | 1 | p.name = $autostring_0 | 6 | 1 | 250 | | | | |
| | +----+------------------------+----------------+------+---------+----------------+ | | |
| +NodeByLabelScan | 2 | p:Person | 125 | 125 | 126 | 120 | 3/0 | 0.772 | Fused in Pipeline 0 |
+------------------+----+------------------------+----------------+------+---------+----------------+------------------------+-----------+---------------------+
Total database accesses: 379, total allocated memory: 184
1 row
As you can see, when you search a node, it will scan all nodes which mean the time complexity is O(N).
However you can create index for node that can improve search faster.
More info: document
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论