Hi.
I have added one “group” document to the bucket that looks like this
{
"groupName": "name",
"members": [{ "name": "username", /* other properties */ }] // 100K elements (for testing)
}
That ‘members’ array will contain a lot of members, so in order for the quick access I’m going to use array index:
CREATE INDEX IDX_group_member_name
ON bucket_name (DISTINCT ARRAY member.name FOR member IN members end, members)
Index is created and all good, but when I execute following query
SELECT member.*
FROM bucket_name
UNNEST members AS member
WHERE member.name = 'username'
nothing is returned.
Explain
{
"plan": {
"#operator": "Sequence",
"~children": [
{
"#operator": "DistinctScan",
"scan": {
"#operator": "IndexScan2",
"covers": [
"cover ((distinct (array (`member`.`name`) for `member` in (`bucket_name`.`members`) end)))",
"cover ((`bucket_name`.`members`))",
"cover ((meta(`bucket_name`).`id`))"
],
"index": "IDX_group_member_name",
"index_id": "318646e3f270ddb0",
"index_projection": {
"entry_keys": [
1
],
"primary_key": true
},
"keyspace": "bucket_name",
"namespace": "default",
"spans": [
{
"exact": true,
"range": [
{
"high": "\"username\"",
"inclusion": 3,
"low": "\"username\""
}
]
}
],
"using": "gsi"
}
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Unnest",
"as": "member",
"expr": "cover ((`bucket_name`.`members`))"
}
]
}
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Filter",
"condition": "((`member`.`name`) = \"username\")"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "`member`",
"star": true
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
},
"text": "select member.*\r\nfrom bucket_name\r\nunnest members as member\r\nwhere member.name = \"username\""
}
However when I add USE KEYS (“group”) the correct result is returned.
Please, advice.