Ok. Keeping your current format, try this in cbq shell:
\set -max_paralllelism (2x # cores);
The issue your query. This in 4.5.0+.
Your format is fine if that’s what your application wants. If want to use index order, then use the original query above, but the output will be in a different format, and you may have to change your app.
cbq> SELECT {SUBSTR(t, 0, 10) : {
> did : {
> "foull_entries" : COUNT(NULLIF(ARRAY_LENGTH(bcn), 0)),
> "total_entries" : COUNT(*),
> "nulld_entries" : COUNT(CASE WHEN ARRAY_LENGTH(bcn)==0 THEN 1 ELSE NULL END)
> }
> }}
> FROM sync_gateway
> WHERE type="bcn_scan" AND SUBSTR(t, 0, 10) BETWEEN "2016-11-01" AND "2016-12-15"
> GROUP BY SUBSTR(t, 0, 10), did
> ORDER BY SUBSTR(t, 0, 10) ASC, did ASC;