Dear all,
I have a question about using indexes with tokens and satisifes condition in WHERE clause.
My bucket is made by document in which we have a field called searchKeyA as an array of strings (they are all keywords).
We want to search all documents whose searchKeyA contains every word passed as a parameter.
As an example, a parameter string can be “alfa beta gamma” and we need to get documents that have both alfa, beta, gamma in the searchKeyA field.
So, we first built an index on searchKeyA as following:
create index idx_searchKeyA on docs_bucket(searchKeyA) using gsi;
Now, we want to fetch documents with queries like the following:
select *
from docs_bucket
where every v in tokens("alfa beta gamma") satisfies v in searchKeyA end;
If we run the explain command we get a plan like this:
"plan": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "PrimaryScan",
"index": "#primary",
"keyspace": "docs_bucket",
"namespace": "default",
"using": "gsi"
},
{
"#operator": "Fetch",
"keyspace": "docs_bucket",
"namespace": "default"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Filter",
"condition": "every `v` in tokens(\"alfa beta gamma\") satisfies (`v` in (`docs_bucket`.`searchKeyA`)) end"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "self",
"star": true
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
}
]
}
Why we are getting a PrimaryScan operation for this query?
Is there a better way to run queries like this?
Thank you for your precious help,
Stefano