2
votes

I'm designing a DB with ArangoDB for a Web Application. I wrote the following AQL query:

FOR result
 IN Collection
 FILTER result.field != 'undefined'
 RETURN result

I added some type of index for field but query doesn't use any indexes in no way.

In your opinion what is the problem? I read that for == operator we can use hash index and for <= or similar operators skip list.

Now, what is the correct way to do the same thing?

1
If the != operator is used on an attribute, no index will be used. First of all, the hash indexes don't support this type of operation. For skiplists, the operation could theoretically be transformed into result.field < 'undefined' OR result.field > 'undefined', so two disjoint ranges could in theory be queried from such index. But in general, the point of using an index is to filter out as many documents as early as possible in the query, and in many cases the != will not lead to a big reduction.stj

1 Answers

3
votes

(pasting my own comment from above as an answer so the question can be marked answered):

If the != operator is used on an attribute, no index will be used.

First of all, hash indexes in ArangoDB don't support this type of operation.

For skiplist indexes, the operation could theoretically be transformed into result.field < 'undefined' OR result.field > 'undefined', so two disjoint ranges could in theory be queried from such index. But in general, the point of using an index is to filter out as many documents as early as possible in the query, and in many cases the != will not lead to a big reduction