I have a bucket which stores Notifications i get from Microsoft Graph API are they are either of type contact or message.
So i created a field called _type which is either contact or message as well as an index on it.
if i i run the following query
select count(*), _type from mail_store
group by _type
it takes like 20 sec, but if i run the below is the execution plan
if i go and put a filter on the _type of IS NOT NULL
select count(*), _type from mail_store
where _type IS NOT NULL
group by _type
it takes only 87ms, as a side note all documents have the _type field so there is no condition where _type IS NULL below is the execution plan.
is there a reason for that kind of behavior and if so what is the rule of thumb, also it seems if there is a group clause it fails to pick the best avail index. On group without where
Index Currently Used
CREATE PRIMARY INDEX undefined ON
mail_store
on group by withe where clause
Index Currently Used
CREATE INDEX adv_type ON
mail_store
(_type
)
in both cases the advise says Existing indexes are sufficient.
So it seems without where clause the system is not able to pick the best index