Given 20k documents of this shape:
{
"type": "report",
"id": "12345",
"answers": [
{
"q": "question1",
"v": "123",
"lbl": "Yes"
},
{
"q": "question2",
"v": "234",
"lbl": "No"
}
]
}
And given this very simple query:
SELECT id,
ARRAY a.v FOR a IN answers WHEN a.q = 'question1' END AS myAnswer
FROM bucket
WHERE type = 'report'
ORDER BY myAnswer
As soon as I add the ORDER BY
clause, performance slows to a crawl (from 50ms to over 10 seconds).
I can find no way to create ANY index which will improve performance. I can create indexes for root-level properties (like type
and id
) that work, but none that improve sorting on answer.v
I tried filtering the results such that myAnswer
is not null, but this didn’t help:
SELECT id,
ARRAY a.v FOR a IN answers WHEN a.q = 'question1' END AS myAnswer
FROM bucket
WHERE type = 'report'
--- doesn't help
AND ANY a IN answers SATISFIES a.q='question1' AND a.v IS NOT NULL END
ORDER BY myAnswer
How on earth can I create an index that will improve sorting on answer.v
?