OrientDB 使用子查询的结果来搜索索引 [英] OrientDB use result of subquery to search index
问题描述
我使用 OrientDb 2.1-rc4 作为文档数据库.我有一个 MyClass
类,它经常被多线程应用程序更新.为了提高性能,我删除了从 State
类到 MyClass
的链接,并添加了从 MyClass
到 State 的链接和索引.
为了获得 MyClass
的所有实例,我需要获得一个 State
列表,然后查询索引.这个查询让我的州摆脱了.
I am using OrientDb 2.1-rc4 as a document database. I have a MyClass
class that gets updated very frequently by a multithreded application. To improve performance I removed the link from the State
class to MyClass
, and added a link and index from MyClass
to State.
In order to get all instances of MyClass
I need to get a list of State
rids and then query the index. This query gets my State rids.
SELECT DISTINCT(roles.views.states.@rid)
FROM #12:1
返回
[["#14:0","#14:1"]]
此查询在索引中找到正确的rids.
This query finds the correct rids in the index.
SELECT FROM index:MyClass.state
where key in [#14:0,#14:1]
当我将两个查询放在一起时.
When I put the two queries together.
SELECT FROM index:MWorkUnit.state
where key in (SELECT DISTINCT(roles.views.states.@rid) FROM #12:1)
我收到以下错误.
java.lang.ClassCastException: com.orientechnologies.orient.core.sql.query.OSQLSynchQuery 不能转换为 java.util.List
java.lang.ClassCastException: com.orientechnologies.orient.core.sql.query.OSQLSynchQuery cannot be cast to java.util.List
如何让 OrientDB 将我的子查询视为删除列表?
How do I get OrientDB to treat my subquery as an rid list?
此查询在不使用索引时有效.
This query works when not using the index.
SELECT FROM MWorkUnit
where state IN (SELECT expand(roles.views.states).@rid FROM #12:1)
推荐答案
这似乎是针对索引的查询的错误:子查询未正确评估.请问你能开一个新问题吗?
This seems a bug on query against indexes: sub queries are not correctly evaluated. Please could you open a new issue or that?
此解决方法应该有效:
SELECT FROM index:MWorkUnit.state
LET $list = (SELECT DISTINCT(roles.views.states.@rid) FROM #12:1)
where key in $list
这篇关于OrientDB 使用子查询的结果来搜索索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!