Hi @vsr1 ,
I need help with index for the below query
SELECT MAX([ instance.expiryTime, { page, instance , ‘_ID’: META(instance).id, ‘_CAS’:META(instance).cas }])[1].*
FROM a-bucket AS instance
JOIN a-bucket AS page ON (instance.pageId = page.pageId)
WHERE page.type = ‘page’
AND page.clientId = “demo”
AND instance.isStacked = FALSE
AND instance.pageId IN [“facebook”]
AND instance.clientId = demo"
AND instance.type = ‘pagedef’
AND ((instance.effectiveTime <= 1616514296114
AND 1616514296114 <= instance.expiryTime)
OR (instance.effectiveTime <= 1616514296114
AND instance.expiryTime IS NULL)
OR (page.allowPastInstance = true
AND instance.effectiveTime <= 1616514296114))
GROUP BY instance.pageId
Current Indexes used are
CREATE INDEX index_instance ON a-bucket(clientId,isStacked,pageId,effectiveTime,expiryTime) WHERE (type = ‘pagedef’
CREATE INDEX fragment_cache ON a-bucket(type,clientId)
CREATE INDEX index_page ON a-bucket(clientId,externalId,pageId) WHERE (type = ‘page’)
This is taking a lot of time around 2 seconds to get the result.
If I remove the below OR condition from the above query
OR (page.allowPastInstance = true
AND instance.effectiveTime <= 1616514296114)
the time comes drastically down to 65ms.
No of approx. documents in the Db : 20000
Can you suggest how can I modify my indexes , I need to keep that OR condition.