Hi All,
Query1 is having one field in where clause f.Product.siteId , that is not present in the secondary index Index1 but still, Index1 is used for Query1 but not for Query2.
Query1 is having one field in where clause that is present in Index1, but Query2 doesn’t have anything common with Index1
Can someone please explain, how this Index is working and what is behind Couchbase mechanism used to resolve this query?
Index1 -
CREATE INDEX idx_bucket1
ON bucket
(Product
.Id
,Product
.p_Id
)
Query 1 -
SELECT * FROM bucket
AS f
WHERE LOWER(f.Product.Id) = ‘x’ AND f.Product.siteId =‘Y’
Query 2-
SELECT * FROM bucket
AS f
WHERE f.Product.siteId =‘Y’
Explain for query - 1
{
“plan”: {
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “IndexScan3”,
“as”: “f”,
“index”: “idx_bucket1”,
“index_id”: “64f505705132ec25”,
“index_projection”: {
“primary_key”: true
},
“keyspace”: “bucket”,
“namespace”: “default”,
“spans”: [
{
“range”: [
{
“inclusion”: 0,
“low”: “null”
}
]
}
],
“using”: “gsi”
},
{
“#operator”: “Fetch”,
“as”: “f”,
“keyspace”: “bucket”,
“namespace”: “default”
},
{
“#operator”: “Parallel”,
“~child”: {
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “Filter”,
“condition”: “((lower(((f
.Product
).Id
)) = “x”) and (((f
.Product
).siteId
) = “Y”))”
},
{
“#operator”: “InitialProject”,
“result_terms”: [
{
“expr”: “self”,
“star”: true
}
]
},
{
“#operator”: “FinalProject”
}
]
}
}
]
},
“text”: “SELECT * FROM bucket
AS f
WHERE LOWER(f.Product.Id) = ‘x’ AND f.Product.siteId =‘Y’”
}
Any help would be greatly appreciated.
Regards,
Naveen Nisad