Hi,
Thanks for your support
I suspect that when query need to return more documents it takes more time. For example if query found only 50 matched documents it takes 10 seconds, but if it found 10000 matched document it takes 60 seconds. I always limit it to 10000 documents since this is the maximum that my application need per query (no paging allowed since I need all the data per query call).
I created 3 indexes:
- document primery key
Definition: CREATE PRIMARY INDEX #primary ON suspectentity USING GSI
- by time and channelid
Definition: CREATE INDEX IndexBasic ON suspectentity(time
,channelId
) USING GSI
- by additional metadata properties
Definition: CREATE INDEX IndexMetadata ON suspectentity((metadata
.clothingShirtColor
),(metadata
.clothingPantsColor
),(metadata
.faceBeard
),(metadata
.faceEyeglasses
),(metadata
.faceHairColor
),(metadata
.faceHat
),(metadata
.faceMustache
),(metadata
.height
)) USING GSI
see the EXPLAIN:
cbq.exe> {6-01-19T12:00’ and channelId=12 and metadata.faceHat=true and metadata.faceBeard=false and metadata.clothingShirtColor=1 and metadata.clothingPantsColor=1 LIMIT 10000;
{
“requestID”: “53779823-ff46-49b3-990d-bb48271c2f00”,
“signature”: “json”,
“results”: [
{
"#operator": “Sequence”,
"~children": [
{
"#operator": “Sequence”,
"~children": [
{
"#operator": “IntersectScan”,
“scans”: [
{
"#operator": “IndexScan”,
“index”: “IndexBasic”,
“keyspace”: “suspectentity”,
“limit”: 9.223372036854776e+18,
“namespace”: “default”,
“spans”: [
{
“Range”: {
“High”: [
"“2016-01-19T12:00"”,
“12”
],
“Inclusion”: 3,
“Low”: [
"“2016-01-19T09:00"”,
“12”
]
},
“Seek”: null
}
],
“using”: “gsi”
},
{
"#operator": “IndexScan”,
“index”: “IndexMetadata”,
“keyspace”: “suspectentity”,
“limit”: 9.223372036854776e+18,
“namespace”: “default”,
“spans”: [
{
“Range”: {
“High”: [
“1”,
“1”,
“successor(false)”
],
“Inclusion”: 1,
“Low”: [
“1”,
“1”,
“false”
]
},
“Seek”: null
}
],
“using”: “gsi”
}
]
},
{
"#operator": “Parallel”,
"~child": {
"#operator": “Sequence”,
"~children": [
{
"#operator": “Fetch”,
“keyspace”: “suspectentity”,
“namespace”: “default”
},
{
"#operator": “Filter”,
“condition”: “(((((((“2016-01-19T09:00” \u003c= (suspectentity
.time
)) and ((suspectentity
.time
) \u003c= “2016-01-19T12:00”)) and
((suspectentity
.channelId
) = 12)) and (((suspectentity
.metadata
).faceHat
) = true)) and (((suspectentity
.metadata
).faceBeard
) = false)) and (((suspectentity
.meta data
).clothingShirtColor
) = 1)) and (((suspectentity
.metadata
).clothingPantsColor
) = 1))”
},
{
"#operator": “InitialProject”,
“result_terms”: [
{
“expr”: “(suspectentity
.id
)”
},
{
“expr”: “(suspectentity
.time
)”
},
{
“expr”: “(suspectentity
.signature
)”
}
]
},
{
"#operator": “FinalProject”
}
]
}
}
]
},
{
"#operator": “Limit”,
“expr”: “10000”
}
]
}
],
“status”: “success”,
“metrics”: {
“elapsedTime”: “15.0141ms”,
“executionTime”: “15.0141ms”,
“resultCount”: 1,
“resultSize”: 5340
}
}