AQL performance and indexes
A little experiment with 100,000 randomly generated docs queried in two ways produce the same result, but time takes on execution is like 80 times different.
The following query took like 1.6s to execute
for doc in random_data limit 1,100 return merge(doc, { client: ( for client in random_data_details filter client.source==doc.value return unset(client, "_id","_rev") ) })
While this one, took just 0.02s
for doc in random_data limit 1,100 sort doc._key DESC collect project = doc, found_client = ( for client in random_data_details filter client.source==doc.value return unset(client, "_id","_rev") )[0] || {} return merge(project, { client: found_client })
Worth mentioning here that those benchmarks are valid only for the case when you have indexes enabled on datasets you querying.
Without indexes enabled the first query took 17s and second one executed with 8.5s.
Indexes allow fast access to documents, provided the indexed attribute(s) are used in a query. While ArangoDB automatically indexes some system attributes, users are free to create extra indexes on non-system attributes of documents.