Hello, we are executing a select query via N1QL over a very large data set. We are looking to fetch the last 10 records.
The query is taking much too long, could you please advice on improving the query or the index?
(Assuming we have to select all fields and can’t use a covering index
)
Many thanks in advance!
SELECT * FROM conversationWHERE (type = 'leg' AND application_id = 'bbf7b41e-9a87-471a-8627-98c6cfeb5ae5' ) ORDER BYtimestamp.start DESC LIMIT 10 OFFSET 0
The used index (leg_application_idx3):
Definition: CREATE INDEX leg_application_idx3ONconversation(type,application_id) WHERE (type = "leg")
We are using couchbase 4.5.
Execution plan:
[
{
“plan”: {
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “IndexScan”,
“index”: “leg_application_idx3”,
“index_id”: “79b31bc04629774f”,
“keyspace”: “conversation”,
“namespace”: “default”,
“spans”: [
{
“Range”: {
“High”: [
“"leg"”,
“successor("bbf7b41e-9a87-471a-8627-98c6cfeb5ae5")”
],
“Inclusion”: 1,
“Low”: [
“"leg"”,
“"bbf7b41e-9a87-471a-8627-98c6cfeb5ae5"”
]
}
}
],
“using”: “gsi”
},
{
“#operator”: “Parallel”,
“~child”: {
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “Fetch”,
“keyspace”: “conversation”,
“namespace”: “default”
},
{
“#operator”: “Filter”,
“condition”: “(((conversation.type) = "leg") and ((conversation.application_id) = "bbf7b41e-9a87-471a-8627-98c6cfeb5ae5"))”
},
{
“#operator”: “InitialProject”,
“result_terms”: [
{
“expr”: “self”,
“star”: true
}
]
}
]
}
}
]
},
{
“#operator”: “Order”,
“limit”: “10”,
“offset”: “0”,
“sort_terms”: [
{
“desc”: true,
“expr”: “((conversation.timestamp).start)”
}
]
},
{
“#operator”: “Offset”,
“expr”: “0”
},
{
“#operator”: “Limit”,
“expr”: “10”
},
{
“#operator”: “FinalProject”
}
]
},
“text”: “SELECT * FROMconversationWHERE (type = ‘leg’ AND application_id = ‘bbf7b41e-9a87-471a-8627-98c6cfeb5ae5’) ORDER BYtimestamp.startDESC LIMIT 10 OFFSET 0”
}
]