已知的深度和边缘查询效率

时间:2015-04-21 01:07:09

标签: orientdb

我的数据如下:

a ---> b ---> c

a,b和c是顶点,有一个a,但有多个b-s和c-s(树结构)。

我的 - >> b edge是一个类(让我们称之为ab类),而b ---> c edge是另一个(bc类)。

我需要一个查询,给定a的名称,产生x个c-s。

到目前为止,我发现这有效:

select expand(set(out("ab").out("bc"))) from a where name='aName' limit x

问题:

  1. 可以改进此查询吗?
  2. 我怎样才能选择例如c-s的名称,而不是整个记录?
  3. 感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我认为只有在 A.name 属性上定义索引时,才能改进查询。

关于你的第二个问题:

create class A extends V
create class B extends V
create class C extends V    

create class AB extends E
create class BC extends E

create vertex A set name = 'aName'
create vertex B set name = 'bName0'
create vertex B set name = 'bName1'
create vertex C set name = 'cName0'
create vertex C set name = 'cName1'
create vertex C set name = 'cName2'
create vertex C set name = 'cName3'    

create edge AB from (select from A where name = 'aName') to (select from B where name = 'bName0')
create edge AB from (select from A where name = 'aName') to (select from B where name = 'bName1')
create edge BC from (select from B where name = 'bName0') to (select from C where name = 'cName0')
create edge BC from (select from B where name = 'bName0') to (select from C where name = 'cName2')
create edge BC from (select from B where name = 'bName1') to (select from C where name = 'cName1')
create edge BC from (select from B where name = 'bName1') to (select from C where name = 'cName3')

这些查询可能会对您有所帮助:

select from (select expand(out("AB").out("BC").include('name')) from A where name = 'aName') limit 3
// or
select name from (select expand(out("AB").out("BC")) from A where name = 'aName') limit 3