For N1QL should we create an index for each search and filter predicate for n1ql to be performant?


#1

How does this work with a sharded couchbase? which will be slow performing queries which ones will be fast


#2

You should make sure that your queries are always using an index. For a multi-key predicate, an index on the most selective predicate is sufficient. For example:

SELECT * FROM b WHERE pred1=x AND pred2=Y

An index on either pred1 or pred2 (or both) is sufficient, but indexing the more selective predicate will improve performance:

CREATE INDEX idx1 ON b(pred1)

Use the EXPLAIN statement to verify index usage:

EXPLAIN SELECT * FROM b WHERE pred1=x AND pred2=Y