I am having trouble getting my query to use the right index and I am wondering what I am doing something wrong with either my query or my index.
Here is the query I am running:
SELECT RAW cd.chargeCategoryIds
FROM app cd
WHERE cd.type = "chargeDscrp"
AND cd.chargeCategoryIds IS VALUED AND cd.chargeCategoryIds != []
GROUP BY chargeCategoryIds
ORDER BY chargeCategoryIds
This is the shape of the documents I am querying:
{
"chargeCategoryIds": [
"chargeCat-1",
"chargeCat-2",
"chargeCat-3"
],
"createdDate": "2021-01-06T06:36:21.6380541+00:00",
"description": null,
"docId": "chargeDscrp-1234",
"lastModified": "2021-04-07T06:13:39.1283129+00:00",
"schemaVer": "2021.4.5.1",
"tenantName": "MyTenant",
"tokens": [],
"type": "chargeDscrp"
}
This is the index I want it to use:
CREATE INDEX app_idx_chargeDscrp_chargeCategoryIds_distinct
ON app
((distinct (array t
for t
in chargeCategoryIds
end))) WHERE (type
= “chargeDscrp”)
This is the index it ends up using which is very slow:
CREATE INDEX app_part_idx_doc_type_tenant
ON app
(type
,tenantName
)