Conjunctive Queries with Arithmetic Comparisons
- CQAC is an extension of classical conjunctive queries that integrates arithmetic comparisons to enable precise filtering and advanced query rewriting.
- The approach leverages hypergraph characterizations and min/max predicates to delineate tractability boundaries and establish fine-grained complexity dichotomies.
- Applications span analytical SQL querying, OLAP, and view-based data management, while ongoing research explores query containment and efficient evaluation techniques.
A conjunctive query with arithmetic comparisons (CQAC) is a fundamental extension of classical conjunctive queries (CQs) that augments relational atoms with built-in arithmetic comparisons—inequalities, equalities, and disequalities—between variables and constants. The CQAC framework underpins both theoretical and practical questions in database theory, especially around the expressiveness, evaluation complexity, and containment of query languages, and is critically involved in query rewriting and certain-answer computation over incomplete data. Of particular recent interest is the subclass of CQACs involving minimum or maximum constraints (e.g., ), which yields intricate complexity dichotomies in ranked enumeration, direct access, and predicate elimination for self-join-free queries.
1. Formal Definitions and Syntax
A conjunctive query with arithmetic comparisons (CQAC) over a relational schema is written: where each is a relational atom, and is a finite conjunction of arithmetic atoms of the form with , . The set of distinguished (head) variables must appear in the body. All variables in the head or in any comparison must also occur in at least one relational atom (the "safety" restriction).
The semantics of CQAC is standard: for a database instance and assignment 0, 1 if 2 makes all relational atoms true on 3 and all arithmetic atoms true in the natural order or arithmetic structure (4, 5, or 6 as domain).
Special attention is given to semi-interval comparisons:
- Left semi-interval (LSI): 7 or 8
- Right semi-interval (RSI): 9 or 0
For CQACs with min/max, one further allows min-predicates (1) and max-predicates (2), where 3 is a set of variables. If 4, then 5 is equivalent to 6 (Carmeli et al., 22 Oct 2025, Afrati et al., 12 Sep 2025, Afrati et al., 2020).
2. Structural Properties and Hypergraph Characterization
The evaluation and tractability of CQACs—especially with min/max—are strongly governed by the structural properties of their relational hypergraphs:
- The hypergraph 7 has as vertices the variables of 8 and as edges the variable sets of each atom 9.
- 0 is acyclic if 1 admits a join-tree (α-acyclicity).
- 2 is free-connex if 3, i.e., the hypergraph augmented with a hyperedge for the distinguished variables, is also acyclic.
The tractability of many key CQAC tasks depends on the absence of bad paths, a notion formalized as follows for self-join-free CQs with min/max predicates:
- There is a bad path between 4 and 5 (for 6) if there exists a chordless path of length at least three in the hypergraph connecting 7 to some 8 (Carmeli et al., 22 Oct 2025).
3. Fine-Grained Complexity Dichotomies
Research has established a precise landscape of tractability for natural computational problems concerning CQACs—especially those with min/max comparisons—in terms of structural and comparison-pattern restrictions.
Table: Complexity Dichotomies for CQAC Tasks with Min/Max (Carmeli et al., 22 Oct 2025)
| Task | Tractable Class | Complexity (Tractable) | Intractable If |
|---|---|---|---|
| Counting | Free-connex acyclic, no bad path | 9 time | Not free-connex acyclic or bad path exists |
| Ranked Enumeration | Free-connex acyclic | 0 preprocessing + 1 delay | Otherwise |
| Direct Access | Free-connex acyclic, no bad path | 2 access | Otherwise |
| Predicate Elimination | Free-connex acyclic, no bad path | 3 time | Otherwise |
Here, "no bad path" refers to the absence of chordless length-4 paths between critical min/max variables, and 5 hides polylogarithmic factors. Lower bounds are conditioned on Hypotheses such as SETH (Strong Exponential Time Hypothesis) and Hyperclique (Carmeli et al., 22 Oct 2025).
4. Algorithmic and Proof Techniques
Positive results for CQAC evaluation leverage several key procedural insights. For acyclic queries:
- Semiring Aggregation: Aggregating over commutative semirings (sum-product, min-max, etc.) on full acyclic queries enables 6 bottom-up computation (Yannakakis-style algorithms).
- Min-predicate elimination: Partition total orders on variables into a constant-size set of partial orders making 7 minimal. For each, pick a join tree that enforces the cover-inequalities, then apply semijoin and filter steps to reduce to standard acyclic CQs, allowing decomposition of 8 into a small union of simpler queries (Carmeli et al., 22 Oct 2025).
- Direct access and enumeration: Utilization of secondary data structures for variable-lexicographic order, prefix sums, and repeated parallel enumeration with duplicate suppression ensure constant or logarithmic output delay given acyclicity and absence of bad paths.
Lower bounds use standard reductions:
- Enumeration or access hardness for non-free-connex queries reduces to Boolean matrix multiplication or triangle-detection. Counting for queries with a chordless path (length 9) on equality incurs SETH/Hyperclique lower bounds (Carmeli et al., 22 Oct 2025).
Containment and certain answer computation employ containment-implication conditions and Datalog transformations (Afrati et al., 12 Sep 2025, Afrati et al., 2020):
- Containment 0 reduces to testing 1 for all containment mappings 2 of bodies.
- For RSI1 CQACs (at most one RSI, possibly multiple LSIs, all closed), containment is in NP; for arbitrary CQACs, 3-complete (Afrati et al., 12 Sep 2025, Afrati et al., 2020).
- Maximally contained rewriting (MCR) and certain answers computation transform CQAC to Datalog4, run the inverse-rule algorithm, and re-express as CQAC or unions thereof; RSI1 admits PTIME certain answers (Afrati et al., 12 Sep 2025, Afrati et al., 2020).
For count-distinct aggregates, equivalence is determined by computing cores and their "flips," the latter reversing inequalities inside equal-sets; decision lies in the third level of the polynomial hierarchy, 5, and is strictly harder than core-isomorphism for standard CQAC equivalence (Hariri et al., 2015).
5. Syntactic Restrictions and Complexity Boundaries
The expressiveness and tractability of CQACs pivot on the pattern and number of arithmetic comparisons. Key restriction classes include:
- RSI1: At most one RSI plus any number of LSIs (all closed). Containment falls in NP, certain answer computation in PTIME (Afrati et al., 12 Sep 2025, Afrati et al., 2020).
- One-AC: Containing CQAC with at most one non-equality AC: containment in NP (Afrati et al., 12 Sep 2025).
- Semi-interval-only: All comparisons are SI (open/closed). If containing CQ is only open SI (with or without 6), containment is 7-complete (Afrati et al., 12 Sep 2025).
- General CQACs: Allowing joins between head/body vars or multiple (open/closed) ACs, the containment and certain answer problems are 8-complete (Afrati et al., 12 Sep 2025, Afrati et al., 2020).
- Min/Max: For CQAC with predicates of the form 9 or 0, near-ideal complexity is obtained precisely under the free-connex acyclic/no-bad-path regime (Carmeli et al., 22 Oct 2025).
These dichotomies delineate the boundary between efficient and intractable cases—there is no PTIME algorithm for containment or MCR in the general case unless the polynomial hierarchy collapses.
6. Applications, Open Problems, and Research Directions
CQACs with arithmetic constraints model a variety of analytical SQL queries with filters (e.g., time windows, price ranges, top-1, or sliding aggregates) and arise naturally in data integration, OLAP, and view-based data management. The fine-grained dichotomies directly inform query optimizer strategies and complexity-aware data infrastructure.
Key open research directions include:
- Extension to multiple min/max or mixed min/max predicates; current dichotomies treat single min/max only (Carmeli et al., 22 Oct 2025).
- Generalization to arbitrary linear or polynomial arithmetic comparisons (e.g., 2) and aggregates beyond min/max (e.g., 3th smallest, HAVING clauses, SUM/AVG), requiring new combinatorial and algorithmic techniques (Carmeli et al., 22 Oct 2025, Hariri et al., 2015).
- Relaxation of self-join-free and bounded-treewidth conditions—quantifying complexity as join patterns grow more intricate (Carmeli et al., 22 Oct 2025).
- Improved understanding of containment and certain answers for count-distinct and other aggregates, especially over discrete domains (Hariri et al., 2015).
The development of semiring-aggregation in full acyclic CQs, order-partitioning of min/max constraints, and the reciprocal use of Datalog4 transformations are anticipated to drive advances for CQAC in both expressiveness and computational tractability. The study of CQAC thus remains a central point of interplay between descriptive complexity, database theory, and practical querying (Carmeli et al., 22 Oct 2025, Afrati et al., 12 Sep 2025, Afrati et al., 2020, Hariri et al., 2015).