简体   繁体   English

OrientDB 遍历 SQL 查询效率

[英]OrientDB Traverse SQL query efficiency

Apologies I am new to Graphing DB!抱歉,我是 Graphing DB 的新手! I have the following basic structure in an OrientDB :我在OrientDB 中有以下基本结构:

在此处输入图片说明

I need to obtain all the permission associated with a given User .我需要获得与给定User相关的所有permission permission are always contained in a Role but a Role can belong either directly to a User or to a Team . permission始终包含在RoleRole可以直接属于UserTeam I haven't added it to the image but the edges between User > Role and Team > Role are has .我没有将它添加到图像中,但User > RoleTeam > Role之间的边缘has . And between User > Team are member .User > Team之间是member

My current approach is:我目前的做法是:

SELECT permission FROM (
  TRAVERSE any() FROM #23:0 WHILE $depth <=4
) WHERE @class='Role'

However, I suspect that there is a much more efficient was of achieving this.但是,我怀疑有一个更有效的方法来实现这一点。

Instead of using any() for traversal, you can use named edges.您可以使用命名边,而不是使用any()进行遍历。

Eg.例如。 if user -belongsTo-> team and user,team -hasPermission-> permission you can write this query like如果user -belongsTo-> teamuser,team -hasPermission-> permission您可以像这样编写此查询

SELECT FROM (
   TRAVERSE out('belongsTo', 'hasPermission') FROM #23:0 WHILE $depth <=2
) WHERE @class='Role'

This will avoid traversal of unwanted branches.这将避免遍历不需要的分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM