arXiv:2609.03672cs.DBSep 2026

Manuscript Offprint

arXiv:2609.03672

Convolution Sum-Product Queries

Kyle Deeds, Timo Camillo Merkl, Dan Suciu

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

We study query evaluation for an extension of sum-product queries (SPQ) that allows atoms with linear combinations of variables (e.g. A(2X+3Y−Z,Y+Z)A(2X + 3Y - Z, Y + Z)), which we call convolution sum-product queries (CSPQs). These queries arise in both practical settings (e.g. image processing workloads) and theoretical ones (e.g. the (min, +)-convolution and kk-SUM conjectures), and capture SPQs with added linear equality constraints. While prior work has considered the impact of linear inin- and disdis-equality constraints on query evaluation, the techniques developed in that setting are asymptotically sub-optimal for CSPQs. To address this, we describe several evaluation algorithms for CSPQs that leverage linear algebra techniques like rank analysis, quotient spaces, and variable substitution. First, we adapt Worst-Case Optimal Joins to CSPQs, achieving a runtime similar in spirit to that for conjunctive queries. Then, we extend the definition of tree decompositions (TDs) to CSPQs, and describe a factorized execution. In this extension, linear combinations are first-class citizens and play the same role as variables in traditional TDs. We define three width measures that bound the complexity of this execution with respect to the size of the domain values, of the active domain, and of the relation's support. Lastly, we show how these methods can be applied to arbitrary fields beyond the rationals.

1 Introduction

The literature on query evaluation has extended conjunctive queries (CQs) in a variety of ways to capture new problems of interest. Sum-product queries (SPQs) generalize CQs from the Boolean semiring to an arbitrary semiring [13], allowing them to express operations such as matrix multiplication, while CQs with disequalities (≠\neq) enabled the analysis of constraint satisfaction and subgraph-isomorphism problems within the CQ paradigm. In this work, we investigate an extension of conjunctive queries with linear expressions over variables in the query. For example, the convolution of two arrays A,BA, B can be expressed as C(X)=∑YA(Y)⋅B(X−Y)C(X) = \sum_Y A(Y) \cdot B(X - Y). We call this class of queries Convolution Sum-Product Queries (CSPQs). We are motivated by a large class of applications, in a variety of domains, which already use linear expressions. For example, SQL allows arbitrary expressions over attributes in the WHERE clause. Query optimizers based on dynamic programming already incorporate joins involving linear expressions, like R1.A+R2.B=R4.D+R5.E−R3.CR_1.A + R_2.B = R_4.D + R_5.E - R_3.C, see [30]. Linear expressions on the variables also occur in a large class of important workloads in tensor, image, and signal processing. For example, matrix convolution is a key operation in image processing pipelines and is not expressible via standard sum-product queries. In this operation, a smaller pattern matrix is iteratively applied to patches of the larger image matrix AA in the following manner:

B(i,j)=∑l,kA(i+l,j+k)⋅Pattern(l,k)B(i,j) = \sum_{l,k} A(i+l, j+k) \cdot \text{Pattern}(l, k)

By selecting an appropriate pattern matrix, this operation is the core computational primitive in image processing tasks such as edge detection and blurring, scientific simulations that use stencil computations, and in the convolution layers of neural networks [10, 11, 15, 26, 33, 29]. Several languages or formalisms already consider linear expressions, but typically as second-class citizens, represented as predicates separate from the main body of the query. Some fine-grained complexity conjectures are expressable in this way [9, 6]. For example, the 3SUM conjecture states that, given three sets A,B,CA, B, C, of size nn, checking if there exists i∈A,j∈B,k∈Ci \in A, j \in B, k \in C so that i+j=ki + j = k cannot be done in time O(n2−ε)O(n^{2-\varepsilon}) and can be expressed as:

Q()=⋁i,j,kA(i)∧B(j)∧C(k) such that i+j=kQ()=\bigvee_{i,j,k}A(i)\land B(j)\land C(k)\text{ such that }i+j=k

while the MinConv conjecture states that the following cannot be evaluated in time O(n2−ε)O(n^{2-\varepsilon}):

Q(k)=min⁡i,j(A(i)+B(j)) such that i+j=kQ(k)=\min_{i,j}(A(i)+B(j))\text{ such that }i+j=k

In this paper, we introduce Convolution Sum-Product Queries, and describe new algorithms for evaluating them. CSPQs extend Sum-Product Queries with linear expressions, while keeping them first-class citizens. The linear expressions occur directly in the query's atoms, for example, the 3SUM and the MinCov queries above are written as follows in our formalism:

Q()←A(X)∧B(Y)∧C(X+Y)Q() \leftarrow A(X) \land B(Y) \land C(X+Y) Q(K)←A(I)+B(K−I)(1)Q(K) \leftarrow A(I) + B(K-I) \tag{1}

We define the semantics of CSPQs, showing that they have always a well-defined answer. This is not obvious a priori. For example, the query Q()=R(X+Y)Q() = R(X + Y) would normally be interpreted as [[Q]]=∑x,yR(x+y)\left[\left[Q\right]\right] = \sum_{x,y} R(x + y), which results in an infinite sum. We use the concept of quotient space from linear algebra to ensure that every CSPQs has a well-defined semantics. In Sec. 3 we introduce CSPQs formally, define their semantics, and discuss some of their properties. Next, we describe several algorithms for evaluating a CSPQ in Sec. 4. We first describe a simple algorithm that runs in time O(∣adom(D)∣k)O(|\text{adom}(D)|^k), where adom(D)\text{adom}(D) is the active domain of the (support of the) input database, and kk is the dimension of the query's span, (defined in Sec. 3). This algorithm is best suited for dense databases, as found, for example, in processing dense tensors. Second, we describe an algorithm, which is best suited for sparse databases, which runs in time O(∣D∣ρ∗(Q))O(|D|^{\rho^*(Q)}). Here ρ∗(Q)\rho^*(Q) is the fractional edge covering number of a CSPQ, and is defined as a significant generalization of the traditional fractional edge covering number of a conjunctive query, or a hypergraph. This algorithm is quite non-obvious. For example, consider the following query, which is a slight variation of the 3SUM query above (Eq. (1)):

Q()←A(X,Y)∧B(Y,Z)∧C(X+Y,Y+Z)Q() \leftarrow A(X,Y) \land B(Y,Z) \land C(X+Y,Y+Z)

We show that ρ∗(Q)=3/2\rho^*(Q) = 3/2, and therefore QQ can be evaluated in time O(∣D∣3/2)O(|D|^{3/2}), were ∣D∣|D| is the size of the database (number of tuples in A,B,CA, B, C). Although our definition of ρ∗\rho^* (in Def. 4.2) looks very different from the traditional one, we show that it coincides with the traditional one when the CSPQ is a traditional conjunctive query. Finally, we adapt tree decompositions to CSPQs. Similarly to ρ∗\rho^*, the definition of a tree decomposition requires a careful extension to linear spaces: we present the definition of a Convolution Tree Decomposition (CTD) in Sec. 5, and describe factorized evaluation algorithms based on CTDs in Sec. 6. We also extend our techniques to arbitrary fields in Sec. 7, then conclude.

Related Work. Other extensions of conjunctive queries with numerical operations or predicates can be found in the literature. In all cases the arithmetic operations are considered second-class citizens, designed to be included in predicates, separate from the main body of the conjunctive query. For example, Arithmetic Constrains are simple comparisons X<YX < Y over a dense domain; Klug [24], Afrati et al. [2, 3], and Brisaboa et al. [7] study the containment and the query rewriting using views problems under this extension. Kiani and Shiri [22, 23, 21] study the query answering using views problem for conjunctive queries extended with linear equality constraints (which are equivalent to our CSPQs). Srivastava [34], and Ibarra and Su [16] study the containment (subsumption) problem for queries with linear constraints, like 2X+3Y<72X + 3Y < 7. The query evaluation problem has been considered in several papers. Extensions of conjunctive queries with general constraints has been discussed in [17, 18], and in [38, 39]. These references apply a technique due to Willard to handle complex predicates, such as X2+XY>5ZX^2 + XY > 5Z, but since they target more general queries than CSPQs, their runtimes are worse than what we propose in this paper: see the discussion in Sec. 4. Koutris et al. [25] and Abo Khamis et al. [19] introduce specialized algorithms for evaluating conjunctive queries with disequality predicates, X≠YX \neq Y. In contrast to these lines of work, the algorithms we present in this paper treat the linear expressions as first class citizens, and show how to apply worst-case optimal joins [32, 36, 31] and tree decompositions [12], by combining them with core ideas in linear algebra. Constraint databases, which have been heavily studied in the literature [27], are unrelated to our paper. They consider input relations that are infinite, defined implicitly using linear or algebraic constraints. In our paper we always assume the support of the input relations is finite. Beyond databases, expressions equivalent to our CSPQs over dense tensors have been intensively study by the compilers community. This work has resulted in the polyhedral model, which can represent various transformations of loops over arrays with linear index expressions, and has been leveraged in several widely used high-performance compilers for tensor algebra [35, 5, 8, 37]. Our work applies similar linear transformations but goes further by analyzing them also in the sparse setting and extending them to leverage tree decompositions style factorizations. Summary of Results.

  • We extend sum-product queries to allow linear expressions on the variables, keeping them as first-class citizens (see Sec. 3).

  • We extend the notion of tree decompositions to CSPQs and prove that these induce a factorization of the queries. (see Sec. 5)

  • We analyze the complexity of CSPQs. We provide basic algorithms (essentially for full queries) and modify worst-case optimal join algorithms to achieve AGM-style bounds (see Sec. 4). Then, we apply these algorithms to the factorizations induced by our novel extension to tree decomposition. The complexity of the evaluation algorithm is characterized by three new width parameters that capture different input density regimes (see Sec. 6).

Most proof are deferred to the appendix and in Appendix F we explain precisely how CSPQs capture SPQs with added linear equality constraints.

References (34)