Hi All,
I’m using Couchbase 6.5.1 CE
and trying to do simple select query count:
SELECT COUNT(*)
FROM myBucket myTable
WHERE myTable.SRC_TABLE_NAME = ‘myTable’
AND myTable.flag =‘T’
AND myTable.valid <> ‘2’
;
result is 42.7 s
with total data in myBucket is 20 mio
and the query count result is 5.999.199
This is my index:
CREATE INDEX idx_count_test ON
myBucket
(flag
,num
,to_number(amount
)) PARTITION BY HASH((meta().id
)) WHERE ((SRC_TABLE_NAME
= ‘myTable’) and (not (valid
= ‘2’)))
This is the explain plan:
{
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “IndexScan3”,
“as”: “myTable”,
“covers”: [
“cover ((myTable
.flag
))”,
“cover ((myTable
.num
))”,
“cover (to_number((myTable
.amount
)))”,
“cover ((meta(myTable
).id
))”
],
“filter_covers”: {
“cover ((myTable
.SRC_TABLE_NAME
))”: “myTable”,
“cover ((not ((myTable
.valid
) = "2")))”: true
},
“index”: “idx_count_test”,
“index_id”: “a8fc937bc85358e0”,
“index_projection”: {
“entry_keys”: [
0
]
},
“keyspace”: “myBucket”,
“namespace”: “default”,
“spans”: [
{
“exact”: true,
“range”: [
{
“high”: “"T"”,
“inclusion”: 3,
“low”: “"T"”
}
]
}
],
“using”: “gsi”
},
{
“#operator”: “Parallel”,
“~child”: {
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “Filter”,
“condition”: “(((cover ((myTable
.SRC_TABLE_NAME
)) = "myTable") and (cover ((myTable
.flag
)) = "T")) and cover ((not ((myTable
.valid
) = "2"))))”
},
{
“#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”
}
]
}
}
]
}
How to speed up this query?
I have tried using partition but still too slow
Thanks