Lune

SIGMOD2023Top-tier venue

Computing the Difference of Conjunctive Queries Efficiently

Xiao Hu, Qichen Wang

Abstract

We investigate how to efficiently compute the difference result of two (or multiple) conjunctive queries, which is the last operator in relational algebra to be unraveled. The standard approach in practical database systems is to materialize the results for every input query as a separate set, and then compute the difference of two (or multiple) sets. This approach is bottlenecked by the complexity of evaluating every input query individually, which could be very expensive, particularly when there are only a few results in the difference. In this paper, we introduce a new approach by exploiting the structural property of input queries and rewriting the original query by pushing the difference operator down as much as possible. We show that for a large class of difference queries, this approach can lead to a linear-time algorithm, in terms of the input size and (final) output size, i.e., the number of query results that survive from the difference operator. We complete this result by showing the hardness of computing the remaining difference queries in linear time. Although a linear-time algorithm is hard to achieve in general, we also provide some heuristics that can provably improve the standard approach. At last, we compare our approach with standard SQL engines over graph and benchmark datasets. The experiment results demonstrate order-of-magnitude speedups achieved by our approach over the vanilla SQL engine.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

4 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Avoiding Materialisation for Guarded Aggregate Queries cites Conjunctive Queries with Comparisons
  • Relational Algorithms for Top-k Query Evaluation cites Conjunctive Queries with Comparisons
  • Succinct Structure Representations for Efficient Query Optimization cites Relational Algorithms for Top-k Query Evaluation
  • Succinct Structure Representations for Efficient Query Optimization cites Yannakakis+: Practical Acyclic Query Evaluation with Theoretical Guarantees
  • Succinct Structure Representations for Efficient Query Optimization cites Conjunctive Queries with Comparisons
  • Yannakakis+: Practical Acyclic Query Evaluation with Theoretical Guarantees cites Relational Algorithms for Top-k Query Evaluation
  • Yannakakis+: Practical Acyclic Query Evaluation with Theoretical Guarantees cites Conjunctive Queries with Comparisons
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers4

  1. Avoiding Materialisation for Guarded Aggregate QueriesMatthias Lanzinger, Reinhard Pichler, Alexander SelzerVLDB 2025 · 7 citations
  2. Yannakakis+: Practical Acyclic Query Evaluation with Theoretical GuaranteesQichen Wang, Bingnan Chen, Binyang Dai, Ke Yi et al.SIGMOD 2025 · 7 citations
  3. Relational Algorithms for Top-k Query EvaluationQichen Wang, Qiyao Luo, Yilei WangSIGMOD 2024 · 5 citations
  4. Succinct Structure Representations for Efficient Query OptimizationZhekai Jiang, Qichen Wang, Christoph KochSIGMOD 2026

Builds on3

  1. Conjunctive Queries with ComparisonsQichen Wang, Ke YiSIGMOD 2022 · 13 citations
  2. Computing Complex Temporal Join Queries EfficientlyXiao Hu, Stavros Sintos, Junyang Gao, Pankaj K. Agarwal et al.SIGMOD 2022 · 9 citations
  3. Density-optimized Intersection-free Mapping and Matrix Multiplication for Join-Project OperationsZichun Huang, Shimin ChenVLDB 2022 · 9 citations

Related papers

  1. Aggregated Deletion Propagation for Counting Conjunctive Query AnswersXiao Hu, Shouzhuo Sun, Shweta Patwa, Debmalya Panigrahi et al.VLDB 2021 · 7 citations
  2. A Compiler for Fused Relational Operations on MultisetsJames Dong, Fredrik KjolstadPLDI 2026
  3. Towards a Converged Relational-Graph Optimization FrameworkYunkai Lou, Longbin Lai, Bingqing Lyu, Yufan Yang et al.SIGMOD 2025 · 4 citations
  4. Polygon: Symbolic Reasoning for SQL using Conflict-Driven Under-Approximation SearchPinhan Zhao, Yuepeng Wang, Xinyu WangPLDI 2025
  5. SPES: A Symbolic Approach to Proving Query Equivalence Under Bag SemanticsQi Zhou, Joy Arulraj, Shamkant B. Navathe, William Harris et al.ICDE 2022 · 19 citations
Dusk over the sea between two cliffs drawn in fine vertical lines