I am using Couchbase Server 4.5.0-2601 Enterprise Edition (build-2601).
And I created a index by
CREATE INDEX `idx-GYEAR-COUNTRY` ON `default`(`GYEAR`,`COUNTRY`) WHERE (_type == "PTD") USING GSI;
And I am using MOI to improve query.
The following N1QL
SELECT count(1)
FROM default g
WHERE g._type == "PTD"
shows in the index I have 198646
documents.
And my query service configure as
{"completed-limit":4000,"completed-threshold":1000,"cpuprofile":"","debug":true,"keep-alive-length":16384,"loglevel":"DEBUG","max-parallelism":2,"memprofile":"","pipeline-batch":512,"pipeline-cap":512,"request-size-cap":67108864,"scan-cap":0,"servicers":8,"timeout":0}
And the following N1QL
SELECT "1965" AS GYEAR,g.COUNTRY,count(1) AS `total`
FROM default g
WHERE g._type == "PTD" AND g.GYEAR == "1965"
GROUP BY g.COUNTRY
ORDER BY `total` DESC LIMIT 10;
took 461.77ms
(GYEAR will be a variable)
The logs shows:
_time=2016-09-20T13:51:13.518+08:00 _level=TRACE _msg=Phase aggregates authorize=101.725µs _id=8d77f958-5075-4a1d-9f58-34fb39efa56e scan=403.540153ms sort=13.668µs run=455.619599ms plan=1.306225ms parse=4.330656ms instantiate=72.104µs
Scan took 403.540153ms
I want all the N1QL took time less in 100ms.
How should I improve query?
Add more index service/data service?
is there any suggest critical point for us to improve query,
such as if the records in the index is more than 1W, you should add more data service to keep the records in the index less than 1W.