OrientDB 如何在一次查询中得到一组顶点及其边的结果集
OrientDB how to get a result set of vertices and its edges in one query
我一直在研究 OrientDB sql 查询以获得一个结果集,该结果集不仅包含顶点,还包含它们之间存在的内部边。
查询可以表示为:
- 我想要所有与
project
相关的顶点(没有项目本身)以及结果中包含的顶点之间的所有边
这是我实现它的方法,但我认为这不是正确的方法。
select expand($union) let $vertices = ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ), $edges = ( select from ( select from E where @rid in ( select bothE() from ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) ) ) where out in ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) and in in ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) ), $union = unionall($vertices, $edges)
以及预期结果:
此解决方案存在的问题:
- 我要多次遍历图(先取顶点再取边最后合并结果)
- 基本查询
select from V where label = 'project'
也执行了几次。
有没有更好的方法来解决这个用例?
谢谢。
试试这个查询:
select expand($c)
let $a=(traverse both(),bothE() from (select from V where label="project")),
$b=(traverse bothE() from (select from V where label="project")),
$c=difference($a,$b)
我一直在研究 OrientDB sql 查询以获得一个结果集,该结果集不仅包含顶点,还包含它们之间存在的内部边。
查询可以表示为:
- 我想要所有与
project
相关的顶点(没有项目本身)以及结果中包含的顶点之间的所有边
这是我实现它的方法,但我认为这不是正确的方法。
select expand($union) let $vertices = ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ), $edges = ( select from ( select from E where @rid in ( select bothE() from ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) ) ) where out in ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) and in in ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) ), $union = unionall($vertices, $edges)
以及预期结果:
此解决方案存在的问题:
- 我要多次遍历图(先取顶点再取边最后合并结果)
- 基本查询
select from V where label = 'project'
也执行了几次。
有没有更好的方法来解决这个用例?
谢谢。
试试这个查询:
select expand($c)
let $a=(traverse both(),bothE() from (select from V where label="project")),
$b=(traverse bothE() from (select from V where label="project")),
$c=difference($a,$b)