Hello there!
I’m currently working on optimizing a query that involves the usage of LEFT NEST. This query is used to search through the contacts collection, which can have a variety of attribute conditions. Additionally, it may also have conditions related to events that have occurred with these contacts.
The query:
SELECT res.attributes
FROM (
SELECT c.customerId,
c.attributes,
ARRAY v FOR v IN e WHEN v.name='PaymentAccepted'
AND (v.data.`price`>100
AND v.data.`currency`='GBP') END AS events_1
FROM `contacts-pool-5` c LEFT NEST `contact-events-pool-5` e ON c.attributes.nxId = e.contactId
WHERE c.customerId=$customerId) AS res
WHERE res.customerId=$customerId
AND (LOWER(res.attributes.`email`) LIKE '%zog.na%'
AND ARRAY_LENGTH(events_1) >= 1)
LIMIT 10
The execution plan:
type or paste code here