SELECT RAW meta().id FROM `my-bucket` where document_type = 'test_document' AND (ANY test_key_obj IN test_key SATISFIES test_key_obj.company_id IN ['1234', '5678'] OR test_key_obj.type_id IN ['abcd', 'efgh'] END)
?
we already tried
CREATE INDEX idx ON `my-bucket`(document_type,(all distinct array {test_key_obj.company_id, test_key_obj.type_id} for test_key_obj in test_key end))
but without access to generate a covering index. If possible, we want to avoid splitting the query into two separate select statements.
Thank you!
OR clause needs to saragble all otherwise Index Scan will not be optimal. Best In this case is use Union Scan.
CREATE INDEX ix2 ON `my-bucket`(DISTINCT ARRAY v.type_id FOR v IN test_key END)
WHERE document_type = "test_document";
CREATE INDEX ix3 ON `my-bucket`(DISTINCT ARRAY v.company_id FOR v IN test_key END)
WHERE document_type = "test_document";
SELECT RAW META(b).id
FROM `my-bucket` AS b
WHERE b.document_type = "test_document"
AND ANY v IN b.test_key SATISFIES v.type_id IN ["abcd", "efgh"] END
UNION
SELECT RAW META(b).id
FROM `my-bucket` AS b
WHERE b.document_type = "test_document"
AND ANY v IN b.test_key SATISFIES v.company_id IN ["1234", "5678"] END;