Manuscript Offprint
arXiv:2610.05440Guanaco: A Global-Uniformity Algorithm for Near-Submodular-Width Conjunctive Query Evaluation
MAHMOUD ABO KHAMIS, University of Oxford, UK
HUBIE CHEN, King's College London, UK
We present Guanaco, an algorithm for performing conjunctive query evaluation where, for each Boolean conjunctive query, and positive epsilon, the algorithm achieves polynomial time with exponent equal to the submodular width plus epsilon. The algorithm and its running time generalize smoothly to general conjunctive queries. We believe the algorithm and its analysis to be notably simple, indeed, together we believe they form a highly simple argument that conjunctive query evaluation can be performed in essentially submodular width time. In the case of Boolean conjunctive queries, the algorithm is based on interleaving three simple primitives: a subroutine for establishing a form of consistency; a subroutine for establishing global uniformity, which, briefly speaking, partitions relations as needed to control discrepancies between average degree and maximum degree; and, a simple step that joins pairs of existing relations to form new relations.
CCS Concepts: • Theory of computation → Database query processing and optimization (theory); • Information systems → Join algorithms.
Additional Key Words and Phrases: conjunctive queries; submodular width; uniformity
1 Introduction
Background. Conjunctive queries are frequently occurring and heavily studied database queries [1, 27], and the computational problem of evaluating a conjunctive query on a relational database—known as conjunctive query evaluation—is intensely studied in databases and in computer science at large [15, 27]. Indeed, this problem can be viewed as a formulation of the constraint satisfaction problem [12, 23], and overall has been studied from a multitude of motivations and perspectives [1, 4, 12, 13, 16–19, 21, 22, 24–27].
It is now well-known that for each conjunctive query, there exists a polynomial-time algorithm for query evaluation, that is, there exists a value and a query evaluation algorithm with running time , where denotes the input database size. Given the centrality of this evaluation problem, a number of works have sought to obtain a fine-grained understanding of the minimum exponent achievable for each conjunctive query. While there is not yet a comprehensive understanding thereof, a number of recent works have shown general upper bounds in terms of the submodular width, a hypergraph measure that was introduced by Marx [26] and is based on the notion of submodularity. We focus our discussion on Boolean conjunctive queries, although the algorithms we discuss can operate on general conjunctive queries. We use to denote the hypergraph underlying conjunctive queries under discussion.
- Building on an algorithm and analysis in Marx’s original article [26] introducing submodular width, Berkholz and Schweikardt [10] presented an algorithm, which (following [2]) we call the Marx-Berkholz-Schweikardt algorithm. This algorithm achieves, for each conjunctive query and , a runtime of . Main ingredients used by this algorithm include two notions of consistency and a general procedure that partitions relations to enforce uniformity, which (briefly) means that the discrepancy between average degree and maximum degree, in relations, is controlled.
Authors' Contact Information: Mahmoud Abo Khamis, mahmoud.abokhamis@cs.ox.ac.uk, University of Oxford, Oxford, UK; Hubie Chen, hubie.chen@kcl.ac.uk, King's College London, London, UK.
Mahmoud Abo Khamis and Hubie Chen
• Abo Khamis, Ngo, and Suciu [5, 6] presented an information-theoretic algorithm called PANDA that achieves a runtime of . Subsequently, they introduced an improved version of the algorithm, called PANDAExpress [7] that mitigates the polylog(N) factor to leave only a single , that is, that runs in time .
• Abo Khamis and Chen [2] presented an algorithm called Jaguar achieving, for each , a runtime of . This algorithm, throughout an execution, maintains a set function defined on all variable subsets and reasons about submodularity to guide a process of computing joins and partitioning relations.
On a high level, these algorithms collectively make use of similar computational primitives, namely, consistency/semijoin reduction, computing joins to introduce new relations, and data partitioning. This consensus suggests that a submodular-width runtime is a natural barrier for algorithms employing these primitives. Related to this, Fan, Koutris, and Zhao [14] presented techniques for lower bounding the runtime of conjunctive query evaluation, and showed that, for a number of different conjunctive queries, no combinatorial algorithm can achieve runtime , assuming established fine-grained complexity-theoretic hypotheses.
Contributions. In this article, we build on the notions, algorithms, and analyses of Marx [26] and Berkholz and Schweikardt [10] to give a new algorithm for conjunctive query evaluation that achieves, for each , a runtime of . We believe our algorithm, called Guanaco, and its analysis to be remarkably simple, and to show a novel way in which the basic ingredients used by the above algorithms can be plainly combined to achieve conjunctive query evaluation in essentially submodular-width time. Indeed, we believe that the algorithm and analysis constitute one of the simplest explanations for showing the claimed time bound on conjunctive query evaluation, and could be used for teaching this query evaluation result.
In the Boolean case, the algorithm is based on interleaving three basic and generic primitives: a subroutine for establishing a form of consistency; a subroutine for establishing global uniformity, which reduces skew between average degree and maximum degree; and a simple step that joins pairs of existing relations to form new relations. In the general case, a version of the well-known Yannakakis algorithm for finding answers to acyclic conjunctive queries is also employed. In contrast to the PANDA family of algorithms and the Jaguar algorithm, the execution of Guanaco is not guided explicitly by submodularity or polymatroids. In terms of its use of submodularity, Guanaco only requires knowing the fixed value of the submodular width, but does not need to know how this value was computed.
Recent work introduced a hypergraph measure called -submodular width [3] which, by leveraging algorithms for fast matrix multiplication, can for some hypergraphs achieve runtimes strictly below the submodular width. We believe that Guanaco, with its high simplicity, may be a fruitful footing for further investigating how to combine algebraic methods with the computational primitives used for submodular-width-based algorithms for conjunctive query evaluation.
2.1 Tree decompositions
Let be a hypergraph. A tree decomposition of is a pair where is a tree and is a map satisfying two properties: (1) (coverage) for each , there exists a vertex with , and (2) for each , the set forms a connected subtree of . Here, when is a vertex, is called the bag of . When , a free-connex tree decomposition of the pair is a tree decomposition of having the extra property that there is a connected subtree of whose bags contain exactly the vertices in , that is, where . Here, the set is intended to represent the free variables of a conjunctive query.
2.2 Submodular width
Relative to a set , a polymatroid is a set function satisfying ; implies (monotonicity); and for all subsets (submodularity). When is a hypergraph, let denote the set containing each polymatroid satisfying edge domination: for each . For a hypergraph and , the submodular width of the pair , denoted by subw, is defined as , where here the minimum is over all free-connex tree decompositions of . In the case that , this becomes a minimum over all tree decompositions of , and one obtains Marx's original definition of submodular width [26].
Given a hypergraph and a set , in order to compute the submodular width, the first step is to distribute the min over the max in the above definition [5, 8]. This distribution gives birth to the concept of “bag selector”, where a bag selector is a set consisting of one bag from each tree decomposition. Let denote the set of all bag selectors. Then, the submodular width becomes:
A linear program
In particular, computing the submodular width reduces to solving a collection of linear programs, one for each bag selector B, and taking their maximum.
2.3 Configurations
To accommodate multiple audiences and multiple backgrounds, we use a formulation of conjunctive query evaluation that, although nonstandard, is intended to be accessible. Each set of variables under discussion will be a finite nonempty set whose subsets are typically denoted with letters such as S, T, U, ...; each domain under discussion will be a finite nonempty set. A configuration on a set V of variables and a domain D is a pair where
• is a nonempty subset of , that is, a set whose elements are subsets of ,
- is an indexed collection of sets of mappings, where for each , it holds that is a set of mappings from to . Such a set is sometimes called a relation.
Mahmoud Abo Khamis and Hubie Chen
We say that a map is an answer of a configuration if for each , it holds that . We use Answers(C) to denote the set of answers of . The hypergraph of a configuration on a set of variables and a domain is the hypergraph .
We will discuss two computational problems. The first one, a formulation of Boolean conjunctive query evaluation, is the problem of deciding, given a configuration, whether or not there exists an answer of the configuration. The second one, which generalizes the first one and is a formulation of conjunctive query evaluation, is the problem of computing, given a configuration C and a set of free variables, the set Answers(C) . We view the first problem as the case of the second problem where : a configuration C has an answer if and only if Answers(C) contains the empty answer, that is, the unique answer whose domain is the empty set .
Example 2.1. Consider, as an example, the conjunctive query
Here, all variables are free, as indicated by the notation , and so we have . A database D for this query would provide a universe D and two relations, namely, , which would be a subset of , that is, a set of pairs with entries from D; and , which would be a subset of , that is, a set of triples with entries from D. In a typical formulation of conjunctive query evaluation on Q, an instance would be a database D for this query, and the goal would be to find the set of query answers, where is an query answer when
To formulate such an instance using the notion of configuration, we would take to be , and define, for example, as the set of maps such that ; the sets and would be defined analogously. Then, an answer of the configuration, as defined above, would be exactly a query answer as just defined.
As a second example, consider the Boolean conjunctive query
Here, no variable is free, as indicated by the notation , and so we take and . Given a database D, we formulate a configuration C from D just as above. Evaluating on a database D now amounts to deciding if the configuration has any answer at all, that is, whether or not Answers(C) is nonempty; we have that Answers(C) is nonempty if and only if Answers(C) contains the empty answer.
We will use the following terminology to discuss configurations. A number of the below notions, including the notions of maximum degree, average degree, and uniformity, appear in and were used in Marx’s article [26]. In what follows, we assume that denote values where and .
• Relative to a configuration , we refer to the elements of as realized sets.
- A configuration is empty when and , and is non-empty when and . Observe that an empty configuration has no answers.
• We say that a configuration is down-closed if is closed under taking subsets.
-
A configuration is -consistent if it is down-closed, non-empty, and for all such that , it holds that .
-
Let be a -consistent configuration, and let . We define the following notions of maximum and average degree:
Here, we write that extends when .
- A down-closed configuration is -uniform if for all such that , it holds that .
• A down-closed configuration is -clean if it is -consistent and -uniform.
Note that in general, we will only discuss uniformity of configurations that are -consistent.
We say that a set of configurations represents a configuration if Answers( ) is equal to Answers( ). Say that a configuration tightens or is a tightening of a configuration if for each , it holds that and . That is, if holds a relation on , then also holds a relation on which must be contained in that of . Observe that when tightens , it holds that Answers( ) Answers( ).
We will use the known fact concerning -consistency. Here and throughout, we assume a RAM model, and we study a data complexity, so (for example) the variable set under discussion is viewed as having constant size.
PROPOSITION 2.2. Fix a variable set V. There exists a linear-time algorithm that, given a configuration C on variable set V, establishes -consistency in that it removes functions from C's relations so that the resulting configuration is -consistent or empty, is a tightening of C, and also has Answers( ) = Answers(C).
PROOF. In brief, the algorithm acts as follows. First, it down-closes the input configuration, if needed, by adding relations that are projections of existing ones; this can be done in linear time and without changing the answer set. Then, it continually removes functions from relations until either -consistency holds, or all relations become empty. This removal process can be implemented in linear time, by reduction to the problem of finding a minimum weight satisfying assignment to a set of Horn clauses, as explained in the proof of Lemma 4.2 [11].
Note 2.3. Fix a hypergraph and a subset . We will use the known fact that there is a version of the Yannakakis algorithm [1, 28], denoted Yannakakis( ) that, given a -consistent configuration with hypergraph and a free-connex tree decomposition of , where all bags are realized in , acts as follows: it restricts the tree decomposition to a subtree where , and then enumerates the set Answers( ) where is the configuration obtained from where the realized sets are restricted to the sets . It does this within time where is the size of , and is the size of the output set. Clearly, we have (Answers( ) .
3 Intuition
Before explaining the Guanaco algorithm in detail, we present in this section the high-level intuition behind the algorithm and give an example execution. To that end, consider the following 4-cycle query:
It is well-known that has a fractional hypertree width [20] of 2 and a submodular width of 3/2. This query has two free-connex tree decompositions, apart from the trivial one that consists of a single bag containing all four variables. These two non-trivial tree decompositions are shown in Figure 1, and they are as follows:
-
A tree decomposition with two nodes and corresponding to two bags and .
-
A tree decomposition with two nodes and corresponding to two bags and .
The fact that the fractional hypertree width of is 2 indicates that, no matter which tree decomposition we choose, there is a worst-case database instance where we cannot beat the runtime,
Mahmoud Abo Khamis and Hubie Chen



Fig. 1. The 4-cycle query (Eq. (1)) and the two non-trivial tree decompositions.
where N is the input size. Indeed, here is such an instance. Assume N is an even number, and let [N] denote the set . Let the relations R, S, T, U all be identical and contain the following tuples:
In the configuration notation, the input is a configuration where the domain , , is defined as follows:
and , , and are defined similarly.
It is not hard to see that no matter which tree decomposition we choose, the intermediate relations corresponding to the bags will have size . However, it is well-known that this query admits an algorithm with runtime [9] on any database instance (where the exponent 3/2 happens to be precisely the submodular width of ). In contrast, our Guanaco algorithm achieves a runtime of for any on any database instance. On the particular database instance specified above, Guanaco achieves a better runtime of . We explain below how this is possible.
Guanaco uses a subroutine, called Cleanup, that takes any configuration and partitions it into a constant number (in data complexity) of configurations that are -clean, for some given parameters and . Recall that a configuration is -clean if it is -consistent and -uniform. Ensuring -consistency is straightforward: In the classic language of databases, this is equivalent to performing semijoin-reductions on the input relations until no further reductions are possible, and this can be done in linear time (by Proposition 2.2). On the other hand, ensuring -uniformity is more involved. Recall that uniformity means that for any two realized sets in the configuration, the maximum degree is not significantly larger than the average degree . Intuitively, this means that the degree should not have a very high variance, hence the name “uniformity”. Whenever we detect a violation of uniformity for some , the Cleanup subroutine partitions the configuration into two configurations and by partitioning the relation into two parts: A “light part” where the degree of each tuple is “small”, and a “heavy part” where the degree of each tuple is “large”. Fixing the uniformity violation for might result in the new configurations and violating -consistency, and similarly, fixing -consistency might result in re-violating previously fixed uniformity violations. Therefore, the Cleanup subroutine iteratively alternates between both until both properties are satisfied, and returns the resulting configurations. It is not obvious that this process terminates. We will see in Section 4 that the Cleanup subroutine does indeed terminate and return a constant number of -clean configurations. In our example, the Cleanup subroutine will partition the input configuration by partitioning into and that are defined as follows:
This is because X-values in have a maximum degree of and an average degree of . Hence, the X-value of 1 is “heavy” and the other X-values are “light”. The other relations , , and are partitioned similarly. At the end, the Cleanup subroutine will return at most 16 configurations, capturing the combinations where each of the four variables X, Y, Z, W is either heavy or light. (The actual number of configurations might vary depending on some implementation details of Cleanup, but it will always be a constant number in data complexity.)
The outer Guanaco algorithm is based on the following idea. Consider an instance, represented as a configuration of size , for example, the configuration described in Eq. (2) for the 4-cycle query. Consider any configuration that tightens and is -clean. For simplicity, suppose that , hence is “perfectly uniform”, meaning that, for any two realized sets , the average degree and maximum degree are the same. In our example, could be one of the 16 configurations returned by the Cleanup subroutine. Let denote the submodular width of the query , which is in this example. Suppose that all realized relations in satisfy . Consider the following set function :
Then, is a polymatroid. Indeed, the monotonicity of follows from the fact that is -consistent, and the submodularity of follows from the fact that is -uniform. To see why submodularity holds, consider any two realized sets where is realized (hence down-closedness implies that is realized as well). Then, we have:
By taking logarithms, we obtain the submodularity . Other submodularity cases can be verified similarly (under mild conditions). Moreover, since tightens , the polymatroid is edge-dominated. But then, recall from Section 2.2 that the submodular width is a maximum over all edge-dominated polymatroids, including the above . We will see later in Section 5 that this implies either one of two things:
-
Either there exists a free-connex tree decomposition of the query whose bags are already realized in C, in which case we can answer the query by running the Yannakakis algorithm on C.
-
Or every realized relation satisfies and there exists a “realizable pair” , i.e., a pair of realized sets where is not realized in and . If this is the case, then we can join the two relations and to create a new relation , and add it to the configuration. The size of the new relation is upper bounded by . On -scale, this is equivalent to , hence . Adding this extra relation to the configuration might violate -consistency and -uniformity, which is why we need to run Cleanup again.
In our example, the Guanaco algorithm initially calls the Cleanup subroutine on the input configuration described by Eq. (2) and forth, and obtains a constant number of -clean configurations, as explained before. WLOG consider the configuration
Mahmoud Abo Khamis and Hubie Chen
where Y and W are “light” and X and Z are “heavy”. In this configuration , the realized relations are as follows:
The corresponding polymatroid g is as follows:
This is indeed a polymatroid that is edge-dominated. Since no tree decomposition from Figure 1 already has both bags realized in , it must be the case that contains at least one realizable pair. In fact, contains two realizable pairs in this case:
-
The pair ( ) where . We can join the two relations and to create a new relation of size .
-
The pair ( ) where . We can join the two relations and to create a new relation of size .
After creating the above two relations, we can run the Yannakakis algorithm using the tree decomposition . Hence, the configuration takes time overall. The other 15 configurations take similar time and use either one of the two tree decompositions.
4 Cleanup subroutine
In this section, we introduce a basic subroutine called Cleanup that interleaves establishing -consistency with establishing global uniformity until clean configurations are obtained. This subroutine and its analysis can be viewed as formulations of similar ones due to Marx [26]. More precisely, relative to a value and a value , the Cleanup algorithm, when given a configuration over variables , outputs a finite set of down-closed configurations that represent , have the same realized sets as (up to down-closing), and are each -clean. Moreover, there exists a computable function such that the algorithm runs within time , where denotes the input database size. The algorithm description uses the following notions, relative to a configuration . Say that a pair violates -uniformity in if and . When , and , define as , that is, is the number of extensions of in .
LEMMA 4.1. Let , be constants; there is a function such that the following holds. Assume that Cleanup is run on and a configuration where every relation has size at most ; then, the length of any root-leaf path in the recursion tree (that is, the depth of the recursion tree) is bounded above by , where is the variable set of . In particular, the algorithm terminates.
PROOF. In the case that M = 1, it is evident that the algorithm does not recurse and that the lemma holds, so for the remainder of the proof, we assume that M > 1.
Let be the configurations of any root-leaf path in the recursion tree; precisely, we consider the configurations right after -consistency is established. Observe that all configurations ever
Indeed, Lemma 4.1 below uses the same core argumentation as Lemma 4.11 in Marx [26]. The notion of uniformity employed by Marx is different from that employed here.
Algorithm 1 Cleanup (value M, configuration C); assumes ,
1: Establish -consistency on C (using the algorithm of Proposition 2.2) 2: if C is empty then 3: Return the empty set 4: end if 5: if there exists a pair violating -uniformity in C then 6: Let S, T be such a pair 7: Assign 8: Assign 9: Assign and to be equal to C but where is replaced by and , respectively 10: Return Cleanup 11: else 12: Return 13: end if
processed by the algorithm share the same set of realized sets. Let us denote . We define the potential function
By assumption, each relation has size at most , so each term of the sum is at most . The number of terms is at most , so we have . We show that in each recursive call, this function decreases by a sufficient amount so as to allow us to bound the path length as desired.
Suppose is an index with . We claim that . We consider two cases depending on how is derived from .
• If is derived from , we have
The first inequality follows from the fact that establishing -consistency only removes tuples from relations and cannot increase maximum degree; the second inequality comes from the definition of from , and the third inequality comes from S, T being a violation of uniformity.
• If is derived from , we first observe that each has at least extensions in . We then have
Mahmoud Abo Khamis and Hubie Chen
It follows that
Here, the first inequality is justified in the same way as the first inequality in the previous case, and the second inequality follows from the observation.
It follows from the claim that the potential function decreases by at least at each stage, and hence we have ; for fixed and , this bound is .
The following theorem summarizes the main properties of the Cleanup algorithm to be used.
THEOREM 4.2. Fix constants , , and a variable set . Assume that the Cleanup algorithm is invoked on and a configuration on variable set where each relation has size at most ; the algorithm returns a set of configurations representing and having size , where each configuration in is -clean, tightens , and has the same realized sets as does. Moreover, the algorithm admits an implementation running within time .
Proof. Since, by Lemma 4.1, the depth of the recursion tree is bounded by , the size of the tree is bounded by ; this latter value in turn bounds the size of the output set , which contains one configuration per leaf of the recursion tree. The set represents the configuration due to the fact that when is partitioned into and , we evidently have Answers( ) = Answers( ) Answers( ). Each configuration in is -clean, since whenever line 12 is reached, the configuration returned is both -consistent and has no pair violating -uniformity; also, each such configuration evidently tightens and has the same realized sets as does. The main computations performed at each node of the recursion tree are the step that establishes -consistency, which runs in linear time due to Proposition 2.2, and the partitioning of a relation, which is evidently in linear time.
5 Guanaco algorithm
We present our main algorithm and its analysis. Let us first give a brief intuitive description of the algorithm. The main algorithm Guanaco receives a configuration , and computes some values. It then calls the main recursive subroutine, called Guanaco-Recurse, on . This subroutine calls Cleanup once, and then for each resulting configuration , it tries to realize a new relation if possible; if this is possible, it then calls itself recursively on the consequent configuration, and in the case that this is not possible, it finds a tree decomposition and runs the Yannakakis algorithm to enumerate the needed answers. (Note that in this case, although we present the algorithm Guanaco-Recurse as attempting to find a tree decomposition of a certain type, it will turn out that such a tree decomposition will always be found.) Thus, on a high level, this subroutine interleaves Cleanup with the creation of new relations.
How are new relations created? The following definition will govern when this is done. Say that a pair is -realizable, with respect to a configuration , if the following hold: , , and .
Note 5.1. Let be an -realizable pair with respect to a configuration . We speak of realizing such a pair on configuration , which means that is added to and a relation is created, by considering each pair of assignments and where extends
, and including (for each such pair of assignments) the assignment in . (Here, by , we are viewing assignments as sets of pairs.) The number of pairs that have to be considered, by definition of -realizable, is less than or equal to , as is the size of the resulting relation . Thus in effect, this process of realizing a pair amounts to taking a binary join whose output size is controlled.
Algorithm 2 Guanaco (configuration ); assumes , has hypergraph , and
1: Assign ▷ See Section 2.2 for how to compute this
2: Assign
3: Assign , where is the variable set of
4: Assign to be the maximum relation size of
5: if then
6: Return the empty set
7: end if
8: Return Guanaco-Recurse
Algorithm 3 Guanaco-Recurse (configuration C); assumes , ; ; and that H, X are as in Guanaco
1: Assign 2: Initialize 3: for each configuration do 4: if has an -realizable pair then 5: Let be the configuration resulting from realizing such a pair on 6: Assign 7: else 8: Search for a free-connex tree decomp. of H, X where all bags are realized, wrt 9: Assign (assuming such a TD was found) 10: end if 11: end for 12: Return A
We first show termination of the main algorithm, along with a time bound. Here and throughout this section, we use OUT to denote the output size.
LEMMA 5.1. (termination/time bound) Fix a hypergraph H with vertex set ; fix and . On any input configuration whose hypergraph is H, the call terminates and runs within time .
PROOF. First, let us consider the recursion tree that Guanaco-Recurse gives rise to, and bound its depth. Each time a recursive call is made, a new relation has been realized, by line 5, and the call to results in a set of configurations with the same realized sets as (by Theorem 4.2); thus, the maximum depth is . The branching factor of the recursion tree is determined by the size of the output given by the call to in line 1; but this is a function of , by Theorem 4.2. The size of the entire recursion tree is thus bounded above by a function of . The algorithm thus terminates.
Mahmoud Abo Khamis and Hubie Chen
To argue the claimed time bound, it suffices to argue that each individual execution of the routine Guanaco-Recurse (that is, excluding the time incurred by recursive calls) runs within time . By Theorem 4.2, line 1 runs within linear time , as do line 4, the check for a realizable pair, and line 8, the search for a tree decomposition. Line 9 executes a call to the Yannakakis algorithm; as remarked in Note 2.3 it is known that this algorithm runs within time , where here denotes the output size of Answers( ) ; but Answers( ) forms part of the overall output, so we have . The only remaining line to analyze is line 5; but as explained in Note 5.1, realizing an -realizable pair can be performed within time .
Towards showing correctness of the algorithm, the following lemma is key; somewhat similar lemmas were given by Marx [26] and by Berkholz and Schweikardt [10]. Our lemma will allow us to derive that, whenever Guanaco-Recurse cannot realize an additional relation on a configuration , there is a submodular function where every set with is realized in the configuration , and moreover has the properties needed to guarantee in line 8 that there is a tree decomposition of the desired form. Speaking approximately, the function is defined by setting to a value close to for each realized set , and to a value close to for each non-realized set .
LEMMA 5.2. Suppose that , , and are values, is a set of variables, and , are defined as in the Guanaco algorithm. Suppose that a non-empty configuration with variable set is such that:
• it is -clean,
• it has no -realizable pair,
• every realized set has .
Then there exists a monotone submodular function such that:
(1)
(2) Each set S of variables satisfying is realized, that is, is in .
(3) Each set where satisfies .
Proof. We show that the following function has the described properties. Set , and define the function by . Define
Define as . In the particular case that , each instance of a operation will only be applied to the value 1, in this proof; we here use the convention that .
We first observe that , so any set of variables has ; we have , and can conclude .
We argue monotonicity of as follows. The function is readily verified to be monotone. It thus suffices to verify that is monotone. But this follows from the following: first, for any realized sets , with , by -consistency we have and thus ; second, by assumption, for any realized set , we have , so if a set is not realized, we have .
We argue submodularity of as follows. First, we note that it is elementarily verified, using the identity , that
(11) and so we have that is submodular. We have to show that for any sets , , we have the inequality . When or , this inequality is immediate; so suppose in the remainder of the verification that and . By the submodularity of , it suffices to verify . In the case that at least one of , is not realized, assume for notation that is not realized; we have , so then the needed inequality follows from the monotonicity of . The remaining case is where both , are realized. In this case, we have, with base logarithms,
Here, the first inequality follows from -uniformity and the second inequality follows from the above inequality (11) on along with the observation that . In order to conclude the argument, it suffices to argue that .
• In the case that is realized, then , and we are done.
- In the case that is not realized, we have that is not a realizable pair, which implies that , and we are done.
We have argued that g is monotone and submodular. We verify the three claimed properties as follows.
(1) The configuration C is assumed to be non-empty, so , implying .
(2) We show that any set satisfying is realized. For any set satisfying this inequality, we have . But then by definition of , we have that and thus is realized.
(3) Suppose that is realized, that is, suppose , and that ; we show . Since , we have . By our initial observation on , we have , and so .
LEMMA 5.3. (correctness) On a configuration with hypergraph , a call to returns Answers() .
PROOF. Consider the recursion tree of Guanaco-Recurse( ) when Guanaco is run on a configuration . We claim that each call Guanaco-Recurse(C) returns a set A where
This suffices, since then the call Guanaco-Recurse( ) returns the set .
First, observe that each configuration resulting from a call to Cleanup is a tightening of C, by Theorem 4.2, and also observe that realizing a pair also tightens a configuration. Thus, every configuration encountered in a call Guanaco-Recurse(C) is a tightening of .
We prove the claim by induction on the structure of the recursion tree. Consider a single execution of Guanaco-Recurse. Let us denote ; with respect to the ith iteration of the for loop, we use to denote the configuration from considered and to denote the set of answers added to A.
- Consider the base case, where the execution of Guanaco-Recurse(C) makes no recursive calls. Each time line 8 is encountered, the configuration satisfies the assumptions of
Mahmoud Abo Khamis and Hubie Chen
Lemma 5.2. Thus by Lemma 5.2, there exists a monotone submodular function satisfying properties (1), (2), and (3) from that lemma's statement. By (1), we obtain that is a polymatroid, and by (3), we have that satisfies edge domination. Thus is in the set defined in Section 2.2, and since , by the definition of submodular width there exists a free-connex tree decomposition of where . It follows from (2) that each set (over ) is realized with respect to . We obtain that is a free-connex tree decomposition of where all bags are realized with respect to , and so line 8 of Guanaco-Recurse successfully finds a tree decomposition.
Thus Yannakakis is run on each configuration , resulting in sets where (recall Note 2.3). We then have , and since represents , we have . Moreover each is a subset of since is obtained by using a free-connex tree decomposition of which covers all edges of . Thus satisfies the stated condition.
- Consider the inductive case, where the execution of Guanaco-Recurse(C) makes recursive calls. In the case that a recursive call is made after examining , let denote the configuration from line 5. In this case, we have by induction; we also have . In the case that no recursive call is made after examining , by reasoning as in the base case, we have . Thus, for all we have
so as C represents C, we obtain
Thus satisfies the stated condition.
Collecting together Lemmas 5.1 and 5.3, we obtain our main result.
THEOREM 5.4. Fix a hypergraph with vertex set , fix , and fix . On any input configuration whose hypergraph is , the call returns Answers within time .
Proof. The call runs within the stated time due to Lemma 5.1, and returns Answers( ) due to Lemma 5.3.
Note 5.2. In the Boolean case, that is, the case where , the algorithms need only return yes or no depending on whether or not there exists an answer to the input configuration , or, equivalently, whether or not the empty assignment is in Answers( ) or not (respectively).
In this case, the algorithms can be simplified as follows. In Guanaco, in line 6, a no can simply be returned. In Guanaco-Recurse, adding results to A via taking a union is tantamount to simply taking the boolean OR of the decisions returned by recursive calls and by the Yannakakis algorithm: the only thing that would possibly be added to A would be the empty assignment. So, in line 6, if the recursive call returns yes, then yes can be returned immediately; line 12 can be replaced with returning no; and lines 8 and 9 can in fact be replaced with returning yes: it was shown in the proof of Lemma 5.3 that a tree decomposition of the stated form (that is, a tree decomposition of H where all bags are realized) always exists, and in this case, as is -consistent and nonempty, by the known dynamic programming algorithm on tree decompositions, there is an answer to restricted to relations defined on bags of H, which implies that there is an answer to the original configuration .
6 Conclusion
Every conjunctive query can be evaluated in polynomial time with a certain exponent. To date, the smallest known value of this exponent that can be achieved using combinatorial algorithms is the submodular width of the query. However, algorithms achieving this exponent are often complex and rely on information theory, LP duality, and sub-probability measures—among other tools [5–8]. In contrast to these algorithms, we presented in this paper a significantly simpler algorithm, called Guanaco, that can evaluate any conjunctive query in polynomial time with an exponent equal to the submodular width plus an arbitrarily small . The algorithm and its analysis are natural and do not rely on any of the aforementioned tools.
We conclude with some open problems.
Removing the extra in the exponent. It is not clear whether the extra in the exponent can be removed. This delta also seems to manifest in the Jaguar algorithm [2], and larger slacks in the exponent also appear in prior algorithms [10, 26]. This non-tightness in the exponent seems to be a common weakness of primal algorithms, by which we mean algorithms that work directly in the space of polymatroids. The only known algorithms that bypass this weakness are dual algorithms, by which we mean algorithms that operate in the space of Shannon inequalities—such as PANDA and PANDAExpress [5–7].
Handling arbitrary degree constraints. While we view Guanaco as being significantly simpler than prior algorithms for conjunctive query evaluation such as PANDA [5–7] and Jaguar [2], the downside is that we have only shown it to achieve a complexity in terms of the input database size N; unlike PANDA and Jaguar, it has not been shown to handle arbitrary degree constraints on the input relations [5].
Acknowledgments
H. Chen acknowledges the support of EPSRC grants EP/V039318/1 and EP/X03190X/1.
References
[1] S. Abiteboul, R. Hull, and V. Vianu. 1995. Foundations of Databases. Addison-Wesley.
[2] Mahmoud Abo Khamis and Hubie Chen. 2026. Jaguar: A Primal Algorithm for Conjunctive Query Evaluation in Submodular-Width Time. Proc. ACM Manag. Data 4, 2, Article 108 (May 2026), 21 pages. https://doi.org/10.1145/3801904
[3] Mahmoud Abo Khamis, Xiao Hu, and Dan Suciu. 2025. Fast Matrix Multiplication meets the Submodular Width. Proc. ACM Manag. Data 3, 2, Article 98 (2025), 26 pages. https://doi.org/10.1145/3725235
[4] Mahmoud Abo Khamis, Hung Q. Ngo, and Atri Rudra. 2016. FAQ: Questions Asked Frequently. In Proceedings of the 35th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems, PODS 2016, San Francisco, CA, USA, June 26 - July 01, 2016, Tova Milo and Wang-Chiew Tan (Eds.). ACM, 13–28. https://doi.org/10.1145/2902251.2902280
[5] Mahmoud Abo Khamis, Hung Q. Ngo, and Dan Suciu. 2017. What Do Shannon-type Inequalities, Submodular Width, and Disjunctive Datalog Have to Do with One Another?. In Proceedings of the 36th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems, PODS 2017, Chicago, IL, USA, May 14-19, 2017, Emanuel Sallinger, Jan Van den Bussche, and Floris Geerts (Eds.). ACM, 429–444. https://doi.org/10.1145/3034786.3056105
[6] Mahmoud Abo Khamis, Hung Q. Ngo, and Dan Suciu. 2025. PANDA: Query Evaluation in Submodular Width. TheoreticCS Volume 4, Article 12 (Apr 2025). https://doi.org/10.46298/theoretics.25.12
[7] Mahmoud Abo Khamis, Hung Q. Ngo, and Dan Suciu. 2026. PANDAExpress: A Simpler and Faster PANDA Algorithm. Proc. ACM Manag. Data 4, 2, Article 114 (May 2026), 26 pages. https://doi.org/10.1145/3801910
[8] Mahmoud Abo Khamis, Hung Q. Ngo, and Dan Suciu. 2026. Query Optimization and Evaluation via Information Theory. In Companion of the 45th Symposium on Principles of Database Systems (India) (PODS Companion '26). Association for Computing Machinery, New York, NY, USA, 2–17. https://doi.org/10.1145/3788852.3805595
[9] Noga Alon, Raphael Yuster, and Uri Zwick. 1997. Finding and Counting Given Length Cycles. Algorithmica 17, 3 (1997), 209–223. https://doi.org/10.1007/BF02523189
[10] Christoph Berkholz and Nicole Schweikardt. 2019. Constant Delay Enumeration with FPT-Preprocessing for Conjunctive Queries of Bounded Submodular Width. In 44th International Symposium on Mathematical Foundations of
Mahmoud Abo Khamis and Hubie Chen
Computer Science (MFCS 2019) (Leibniz International Proceedings in Informatics (LIPics), Vol. 138), Peter Rossmanith, Pinar Heggernes, and Joost-Pieter Katoen (Eds.). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 58:1–58:15. https://doi.org/10.4230/LIPics.MFCS.2019.58
[11] Christoph Berkholz and Nicole Schweikardt. 2020. Constant delay enumeration with FPT-preprocessing for conjunctive queries of bounded submodular width. CoRR abs/2003.01075 (2020). arXiv:2003.01075
[12] Hubie Chen. 2023. Computability and Complexity. The MIT Press, Cambridge, MA.
[13] Hubie Chen and Moritz Müller. 2017. One Hierarchy Spawns Another: Graph Deconstructions and the Complexity Classification of Conjunctive Queries. ACM Trans. Comput. Log. 18, 4 (2017), 29:1–29:37.
[14] Austen Z. Fan, Paraschos Koutris, and Hangdong Zhao. 2023. The Fine-Grained Complexity of Boolean Conjunctive Queries and Sum-Product Problems. In 50th International Colloquium on Automata, Languages, and Programming (ICALP 2023) (Leibniz International Proceedings in Informatics (LIPics), Vol. 261), Kousha Etessami, Uriel Feige, and Gabriele Puppis (Eds.). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 127:1–127:20. https://doi.org/10.4230/LIPics.ICALP.2023.127
[15] J. Flum and M. Grohe. 2006. Parameterized Complexity Theory. Springer.
[16] Georg Gottlob, Gianluigi Greco, Nicola Leone, and Francesco Scarcello. 2016. Hypertree Decompositions: Questions and Answers. In Proceedings of the 35th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems, PODS 2016, San Francisco, CA, USA, June 26 - July 01, 2016, Tova Milo and Wang-Chiew Tan (Eds.). ACM, 57–74. https://doi.org/10.1145/2902251.2902309
[17] Georg Gottlob, Matthias Lanzinger, Reinhard Pichler, and Igor Razgon. 2021. Complexity Analysis of Generalized and Fractional Hypertree Decompositions. J. ACM 68, 5 (2021), 38:1–38:50.
[18] Georg Gottlob, Nicola Leone, and Francesco Scarcello. 2000. A comparison of structural CSP decomposition methods. Artif. Intell. 124, 2 (2000), 243–282.
[19] Martin Grohe. 2007. The complexity of homomorphism and constraint satisfaction problems seen from the other side. J. ACM 54, 1 (2007), 1–24.
[20] Martin Grohe and Dániel Marx. 2006. Constraint solving via fractional edge covers. In Proceedings of the Seventeenth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2006, Miami, Florida, USA, January 22-26, 2006. ACM Press, 289–298. http://dl.acm.org/citation.cfm?id=1109557.1109590
[21] Martin Grohe and Dániel Marx. 2014. Constraint Solving via Fractional Edge Covers. ACM Trans. Algorithms 11, 1 (2014), 4:1–4:20.
[22] Martin Grohe, Thomas Schwentick, and Luc Segoufin. 2001. When is the evaluation of conjunctive queries tractable?. In STOC 2001.
[23] P. Kolaitis and M. Vardi. 2000. Conjunctive-Query Containment and Constraint Satisfaction. J. Comput. System Sci. 61 (2000), 302–332.
[24] Dániel Marx. 2010. Can You Beat Treewidth? Theory of Computing 6, 1 (2010), 85–112.
[25] Dániel Marx. 2011. Tractable Structures for Constraint Satisfaction with Truth Tables. Theory of Computing Systems 48 (2011), 444–464.
[26] Dániel Marx. 2013. Tractable Hypergraph Properties for Constraint Satisfaction and Conjunctive Queries. J. ACM 60, 6 (2013), 42:1–42:51. https://doi.org/10.1145/2535926
[27] Nicole Schweikardt, Thomas Schwentick, and Luc Segoufin. 2009. Database Theory: Query Languages. In Algorithms and Theory of Computation Handbook (second ed.), Mikhail J. Atallah and Marina Blanton (Eds.). Vol. 2: Special Topics and Techniques. CRC Press, Chapter 19.
[28] Mihalis Yannakakis. 1981. Algorithms for Acyclic Database Schemes. In Very Large Data Bases, 7th International Conference, September 9-11, 1981, Cannes, France, Proceedings. IEEE Computer Society, 82–94.