Index for count and group by

Hi,

Are there anyway to improve performance of group by condition:
SELECT source, count(*) FROM default
GROUP BY source
I tried to create create index on “source” but didnot help

Thanks

If count on MISSING source is not required. Try this.

CREATE INDEX ix1 ON default(source);
SELECT source, count(1) FROM default  WHERE source IS NOT MISSING GROUP BY source;

Also check article by @keshav_m https://dzone.com/articles/count-amp-group-faster-using-n1ql

1 Like