【发布时间】:2015-02-10 17:13:53
【问题描述】:
我想查找没有个人资料的用户集。
ArangoDB 2.4.3
LENGTH(users) -> 130k
LENGTH(profiles) -> 110k
users.userId -> unique hash index
profiles.userId -> unique hash index
我做的这个 AQL sn-p 比仲夏穿越大峡谷的蜗牛还慢。
LET usersWithProfiles = ( /* This part is ok */
FOR i IN users
FOR j IN profiles
FILTER i.userId == j.userId
RETURN i
)
LET usersWithoutProfiles = ( /* This is not */
FOR i IN usersWithProfiles
FILTER i NOT IN users
RETURN i
)
RETURN LENGTH(usersWithoutProfiles)
我很确定有一种完全理智的方法可以做到这一点,但我错过了它。有什么想法吗?
编辑 1(在 @dothebart 的回复之后):
这是新查询,但还是很慢
LET userIds_usersWithProfile = (
FOR i IN users
FOR j IN profile
FILTER i.userId == j.userId
RETURN i.userId
)
LET usersWithoutProfiles = (
FOR i IN users
FILTER i.userId NOT IN userIds_usersWithProfile
RETURN i
)
RETURN LENGTH(usersWithoutProfiles)
【问题讨论】: