Skip to main content
QUICK REVIEW

[Paper Review] Any-k Algorithms for Enumerating Ranked Answers to Conjunctive Queries

Nikolaos Tziavelis, Wolfgang Gatterbauer|arXiv (Cornell University)|May 11, 2022
Data Management and AlgorithmsComputer Science7 citations
TL;DR

This paper introduces novel 'any-k' algorithms for efficiently enumerating ranked answers to conjunctive queries (CQs) by pushing ranking functions—such as sum-of-weights—into the join computation, avoiding full materialization. The approach achieves O(n + k log k) time complexity for data complexity, matching the theoretical lower bound up to a logarithmic factor, and outperforms traditional 'join-then-rank' methods in practice.

ABSTRACT

We study ranked enumeration for Conjunctive Queries (CQs) where the answers are ordered by a given ranking function (e.g., an ORDER BY clause in SQL). We develop "any-k" algorithms, which, without knowing the number k of desired answers, push down the ranking into joins by carefully ordering the computation of intermediate tuples and avoiding materialization of join answers until they are needed. For this to be possible, the ranking function needs to obey a particular type of monotonicity. Supported ranking functions include the common sum-of-weights, where answers are compared by the sum of input-tuple weights, as well as any commutative selective dioid. Our results extend a well-known unranked-enumeration dichotomy, which states that only free-connex CQs are tractable (under certain hardness hypotheses and for CQs without self-joins). For this class of queries and with n denoting the size of the input, the data complexity of our ranked enumeration approach for the time to the kth CQ answer is O(n+klogk), which is only a logarithmic factor slower than the O(n+k) unranked-enumeration guarantee. A core insight of our work is that ranked enumeration for CQs is closely related to Dynamic Programming and the fundamental task of path enumeration in a weighted DAG. We uncover a previously unknown tradeoff: one any-k algorithm has lower complexity when the number of returned answers is small, the other when their number is large. This tradeoff is eliminated under a stricter monotonicity property that we define and exploit for a novel algorithm that asymptotically dominates all previously known alternatives, including Eppstein's algorithm for sum-of-weights path enumeration. We empirically demonstrate the findings of our theoretical analysis in an experimental study that highlights the superiority of our approach over the join-then-rank approach that existing database systems follow.

Motivation & Objective

  • To address the performance bottleneck of traditional 'join-then-rank' approaches in database systems that materialize all answers before sorting.
  • To develop efficient, anytime algorithms that return answers in ranked order without prior knowledge of k, the number of desired results.
  • To extend the unranked enumeration dichotomy to ranked enumeration by identifying conditions under which efficient ranked enumeration is possible.
  • To unify and generalize prior work on k-shortest paths, ranked retrieval, and dynamic programming under a single framework based on commutative selective dioids.
  • To demonstrate the superiority of the proposed approach over existing database systems through empirical evaluation.

Proposed method

  • Introduces subset-monotonicity (s-monotonicity) as a sufficient condition for efficient ranked enumeration, ensuring that partial solutions can be extended in a way that preserves ranking order.
  • Leverages the algebraic structure of commutative selective dioids to model ranking functions, enabling the application of dynamic programming principles to CQs.
  • Designs two core algorithms: anyK-rec, based on recursive enumeration of deviations (inspired by REA), and anyK-part, based on the Lawler-Murty procedure for k-shortest paths.
  • Develops anyK-part+, a novel algorithm that asymptotically dominates previous methods, including Eppstein’s algorithm, by eliminating the O(ℓ) path length dependency in complexity.
  • Applies the framework to acyclic and free-connex CQs, with extension to cyclic CQs via decomposition, and generalizes to any problem solvable via dynamic programming with a semiring structure.
  • Empirically evaluates the algorithms against traditional 'join-then-rank' strategies, showing significant performance gains in practice.

Experimental results

Research questions

  • RQ1Can ranked enumeration for conjunctive queries be performed efficiently without materializing all intermediate results?
  • RQ2What algebraic and structural properties of ranking functions enable efficient any-k enumeration?
  • RQ3How does the complexity of ranked enumeration compare to unranked enumeration, and can it achieve near-optimal performance?
  • RQ4Can existing k-shortest path algorithms be generalized and improved to handle general conjunctive queries with arbitrary ranking functions?
  • RQ5Is there a unified framework that connects ranked enumeration in CQs, dynamic programming, and path enumeration in weighted DAGs?

Key findings

  • The proposed anyK-part+ algorithm achieves O(n + k log k) time complexity for data complexity, which is asymptotically optimal up to a logarithmic factor.
  • The framework supports a broad class of ranking functions, including sum-of-weights and any commutative selective dioid, enabling generalization beyond simple aggregation.
  • The algorithms outperform traditional 'join-then-rank' approaches in practice, especially when k is small, due to early pruning and avoidance of full result materialization.
  • Subset-monotonicity is identified as a key sufficient condition for efficient ranked enumeration, and it is shown to be compatible with the algebraic structure of commutative selective dioids.
  • The work establishes a theoretical foundation linking ranked enumeration in CQs to dynamic programming and k-shortest paths, unifying previously isolated lines of research.
  • The approach generalizes to problems such as DNA sequence alignment and Viterbi decoding, demonstrating broad applicability beyond relational databases.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.