OrientDB如何在一个查询中获取顶点及其边的结果集

时间:2015-12-03 11:28:59

标签: sql orientdb graph-databases

我一直在使用OrientDB sql查询来获取一个结果集,该结果集不仅包含顶点,还包含它们之间存在的内部边缘。

查询可以表示为:

  • 我想要所有与project相关的顶点(没有项目本身)以及结果中包含的顶点之间的所有边

enter image description here

以下是我如何实现它,但我认为这不是正确的方法。

enter image description here

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)

预期结果:

enter image description here

此解决方案存在问题:

  • 我必须多次遍历图形(首先获取顶点,然后获取边缘以最终合并结果)
  • 基本查询select from V where label = 'project'也会多次执行。

有没有更好的方法来解决这个用例?

感谢。

1 个答案:

答案 0 :(得分:5)

尝试此查询:

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)