I need help to figure-out why my query is not using indexCountScan. I am using couchbase 4.0.0 version.
I have created below index:
CREATE INDEX indx_org ON ctmonitor_t(organizationName
) USING GSI
My query is as below:
select count(*) from ctmonitor_t use index(indx_org) where organizationName!=‘DHRUV’;
I get below plan in explain:
cbq.exe> explain select count() from ctmonitor_t use index(indx_org) where organizationName!=‘DHRUV’;
{
“requestID”: “d265bbeb-efdd-4d1c-b00d-3cbbb5510333”,
“signature”: “json”,
“results”: [
{
"#operator": “Sequence”,
"~children": [
{
"#operator": “UnionScan”,
“scans”: [
{
"#operator": “IndexScan”,
“index”: “indx_org”,
“keyspace”: “ctmonitor_t”,
“limit”: 9.223372036854776e+18,
“namespace”: “default”,
“spans”: [
{
“Range”: {
“High”: [
"“DHRUV”"
],
“Inclusion”: 0,
“Low”: null
},
“Seek”: null
},
{
“Range”: {
“High”: null,
“Inclusion”: 0,
“Low”: [
"“DHRUV”"
]
},
“Seek”: null
}
],
“using”: “gsi”
}
]
},
{
"#operator": “Parallel”,
"~child": {
"#operator": “Sequence”,
"~children": [
{
"#operator": “Fetch”,
“keyspace”: “ctmonitor_t”,
“namespace”: “default”
},
{
"#operator": “Filter”,
“condition”: “(not ((ctmonitor_t
.organizationName
) = “DHRUV”))”
},
{
"#operator": “InitialGroup”,
“aggregates”: [
"count()"
],
“group_keys”: []
}
]
}
},
{
"#operator": “IntermediateGroup”,
“aggregates”: [
“count()"
],
“group_keys”: []
},
{
"#operator": “FinalGroup”,
“aggregates”: [
"count()”
],
“group_keys”: []
},
{
"#operator": “Parallel”,
"~child": {
"#operator": “Sequence”,
"~children": [
{
"#operator": “InitialProject”,
“result_terms”: [
{
“expr”: “count(*)”
}
]
},
{
"#operator": “FinalProject”
}
]
}
}
]
}
],
“status”: “success”,
“metrics”: {
“elapsedTime”: “2.0002ms”,
“executionTime”: “2.0002ms”,
“resultCount”: 1,
“resultSize”: 3727
}
}
As per my understanding couchbase should lookup indexes and give me a count without reading the documents on disk. But the server graphs show that it is reading the documents also.