Hi,
Given the document structure:
{ "id" : "123", "type" : "data", "value" : "some value", "created" : 1478109980000, owner : "some username"}
And created index:
CREATE INDEX
owner_type_created_descON
sensorbucket(
owner,
type,(-
created)) USING GSI
When I run following query it runs really slow:
select * from sensorbucket use index (owner_type_created_desc) where owner = 'milan' and type = 'data' and created >= 1481719427523;
Here’s the explain output:
{
"requestID": "d940371a-41a5-491a-85ed-ec99fa9d23e2",
"signature": "json",
"results": [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "IndexScan",
"index": "owner_type_created_desc",
"keyspace": "sensorbucket",
"namespace": "default",
"spans": [
{
"Range": {
"High": [
"\"milan\"",
"successor(\"data\")"
],
"Inclusion": 1,
"Low": [
"\"milan\"",
"\"data\""
]
}
}
],
"using": "gsi"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Fetch",
"keyspace": "sensorbucket",
"namespace": "default"
},
{
"#operator": "Filter",
"condition": "((((`sensorbucket`.`owner`) = \"milan\") and ((`sensorbucket`.`type`) = \"data\")) and (1481719427523 \u003c= (`sensorbucket`.`created`)))"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "self",
"star": true
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
}
],
"status": "success",
"metrics": {
"elapsedTime": "1.91893ms",
"executionTime": "1.876985ms",
"resultCount": 1,
"resultSize": 2217
}
But when I add limit that is smaller than the number of available results:
select * from sensorbucket use index (owner_type_created_desc) where owner = 'milan' and type = 'data' and created >= 1481719427523 limit 5;
it runs 10 times faster. I guess that in that case the query actually utilizes the index. If I omit ‘limit’ clause, or if limit is larger than the number of results that satisfy the query in that case the query is slow.
Am I missing something?