MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / execute_aggregate

Method execute_aggregate

nodedb/src/data/executor/handlers/aggregate.rs:172–601  ·  view source on GitHub ↗
(
        &mut self,
        task: &ExecutionTask,
        tid: u64,
        collection: &str,
        group_by: &[String],
        aggregates: &[AggregateSpec],
        filters: &[u8],
        having

Source from the content-addressed store, hash-verified

170impl 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];

Callers 1

dispatch_queryMethod · 0.80

Calls 15

execute_grouping_setsFunction · 0.85
aggregate_cache_keyFunction · 0.85
canonical_agg_keyFunction · 0.85
write_kv_strFunction · 0.85
write_kv_i64Function · 0.85
legacy_aggregate_pairsFunction · 0.85
try_columnar_aggregateFunction · 0.85
json_to_msgpack_or_emptyFunction · 0.85
sort_aggregated_rowsFunction · 0.85
encode_json_vecFunction · 0.85
build_group_key_indexedFunction · 0.85

Tested by

no test coverage detected