我想找到一组没有个人资料的用户。
ArangoDB 2.4.3
LENGTH(users) -> 130k
LENGTH(profiles) -> 110k
users.userId -> unique hash index
profiles.userId -> unique hash index
我制作的这个 AQL 片段比仲夏穿越大峡谷的蜗牛还慢。
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)