【发布时间】:2021-07-07 03:31:48
【问题描述】:
在分析缓慢的 gremlin 遍历时遇到警告。
警告:>> OrderGlobalStep([[[CoalesceStep([[VertexStep(IN,[view],edge), ProfileStep, NeptuneHasStep([isActive.eq(true)]), ProfileStep, EdgeVertexStep(OUT), ProfileStep, NeptuneHasStep([~id.eq(63b944e2-481d-42c8-a1a3-c0bc3ad24484)]), ProfileStep, RangeGlobalStep(0,1), ProfileStep, CountGlobalStep, ProfileStep], [ConstantStep(0), ProfileStep]]), ProfileStep] , asc], [value(rekognitionModerationDate), desc], [value(createdDate), desc]])
分析器报告此步骤占用了总执行时间的 62%,因此我想对其进行优化。下面是完整遍历的简化版:
g.V()
.hasLabel("post")
.order()
.by(
__.coalesce(
__.inE("view")
.has("isActive", true)
.outV()
.hasId(userId)
.limit(1)
.count(),
__.constant(0)
),
order.asc
)
目标是首先输出没有传入view 边的post 顶点。换句话说,显示请求用户尚未查看的帖子,然后是他们查看过的帖子。当前遍历有效,但速度很慢。如何将其重构为“原生”,以便更快地执行?
编辑:显然,问题在于 Neptune 没有对 order().by() 的原生支持,并带有自定义比较器,如下所述:
https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-step-support.html
我仍然对如何重构它以获得纯原生支持的想法感兴趣。
【问题讨论】: