Expand description
Average-query dispatcher entry point.
Routes a DocumentAverageRequest to one of two backends:
- No-prove path → delegates to the joint count-and-sum
dispatcher
Drive::execute_document_count_and_sum_request, which walks grovedb ONCE and reads both metrics from each visited count-sum-bearing element viagrovedb::Element::count_sum_value_or_default. See its module docstring for the routing / atomicity contract. - Prove path → dispatched to
Drive::execute_document_average_prove(defined below), which routes to one of the PCPS / direct-read prove executors based on(mode, where_clauses). The prove path’s per-shape rules are unchanged.
§Joint dispatch
The no-prove dispatcher at
crate::query::drive_document_count_and_sum_query reads
(count, sum) together — via grovedb’s combined
query_aggregate_count_and_sum accumulator on the aggregate range
branch, and via a single PCPS walk on the distinct-grouped branch.
Routing reuses sum’s versioned mode-detection table so the
(where_clauses × mode) → executor decision has a single source
of truth shared with the count and sum surfaces.
§Prove path shapes (unchanged)
The prove-path routing table at
[Self::execute_document_average_prove] picks one of:
- empty-where + documentsCountable + documentsSummable
doctype → primary-key count-sum tree direct read
- range AVG on a rangeAverageable index → PCPS
AggregateCountAndSumOnRange proof
- In + range AVG on a rangeAverageable index → carrier-PCPS
proof
- GroupByRange / GroupByCompound + range on a
rangeAverageable index → per-distinct-key
count-and-sum proof (walks ProvableCountProvableSumTree
terminators)
- Equal/In + no range on a summable + countable index →
point-lookup count-and-sum proof (walks count-sum-bearing
terminator elements)
The client verifies with the matching
verify_*_count_and_sum_proof helpers in drive-proof-verifier.