Hi,
Following is the document which I get after running explain on one of the query.
[
{
“plan”: {
"#operator": “Sequence”,
"~children": [
{
"#operator": “DistinctScan”,
“scan”: {
"#operator": “IndexScan”,
“index”: “activity_pins”,
“index_id”: “2c66f03e9193a364”,
“keyspace”: “activity”,
“namespace”: “default”,
“spans”: [
{
“Range”: {
“High”: [
"“atlas”"
],
“Inclusion”: 3,
“Low”: [
"“atlas”"
]
}
},
{
“Range”: {
“High”: [
"“review”"
],
“Inclusion”: 3,
“Low”: [
"“review”"
]
}
}
],
“using”: “gsi”
}
},
{
"#operator": “Fetch”,
“keyspace”: “activity”,
“namespace”: “default”
},
{
"#operator": “Parallel”,
"~child": {
"#operator": “Sequence”,
"~children": [
{
"#operator": “Unnest”,
“as”: “pin”,
“expr”: “(activity.pins)”
},
{
"#operator": “Filter”,
“condition”: “((((pin.pin_type) in [“review”, “atlas”]) and ((pin.place_id) = “MMI000”)) and ((pin.status) in [0, “0”]))”
},
{
"#operator": “InitialGroup”,
“aggregates”: [
“count((pin.pin_id))”,
“sum((pin.pin_rate))”
],
“group_keys”: [
"(pin.pin_type)"
]
}
]
}
},
{
"#operator": “IntermediateGroup”,
“aggregates”: [
“count((pin.pin_id))”,
“sum((pin.pin_rate))”
],
“group_keys”: [
"(pin.pin_type)"
]
},
{
"#operator": “FinalGroup”,
“aggregates”: [
“count((pin.pin_id))”,
“sum((pin.pin_rate))”
],
“group_keys”: [
"(pin.pin_type)"
]
},
{
"#operator": “Parallel”,
"~child": {
"#operator": “Sequence”,
"~children": [
{
"#operator": “InitialProject”,
“result_terms”: [
{
“as”: “total_pin”,
“expr”: “count((pin.pin_id))”
},
{
“as”: “total_rating”,
“expr”: “sum((pin.pin_rate))”
},
{
“expr”: “(pin.pin_type)”
}
]
},
{
"#operator": “FinalProject”
}
]
}
}
]
},
“text”: “SELECT COUNT(pin.pin_id) AS total_pin,SUM(pin.pin_rate) AS total_rating, pin.pin_type FROM activity UNNEST activity.pins AS pin WHERE pin.pin_type IN[‘review’,‘atlas’] AND \npin.place_id=‘MMI000’ AND pin.status IN [0,‘0’] GROUP BY pin.pin_type;”
}
]
This query is taking some where aroung 200ms what should I do to optimize it, I have already done indexing on one of the field. what more should be done to optimize it.