Prerequisites
I've created database with two generated collections: users and notes. Each contains ~1M documents.
Here are the structures:
user: (the name
field uses skiplist index):
{
"name": "Some user name"
}
note: (the authors
field contains _key
s to the documents from users
collection):
{
"title": "Some title",
"authors": [
"12345", "12346", "12347", ...
]
}
Problem
I need to join the users
collection on authors
field and then filter by user name
but it takes too long. It's ~3.5s on my local. The Specific name
value occurs only once.
let specificUsers = (
for user in users
filter user.name == 'Specific name'
return user
)
for note in notes
let authors = (
for user in specificUsers
filter user._key in (note.authors != null ? note.authors : [])
return user
)
filter count(authors) > 0
// filter 'Specific name' in (authors[*].name) // this way takes even longer
limit 10
return merge(note, {
authors: authors
})
If I omit the count
filter or do filtering on "owned" attributes, it loads fast, of course. But the need is to actually do filtering on joined collection. Just like in relational databases.
Question
Am I doing something wrong or ArangoDB is not supposed to perform well in this case?
Please let me know if I need to provide more details.
(note.authors != null ? note.authors : [])
. Even with index enabled. – Sergey Solo