Hi, I was searching about how the composite index sequence affect the performance on N1QL, but didn’t get an explanation on this.
I am using quite a lot of composite index (sometimes with array index).
What I observed was using the below 2 indexes:
- create index
idxonbucket((key1),(key2),(key3),(distinct (arrayxforxin (array_key) end))) - create index
idxonbucket((distinct (arrayxforxin (array_key) end)),(key1),(key2),(key3))
(1) will take a few seconds to return the result while (2) will take <100ms to return the result.
I’ve tried altering the sequence of expressions in my query WHERE clause, but the result is the same.
May I know:
- Does this means: the sequence of keys in the query doesn’t affect the result, but the sequence of keys in index does
- Apart from array index, does the sequence of other keys affect the performance as well?
- How should we know the correct sequence when we construct an index/query, except by trying all the combinations each time we implement a new query?
FYI, I’m using 4.6.0-3573 Enterprise Edition.
Thanks a lot.



