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 about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 1c722386-233e-49fd-8bbb-cb33bc1cb02eCited by top-tier papers4
- Avoiding Materialisation for Guarded Aggregate QueriesMatthias Lanzinger, Reinhard Pichler, Alexander SelzerVLDB 2025 · 7 citations
- Yannakakis+: Practical Acyclic Query Evaluation with Theoretical GuaranteesQichen Wang, Bingnan Chen, Binyang Dai, Ke Yi et al.SIGMOD 2025 · 7 citations
- Relational Algorithms for Top-k Query EvaluationQichen Wang, Qiyao Luo, Yilei WangSIGMOD 2024 · 5 citations
- Succinct Structure Representations for Efficient Query OptimizationZhekai Jiang, Qichen Wang, Christoph KochSIGMOD 2026
Builds on3
- Conjunctive Queries with ComparisonsQichen Wang, Ke YiSIGMOD 2022 · 13 citations
- Computing Complex Temporal Join Queries EfficientlyXiao Hu, Stavros Sintos, Junyang Gao, Pankaj K. Agarwal et al.SIGMOD 2022 · 9 citations
- Density-optimized Intersection-free Mapping and Matrix Multiplication for Join-Project OperationsZichun Huang, Shimin ChenVLDB 2022 · 9 citations
Related papers
- Aggregated Deletion Propagation for Counting Conjunctive Query AnswersXiao Hu, Shouzhuo Sun, Shweta Patwa, Debmalya Panigrahi et al.VLDB 2021 · 7 citations
- A Compiler for Fused Relational Operations on MultisetsJames Dong, Fredrik KjolstadPLDI 2026
- Towards a Converged Relational-Graph Optimization FrameworkYunkai Lou, Longbin Lai, Bingqing Lyu, Yufan Yang et al.SIGMOD 2025 · 4 citations
- Polygon: Symbolic Reasoning for SQL using Conflict-Driven Under-Approximation SearchPinhan Zhao, Yuepeng Wang, Xinyu WangPLDI 2025
- 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
