arXiv:2610.13756cs.DBOct 2026

Manuscript Offprint

arXiv:2610.13756

ProvQML: Efficient Provenance Capture for Machine Learning as Recursive Aggregate SQL [Extended Version]

Nkechi J. Akinwale, Seokki Lee

NKECHI J. AKINWALE, University of Cincinnati, USA

SEOKKI LEE, University of Cincinnati, USA

Expressing ML algorithms as recursive aggregate SQL queries over distributed systems enables large-scale declarative data analytics, yet no existing system supports scalable provenance capture, necessary for ML explainability. We present ProvQML, a provenance-aware recursive aggregate SQL engine that efficiently captures fine-grained provenance while evaluating ML algorithms as recursive aggregate queries. We capture two types of provenance: (i) local provenance that records the contribution of each training instance to gradient computation at a specific model state, and (ii) global provenance that encodes the sequence of model parameter updates across the iterations. Extensive experiments on widely used ML datasets demonstrate that our approach efficiently captures both provenance for various ML models over widely used ML datasets.

CCS Concepts: • Information systems → Relational database query languages.

Additional Key Words and Phrases: Provenance, Declarative Machine Learning, Aggregate in Recursion

ACM Reference Format:

Nkechi J. Akinwale and Seokki Lee. 2026. ProvQML: Efficient Provenance Capture for Machine Learning as Recursive Aggregate SQL [Extended Version]. Proc. ACM Manag. Data 1, 1 (October 2026), 29 pages. https://doi.org/10.1145/nnnnnnn.nnnnnnn

1 Introduction

Expressing ML algorithms as recursive aggregate SQL queries over distributed systems such as Apache Spark has gained traction [40, 48]. For iterative ML tasks, aggregation within recursion is essential for fixpoint convergence [50]. There is also an increasing need for ML explainability [24, 30, 43]. In the context of ML as a declarative query, explainability of ML aligns with the database community's long-standing work on explaining query results [4, 6, 7, 9, 25, 27, 32]. These studies rely on provenance, the record of how a query result is derived from input tuples, which is a well-studied method for such explanations. For ML queries, [3, 45] envision that provenance can trace how training instances drive model parameter updates, supporting model validation and debugging. It also enables the possibility of computing feature importance [24, 30], which quantifies each feature's statistical contribution to the trained model. Despite this, no existing system supports scalable provenance capture for recursive aggregate SQL that is needed for ML explainability.

EXAMPLE 1 (MOTIVATING EXAMPLE). Figure 1 shows a sample of the ACS Income dataset, 1^{1} which records demographic and employment attributes, including class of work (CWork) and occupation category (OCat) along with a binary income label (Y = 1 if annual income exceeds 50,000, 0 otherwise), 1^{1}https://fairlearn.org/main/user_guide/datasets/acs_income

Authors' Contact Information: Nkechi J. Akinwale, University of Cincinnati, USA, akwarinj@mail.uc.edu; Seokki Lee, University of Cincinnati, USA, lee5sk@ucmail.uc.edu.

Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from permissions@acm.org.

© 2026 Copyright held by the owner/author(s). Publication rights licensed to ACM.

ACM 2836-6573/2026/10-ART

https://doi.org/10.1145/nnnnnnn.nnnnnnn

Nkechi J. Akinwale and Seokki Lee

Input training data T\mathcal{T}

ICVY
1Age461
1CWork11
1OCat17601
1Education241
1Sex11
1Race11
2Age450
2CWork60
⋮\vdots⋮\vdots⋮\vdots⋮\vdots

Optimized weights

CPJ
Age15.4500100
CWork-0.4633100
OCat-24.1800100
Education11.5067100
Sex0.4367100
Race-0.4067100

Fig. 1. ACSIncome data T\mathcal{T} [11] (verticalized and pre-processed), and trained model parameters (results) over 100 iterations (J=100J = 100).

Figure

Fig. 2. Overview of ProvQML query evaluation for the running example

which is reinterpreted as a loan approval outcome. The input data T\mathcal{T} is stored in a verticalized format where each feature and its value of an instance appear as a tuple. We will revisit the verticalization in Section 2. Tom, an analyst at a bank, uses logistic regression model to determine the loan approval outcomes, and the optimized model's weights are shown in the figure. His manager raises a concern that loan approvals from the first half the year disproportionately favor a particular racial group. The model weights alone are insufficient to diagnose the cause, e.g., Race has one of the lowest weights, so Tom needs to trace which training instances drove the weight updates at each iteration.

In this paper, we present ProvQML, a provenance-aware recursive aggregate SQL engine built on top of Apache Spark that instruments input queries expressing ML algorithms, e.g., [48], to efficiently capture fine-grained provenance while evaluating a broad range of such algorithms. Unlike [48], which requires mutual and non-linear recursion with multiple aggregates, ProvQML

ProvQML: Efficient Provenance Capture for Machine Learning as Recursive Aggregate SQL [Extended Version]

3

uses standard linear recursion with window functions, requiring no new recursion constructs, that can be evaluated in standard (distributed) database systems with a minimal extension. The correctness of ProvQML's query rewriting and optimization relies on two properties established by prior work [17, 48, 50]. The Pre-Mappability (PreM) property [17, 50] gives conditions under which extrema aggregates (min, max) can be pushed into recursion while producing the same result as the equivalent aggregate-stratified program. For non-extrema aggregates (sum, avg), the Pre-Countable Cardinality (PCC) property [48] guarantees correctness when the delta relation's cardinality is constant across iterations and pre-computable which is a condition ML workloads such as batch gradient descent satisfy naturally. Figure 2 gives an overview of ProvQML's query evaluation pipeline.

Provenance capture via query rewriting. The top of Figure 2 shows ProvQML instruments the input ML query QMLQ_{ML} expressing Tom's logistic regression model in SQL (Example 1) into a rewritten query QML′Q'_{ML} computing the optimized model's weights and their provenance. We will explain the details of QMLQ_{ML} and QML′Q'_{ML} in Section 2 and Section 4, respectively. The formulation of ML queries based on prior work [48] involves mutual and non-linear recursion (highlighted on QMLQ_{ML}), which makes direct provenance instrumentation prohibitively expensive. It increases the number of recursions as provenance capture for aggregate query requires to join with its input relations. The ProvQML's instrumentation consists of two phases: (i) detecting mutually recursive and non-linearly recursive relations on QMLQ_{ML}, then (ii) collapsing them into a single linear recursive relation whose recursive case expresses intermediate computations as a sequential chain of provenance subqueries using window functions. PreM ensures that aggregates in the rewritten recursive case can be pushed into the recursion without altering the fixpoint, and PCC ensures QML′Q'_{ML} converges to the same result as QMLQ_{ML}. The rewritten query captures two types of provenance, as shown in the bottom half of Figure 2. Local provenance PLP_{L} records each training instance's contribution to gradient computation at a specific model state by capturing the per-instance prediction PrediPred_i, the per-instance gradient contribution GradiGrad_i, and the aggregated gradient Grad. For example, for the first customer Age = 46 annotated with t1t_1, ProvQML computes provenance for the per-instance prediction Pred1=YP1=1/(1+exp⁡(−(sum(t1.V⋅pc,t2.V⋅pc,⋯ ,t6.V⋅pc)))Pred_1 = YP_1 = 1/(1 + \exp(-(sum(t_1.V \cdot p_c, t_2.V \cdot p_c, \cdots, t_6.V \cdot p_c))) using the model parameter pcp_c from the previous iteration. At j=1j = 1, pcp_c refers to the initialized model parameter 0.01, which gives Pred1=YP1=1/(1+exp⁡(−(sum(46,1,1760,24,1,1)⋅0.01)))=1/(1+e−18.33)Pred_1 = YP_1 = 1/(1 + \exp(-(sum(46, 1, 1760, 24, 1, 1) \cdot 0.01))) = 1/(1 + e^{-18.33}). It further computes the corresponding per-instance gradient contribution Grad1=GI1=(YP1−t1.Y)⋅t1.V=−5.04×10−7Grad_1 = GI_1 = (YP_1 - t_1.Y) \cdot t_1.V = -5.04 \times 10^{-7}, which contributes to the aggregated gradient value of 288=Grad1+Grad7+⋯288 = Grad_1 + Grad_7 + \cdots. Thus, at j=1j = 1, the updated model parameter PP for Age becomes -0.4717. Global provenance PGP_G preserves the sequence of model parameter updates across the fixpoint iterations by accumulating PLP_L at each iteration j=0,…,kj = 0, \ldots, k as a set of PLP_L in RDDs. The captured provenance enables Tom to reconstruct the full optimization trajectory and trace which training instances drove the weight of, e.g., Age = 15.4500, after 100 iterations.

Optimization for Provenance Capture. Capturing local and global provenance introduces two challenges, both of which are reflected in the optimized query plan shown in Figure 2. First, the window functions required for update of model's parameters involve sorting and shuffling across worker nodes at every iteration. ProvQML addresses this by broadcasting the small delta model relation δM\delta M to all workers, eliminating the join shuffle entirely, and by partitioning the input training data T\mathcal{T} by instance identifier I once upfront. Since the prediction window function partitions on I, this upfront partitioning eliminates its reshuffle; only a single shuffle per iteration remains for the gradient window function, which partitions on C. Second, accumulating global provenance over k iterations incurs O(∣T∣⋅k)O(|\mathcal{T}| \cdot k) memory growth. ProvQML joins only with δMj−1\delta M_{j-1} at each iteration based on the observation that tuples from earlier iterations yield no valid join results due to mismatched iteration keys. Furthermore, it evicts per-iteration RDDs once the accumulated

Nkechi J. Akinwale and Seokki Lee

global provenance subsumes the provenance from the previous iterations, keeping the memory usage bounded at O(∣T∣)O(|\mathcal{T}|) per iteration.

Usability of Provenance. Provenance-aware recursive training pipelines provide a principled mechanism for exposing the dependency structure of iterative optimization. By materializing intermediate values such as per-instance predictions ( PrediPred_i) and per-tuple gradient contributions ( GradiGrad_i) at each iteration j, the system makes explicit the lineage linking individual training instances to parameter updates. Instead of observing only the final weight vector, analysts like Tom, can reconstruct how specific instances contribute to the aggregated gradient and how these contributions propagate across recursive state transitions. This fine-grained provenance enables systematic identification of influential records and feature-level sensitivity as indicated in [3, 45] without re-executing the recursive query entirely (retraining the model). In regulated settings, the resulting provenance can constitute a formally defined mapping from input training instances to final model parameters, supporting auditability of the training process.

Beyond interpretability, embedding provenance within the recursive relation enables computational reuse and adaptive optimization. By persisting iteration indices (j)(j), gradient aggregates, and their contributing instances, the system supports warm-start execution, allowing training to resume from a previously materialized iteration state without recomputing earlier steps. Furthermore, the availability of cross-iteration lineage enables convergence diagnostics based on the evolution of gradient magnitudes and directions. Such diagnostics can guide dynamic adjustment of hyperparameters (e.g., learning rate or sampling ratio) within the same declarative framework. By integrating provenance into the recursive query dataflow, the system reduces reliance on external monitoring while enabling selective retraining and incremental refinement grounded in explicit dependency analysis.

Contributions. We make the following contributions:

  • We introduce the ProvQML query language, which extends recursive aggregate SQL with support for subqueries and window functions within the recursive case, enabling provenance capture for a broad range of ML algorithms (Section 4).

  • We devise query rewriting techniques that capture local and global provenance during query evaluation (model training), with correctness guaranteed by PreM and PCC (Section 5).

  • We develop ProvQML, a recursive aggregate SQL engine on top of Apache Spark that executes the rewritten queries with optimizations that reduce shuffle overhead and bound memory growth during provenance capture (Section 6).

  • We evaluate ProvQML using 5 ML algorithms and 4 real-world datasets, demonstrating efficient provenance capture (Section 7).

The rest of the paper is organized as follows: Section 2 covers basics of recursive aggregate queries including PreM and PCC properties. Section 3 formalizes the problem, and Section 4 introduces ProvQML query language. Section 5 explains provenance computation and Section 6 discusses optimizations. We present experiments in Section 7, related work in Section 8, and conclusion in Section 9.