简体   繁体   English

Orient SQL-使用WHERE过滤结果集?

[英]Orient SQL - Filter result set using WHERE?

I've got a bit of a semantic question about Orient SQL queries. 我有一个关于Orient SQL查询的语义问题。

Take for example this very simple graph: 以这个非常简单的图形为例:

v(#12:1 User) --> e(#13:1 FriendOf) --> v(#12:2 User)

In other words, a given User with an rid of #12:1 is friends with another user with an rid of #12:2. 换句话说,给定用户摆脱#12:1是与另一个用户摆脱#12:2的朋友。

To get the friends of user #12:1, one might express this in Orient SQL like so: 为了结识用户#12:1的朋友,人们可能会在Orient SQL中这样表示:

SELECT EXPAND(both("FriendOf")) FROM #12:1

This query would return a result list comprised of the User with rid #12:2. 该查询将返回包含用户编号为#12:2的用户的结果列表。

Now lets say I want to filter that result list by an additional criteria, like say a numeric value ("age"): 现在,让我说我想通过其他条件(例如数字值(“年龄”))来过滤结果列表:

SELECT EXPAND(both("FriendOf")) FROM  #12:1 WHERE age >= 10

The above query would filter the CURRENT vertex (#12:1), NOT the result set. 上面的查询将过滤CURRENT顶点(#12:1),而不是结果集。 Which makes sense, but is there a way to apply the filter to the EXPAND(both("FriendOf")) result rather than the current vertex? 哪一个有意义,但是有没有办法将过滤器应用于EXPAND(both(“ FriendOf”))结果而不是当前顶点? I know I can do this with gremlin like so: 我知道我可以像这样用gremlin做到这一点:

SELECT EXPAND(gremlin('current.both("FriendOf").has("age",T.gte,10)')) FROM #12:1

But the above does not seem to make use of indexes (at least not when I ask it to explain). 但是以上内容似乎并没有利用索引(至少在我要求解释时没有使用索引)。 For very large data sets, this is problematic. 对于非常大的数据集,这是有问题的。

So is there a proper way to apply a WHERE statement to the resulting data set? 那么是否有适当的方法将WHERE语句应用于结果数据集?

Thanks ! 谢谢 !

... is there a way to apply the filter to the EXPAND(both("FriendOf")) result rather than the current vertex? ...是否可以将过滤器应用于EXPAND(both(“ FriendOf”))结果而不是当前顶点?

The simple answer is to embed your basic "SELECT EXPAND ..." within another SELECT, ie 简单的答案是将基本的“ SELECT EXPAND ...”嵌入另一个SELECT中,即

SELECT FROM (SELECT EXPAND(both("FriendOf")) FROM #12:1) WHERE age >= 10

By the way, on my Mac, the above took .005s compared to over 2s for the Gremlin version. 顺便说一句,在我的Mac上,上面的代码花费了0.005秒,而Gremlin版本花费了超过2秒。 There must be a moral there somewhere :-) 某处一定有道德:-)

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

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