Hello everyone,
I’ve been struggling with a certain query for some time now and that’s why I decided I should discuss it here in order to find a solution. It’s a N1QL related issue.
I have this schema:
{
“attribute1” : “test”,
“attribute2” : “test”,
“array1” : [
{
“nestedAttr” : “SUF1”
},
{
“nestedAttr” : “SUF2”
},
],
“array2” : [
{
“nestedAttr” : “SUF1”
},
{
“nestedAttr” : “SUF2”
},
]
}
The query I am trying to run is this:
SELECT *
FROM default
WHERE attribute1 = “test”
AND attribute2 = “test”
AND
(
ANY arr1 IN array1 SATISFIES arr1.nestedAttr
= ‘SUF1’ END
OR ANY arr2 IN array2 SATISFIES arr2.nestedAttr
= ‘SUF1’ END
)
I have created two indexes for this query:
CREATE INDEX default_nested_index_1
ON default
(attribute1
,attribute2
,(all (array (arr1
.nestedAttr
) for arr1
in array1
end)))
CREATE INDEX default_nested_index_2
ON default
(attribute1
,attribute2
,(all (array (arr2
.nestedAttr
) for arr2
in array2
end)))
Now when I search only in the first array1 it works and the proper index is being used. But when I try the two arrays it doesnt use the two indexes and its taking a lot of time to execute.
Any ideas?