I have a bucket with 2m documents, out of which all but 180k are audits (have “<AUDIT>” partway through their ID). I have a primary index, and also have 2 other indexes, both with the same filter requirements that exclude audit documents
CREATE INDEX device_model ON bucket(lower((device_info.model))) WHERE (((meta().id) like "device---%") and (not contains((meta().id), "<AUDIT>"))) WITH { "num_replica":1 }
CREATE INDEX device_make ON bucket(lower((device_info.make))) WHERE (((meta().id) like "device---%") and (not contains((meta().id), "<AUDIT>"))) WITH { "num_replica":1 }
If I run a query that uses either one of these two as a covering index, eg
select meta().id from bucket
where meta().id like "device---%"
and not contains(meta().id, "<AUDIT>")
and lower(device_info.make) = "test"
offset 100000
limit 100
,it works great, and responds in ~35ms, only looking at that covering index.
If I do a query that uses both, eg
select meta().id from bucket
where meta().id like "device---%"
and not contains(meta().id, "<AUDIT>")
and lower(device_info.make) = "test"
and lower(device_info.model) = "test"
offset 100000
limit 100
it takes like 16 seconds. In the explain plan it is doing an intersect scan with not only both secondary indexes but also the primary index, which requires iterating over all 2m documents in that index.
So… why is this? Why can’t it just intersect the 2 highly selective covering indexes? Any help appreciated.
(all doc IDs are prefixed with a doc type of device---
, so a doc ID might be device---test1
or device---test1<AUDIT>143243
). Also this is server v5.5.1.