(
&mut self,
task: &ExecutionTask,
tid: u64,
collection: &str,
group_by: &[String],
aggregates: &[AggregateSpec],
filters: &[u8],
having
| 170 | impl CoreLoop { |
| 171 | #[allow(clippy::too_many_arguments)] |
| 172 | pub(in crate::data::executor) fn execute_aggregate( |
| 173 | &mut self, |
| 174 | task: &ExecutionTask, |
| 175 | tid: u64, |
| 176 | collection: &str, |
| 177 | group_by: &[String], |
| 178 | aggregates: &[AggregateSpec], |
| 179 | filters: &[u8], |
| 180 | having: &[u8], |
| 181 | limit: usize, |
| 182 | sub_group_by: &[String], |
| 183 | sub_aggregates: &[AggregateSpec], |
| 184 | grouping_sets: &[Vec<u32>], |
| 185 | sort_keys: &[(String, bool)], |
| 186 | ) -> Response { |
| 187 | debug!(core = self.core_id, %collection, group_fields = group_by.len(), aggs = aggregates.len(), "aggregate"); |
| 188 | |
| 189 | // ROLLUP / CUBE / GROUPING SETS path: union results from each set. |
| 190 | if !grouping_sets.is_empty() { |
| 191 | return super::grouping_sets_exec::execute_grouping_sets( |
| 192 | self, |
| 193 | task, |
| 194 | tid, |
| 195 | collection, |
| 196 | group_by, |
| 197 | aggregates, |
| 198 | filters, |
| 199 | having, |
| 200 | limit, |
| 201 | grouping_sets, |
| 202 | ); |
| 203 | } |
| 204 | |
| 205 | // Fast path: incremental aggregate cache. |
| 206 | if filters.is_empty() && having.is_empty() { |
| 207 | let cache_key = aggregate_cache_key( |
| 208 | tid, |
| 209 | collection, |
| 210 | group_by, |
| 211 | aggregates, |
| 212 | sub_group_by, |
| 213 | sub_aggregates, |
| 214 | ); |
| 215 | if let Some(cached) = self.aggregate_cache.get(&cache_key) { |
| 216 | debug!(core = self.core_id, %collection, "aggregate cache hit"); |
| 217 | return self.response_with_payload(task, cached.clone()); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // Fast path: index-backed COUNT/GROUP BY. |
| 222 | if group_by.len() == 1 |
| 223 | && filters.is_empty() |
| 224 | && having.is_empty() |
| 225 | && aggregates.len() == 1 |
| 226 | && aggregates[0].expr.is_none() |
| 227 | && aggregates[0].function == "count" |
| 228 | { |
| 229 | let field = &group_by[0]; |
no test coverage detected