AGE函数在传递路径作为参数时如何工作?

huangapple go评论65阅读模式
英文:

How does an AGE function works when the passed argument is a PATH?

问题

我已经分析了age_relationships()函数的行为 - 可以在这里找到 - 并且在GDB中查看它的运行方式,似乎该函数会针对每个可用的路径多次调用。所以,例如,如果我们想要找到两个节点之间的所有路径,必须执行以下查询:

SELECT * FROM cypher('graph_name', $$
MATCH (v:Person {lastName: 'Beran'}), (v2:Person {lastName: 'Jones'}), p=((v)-[Knows*..15]-(v2))
RETURN relationships(p)
$$) AS (shortestpath agtype);

relationships(p) - 与age_relationships()相同 - 将会对这两个顶点之间的每个路径多次调用。尽管我认为这个函数会找到并检索所有路径,就像这样的伪代码一样:

age_relationships(paths):
    对于路径中的每个路径:
        检索路径

它实际上是这样工作的:

对于路径中的每个路径:
    age_relationships(路径):
        检索路径

为什么它以这种方式工作呢?

英文:

I've analyzed the behavior of the age_relationships() function - that can be found here - and looking how it works in GDB, it seems that the function is called multiple times for each available path. So, for example, if we want to find all paths between two nodes, the following query must be executed:

SELECT * FROM cypher('graph_name', $$
MATCH (v:Person {lastName: 'Beran'}), (v2:Person {lastName: 'Jones'}), p=((v)-[Knows*..15]-(v2))
RETURN relationships(p)
$$) AS (shortestpath agtype);

The relationships(p) - which is the same as age_relationships() - will be called multiple times for every path between these two vertices. Although I though that all paths would be found and retrieved by this function, as something like this pseudo code:

age_relationships(paths):
    for every path in paths:
        retrieve path

it works the other way around:

for every path in paths:
    age_relationships(path):
        retrieve path

Why does it work this way?

答案1

得分: 1

"The 'age_relationships(paths)'函数的独特路径管理方法,该方法是从Cypher查询结果中获取的路径的基础。该函数系统地分析每条路径,而不是将所有路径作为整体进行分析。处理每条路径的这种有意决策是出于调优和性能最大化的愿望,特别是在处理复杂和资源密集型查询时。

这种单独处理每条路径的方法不仅加速了计算,还提高了系统的整体效率,特别是在处理复杂和多样的问题时。该函数确保每条路径都经过准确的检查和处理,通过将任务分成更小、可管理的块来完成。"

英文:

The "age_relationships(paths)" function's unique method of managing paths obtained from the Cypher Query results serves as the foundation for its implementation. This function methodically analyzes each path separately as opposed to analyzing all paths as a whole. This intentional decision to handle pathways individually is motivated by the desire to fine-tune and maximize performance, especially when dealing with complex and resource-intensive queries.

This method of treating each path separately not only speeds up computing but also improves the system's overall effectiveness, especially when handling complex and multifarious questions. The function makes sure that each path is accurately examined and processed by segmenting the task into smaller, manageable chunks.

答案2

得分: 0

这是因为 Cypher 的 MATCH 子句在查询中像 (v)-[*]-(v2) 这样的情况下会找到并检索两个节点之间的每条路径。因此,函数 relationships 获取这条路径并检索路径中的每个其他条目(以获取仅边缘)。

为了更好地理解这个路径是如何构建的,您可以调试 transform_cypher_match 函数以及 cypher_clause.c 文件中的其他相关函数。

英文:

This occurs because the Cypher MATCH clause finds and retrieves every path between the two nodes in a query like (v)-[*]-(v2). Therefore, the function relationships takes this path and retrieves every other entry from the path (to obtain just the edges).

To gain a better understanding of how this path is constructed, you can debug the transform_cypher_match function and other related functions in the cypher_clause.c file.

答案3

得分: 0

The reason is that the function age_relationships(paths) works on every path individually when the Cypher Query returns the results to this function.

通过在每个路径上单独工作的方式,函数 age_relationships(paths) 在 Cypher 查询将结果返回给该函数时能够实现性能优化,尤其适用于复杂查询。

英文:

The reason is that the function age_relationships(paths) works on every path individually when the Cypher Query returns the results to this function.

By this individually working approach on each path, the process becomes performance-optimized for complex queries.

huangapple
  • 本文由 发表于 2023年7月4日 23:30:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76614078.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定