0

我目前有 2 个名为community和的顶点集合user。作为社区成员的每个用户都使用边缘链接到该社区community_user

我正在尝试community_user为给定用户更新其 _id 和给定其 _id 的边缘community

SELECT read from community_user where 
     outV() in (select @rid FROM `community` WHERE ( `_id` = '5ab283c35b6b9435d4c9a958' )) 
     and 
     inV() in (select @rid from user where _id  = 'x5mxEBwhMfiLSQHaK')

这个查询确实有效,尽管一旦community_user边缘被填充它会相当慢。

有没有办法索引这个搜索或更快的解决方案来找到我需要的值?

我当前的相关索引在community._id并且user._id

EXPLAIN查询的结果是:

{
    "result": [
        {
            "@type": "d",
            "@version": 0,
            "documentReads": 1,
            "fullySortedByIndex": false,
            "documentAnalyzedCompatibleClass": 1,
            "recordReads": 1,
            "fetchingFromTargetElapsed": 0,
            "indexIsUsedInOrderBy": false,
            "currentMatch": null,
            "compositeIndexUsed": 1,
            "current": "#169:839",
            "depth": 0,
            "involvedIndexes": [
                "user._id"
            ],
            "limit": -1,
            "matched": {
                "$ORIENT_DEFAULT_ALIAS_0": "#1770:0",
                "theEdge": "#1817:1889"
            },
            "evaluated": 1,
            "elapsed": 1490.7661,
            "resultType": "collection",
            "resultSize": 1,
            "@fieldTypes": "documentReads=l,documentAnalyzedCompatibleClass=l,recordReads=l,fetchingFromTargetElapsed=l,compositeIndexUsed=l,current=x,involvedIndexes=e,evaluated=l,elapsed=f"
        }
    ],
    "notification": "Query executed in 1.521 sec. Returned 1 record(s)"
}
4

1 回答 1

0

最简单的方法是使用 MATCH 语句

MATCH
  {class:community, where:(_id = '5ab283c35b6b9435d4c9a958' )}
    .outE(){as:theEdge}.inV(){class:user, where:(_id  = 'x5mxEBwhMfiLSQHaK')}
RETURN $elements
于 2018-04-26T10:09:50.980 回答