Last week saw the addition of the
RETURN DISTINCT for AQL queries.
This is a new shortcut syntax for making result sets unique.
For this purpose it can be used as an easier-to-memorize alternative for
the already existing
COLLECT is very flexible and
can be used for multiple purposes, but it is syntactic overkill for making
a result set unique.
RETURN DISTINCT syntax makes queries easier to write and understand.
Here’s a non-scientific proof for this claim:
Compare the following queries, which both return each distinct
value from the collection:
1 2 3
Clearly, the query using
RETURN DISTINCT is more intuitive, especially for
AQL beginners. Apart from that, using
RETURN DISTINCT will save a bit of typing
compared to the longer
RETURN DISTINCT will work by creating an
AggregateNode. The optimizer will try the sorted and the hashed variants
for both, so they should perform about the same.
However, the result of a
RETURN DISTINCT does not have any guaranteed order,
so the optimizer will not insert a post-
SORT for it. It may do so for a regular
As mentioned before,
COLLECT is more flexible than
COLLECT is superior to
RETURN DISTINCT when the result set should
be made unique using more than one criterion, e.g.
1 2 3
This is currently not achievable via
RETURN DISTINCT, as it only works
with a single criterion.