N1QL Performance Issue


we have a test system with 4 nodes all running couchbase server 4.1.
All three services (data, index, query) are running on every node.


When i execute the following query on a bucket with 2.000.000 documents and a secondary index on country,
the query takes about 8 minutes.

SELECT country, COUNT(*) FROM Test GROUP BY country

If i run the same query on our sql server with 20.000.000 entries and no index on country
it takes about 3 minutes.

I haven’t found any statements about the performance of n1ql.
But i think the query should run a lot faster.

Is there a way to speed up the query?


Have you created a secondary index on the field country?

Yes i have a Primary index and a secondary index on country

You might get better performances if you use separated nodes running the index and query services independently.
@geraldss and @cihangirb can tell you more on expected results.


Please do the following in order to get the benefit of a covering index, and then rerun your test:

1 Like

Thx for the fast response.

IS NOT MISSING reduced the execution time from 8 minutes to about 40 seconds.

1 Like