'connect by'或'WITH RECURSIVE'在高度连接的大数据场景中是否可用?
Are 'connect by' or 'WITH RECURSIVE' even usable in a highly connected big data scenario?
想象一下以下大数据情况:
SQL 数据库中存储了 100 万人。
他们每个人都正好跟随另外 50 个人。
所以有这样一个table(有5000万个条目):
person1 | person2
0 | 1
0 | 2.341
0 | 212.881
.. | ..
999.999 | 421.111
999.999 | 891.129
999.999 | 920.917
是否可以使用 Oracle 的 connect by
或 MySQL 的 WITH RECURSIVE
来查明一个人与另一个人之间是否存在联系(可能通过中介)?
这些查询真的会 运行 永远吗? (数据高度关联)
或者有没有办法限制查询的深度? (在这种情况下:只有 < 3 个中间人)
上下文:这个例子将用于解释为什么图形数据库在某些情况下可以更好,我想展示这是否可以用 SQL.[=31= 解决]
Is it possible to use Oracle's connect by
or MySQL's WITH
RECURSIVE
to find out if there is a connection (maybe over
intermediaries) from one person to an other?
是的。这就是这些功能的目的。
Would those queries literally run forever? (the data are highly connected)
与所有 SQL 查询一样,适当的索引对于良好的性能至关重要。
至于"forever" Oracle detects loops in hierarchies (that is, when the data breaks the assumption that it is a directed acyclic graph.)
递归通用 table 表达式(在大多数非 Oracle table 服务器中)可以通过级别限制其递归。看到这个 https://dba.stackexchange.com/questions/16111/cte-running-in-infinite-loop.
做这种工作用图数据库好吗?那是见仁见智了。
- 你还需要循环检测。
- 在生产中,将数据从一个数据库移动到另一个数据库,或者在多个地方保留副本,成本很高。因此,您的实用设计选择将受到系统存储数据的位置的影响。
想象一下以下大数据情况:
SQL 数据库中存储了 100 万人。 他们每个人都正好跟随另外 50 个人。
所以有这样一个table(有5000万个条目):
person1 | person2
0 | 1
0 | 2.341
0 | 212.881
.. | ..
999.999 | 421.111
999.999 | 891.129
999.999 | 920.917
是否可以使用 Oracle 的 connect by
或 MySQL 的 WITH RECURSIVE
来查明一个人与另一个人之间是否存在联系(可能通过中介)?
这些查询真的会 运行 永远吗? (数据高度关联)
或者有没有办法限制查询的深度? (在这种情况下:只有 < 3 个中间人)
上下文:这个例子将用于解释为什么图形数据库在某些情况下可以更好,我想展示这是否可以用 SQL.[=31= 解决]
Is it possible to use Oracle's
connect by
or MySQL'sWITH RECURSIVE
to find out if there is a connection (maybe over intermediaries) from one person to an other?
是的。这就是这些功能的目的。
Would those queries literally run forever? (the data are highly connected)
与所有 SQL 查询一样,适当的索引对于良好的性能至关重要。
至于"forever" Oracle detects loops in hierarchies (that is, when the data breaks the assumption that it is a directed acyclic graph.)
递归通用 table 表达式(在大多数非 Oracle table 服务器中)可以通过级别限制其递归。看到这个 https://dba.stackexchange.com/questions/16111/cte-running-in-infinite-loop.
做这种工作用图数据库好吗?那是见仁见智了。
- 你还需要循环检测。
- 在生产中,将数据从一个数据库移动到另一个数据库,或者在多个地方保留副本,成本很高。因此,您的实用设计选择将受到系统存储数据的位置的影响。