Hi, I am having performance issues on a similar scenario. I have a membase bucket with barely 2,000 documents and the following indexes:
CREATE INDEX id_ix
ON couch
((meta().id
))
CREATE PRIMARY INDEX #primary
ON couch
I want to “operate” on all items who’s key starts with a specific prefix using N1QL, so I’m running a query as such:
SELECT * FROM couch WHERE META(couch).id LIKE ‘local.pre%’ -> 160ms
SELECT COUNT(*) FROM couch WHERE META(couch).id LIKE ‘local.pre%’ -> 35ms
On our production servers, where the buckets are much more full, these operations take > 20seconds.
Using EXPLAIN shows that the indexes are being used, so I don’t really understand how can this be so slow.
This is affecting the Drupal Couchbase integration that I maintain: https://www.drupal.org/project/couchbasedrupal
[
{
“plan”: {
"#operator": “Sequence”,
"~children": [
{
"#operator": “IndexScan”,
“covers”: [
“cover ((meta(couch
).id
))”,
“cover ((meta(couch
).id
))”
],
“index”: “id_ix”,
“index_id”: “321ddc05c6122a67”,
“keyspace”: “couch”,
“namespace”: “default”,
“spans”: [
{
“Range”: {
“High”: [
"“local.prf”"
],
“Inclusion”: 1,
“Low”: [
"“local.pre”"
]
}
}
],
“using”: “gsi”
},
{
"#operator": “Parallel”,
"~child": {
"#operator": “Sequence”,
"~children": [
{
"#operator": “Filter”,
“condition”: “(cover ((meta(couch
).id
)) like “local.pre%”)”
},
{
"#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”
}
]
}
}
]
},
“text”: “SELECT COUNT(*) FROM couch WHERE META(couch).id LIKE ‘local.pre%’”
}
]