On the Convergence Rate of Linear Datalogo over Stable Semirings

Sungjin Im, Benjamin Moseley, Hung Q. Ngo, Kirk Pruhs · DOI

Introduction

Recursive query languages are essential for modern data analytics, particularly when dealing with graph-structured data or complex network dependencies. Datalog◦ represents a significant evolution in this field, extending traditional Datalog to support recursive computations over algebraic structures known as semirings. This extension allows for the seamless integration of aggregation and recursion, enabling queries such as shortest-path calculations (using the tropical semiring) or network reliability analysis.

However, the power of Datalog◦ comes with a theoretical challenge: convergence. While standard Datalog is guaranteed to terminate efficiently, Datalog◦ programs over certain semirings can exhibit slow convergence or even fail to terminate. Previous research established that convergence is guaranteed on "stable" semirings, but the best-known upper bounds for the number of iterations required were exponential ($O(p^n)$). This paper addresses this gap by providing the first polynomial-time convergence guarantees for the widely used class of linear Datalog◦ programs.

The Convergence Challenge in Recursive Analytics

In Datalog◦, a program is considered "linear" if each rule contains at most one recursive atom. These programs are the "bread and butter" of recursive queries. Despite their ubiquity, their theoretical efficiency remained poorly understood. The primary concern was the "iteration count"—how many times the system must apply its update rules before the results stop changing.

Prior to this work, the gap between practical performance and theoretical bounds was vast. While practitioners observed relatively fast convergence in real-world applications, the mathematical safety net was an exponential bound that suggested these queries might become intractable as the dataset size ($n$) grew. This paper aims to reconcile theory with practice by proving that for linear programs, the worst-case scenario is actually polynomial.

Methodology: From Logic to Linear Algebra

The authors approach the problem by treating a linear Datalog◦ program as a linear algebraic system. They model the "Immediate Consequence Operator"—the function that computes new facts from existing ones—as a linear function: $f(x) = Ax + b$. Here, $A$ is a matrix representing the recursive rules, and $b$ represents the base facts.

To analyze the convergence of this system, the authors employ a graph-theoretic decomposition:

  1. Matrix as Graph: The matrix $A$ is viewed as a directed graph where edges are labeled with elements from the semiring.
  2. Walk Decomposition: The value of a query after $k$ iterations is shown to be the sum of all "walks" in this graph with a length of up to $k$.
  3. Pigeonhole Principle and Stability: The core of the proof relies on $p$-stability. A semiring is $p$-stable if, for any element $a$, the sum of $p$ instances of $a$ is equal to the sum of $p+1$ instances. By applying the pigeonhole principle to long walks, the authors demonstrate that any walk exceeding a specific threshold must contain cycles that repeat. Due to $p$-stability, these repeating cycles eventually stop contributing new information to the total sum, leading to convergence.

Key Theoretical Results

The paper establishes several new upper bounds that significantly improve our understanding of Datalog◦ complexity:

  • General Polynomial Bound: For any linear Datalog◦ program over a $p$-stable semiring, convergence is reached in $O(pn^3)$ steps. This replaces the previous $O((p+1)^n)$ exponential bound, providing a robust theoretical guarantee for efficiency.
  • Small Semiring Bound: In cases where the semiring has a finite ground set of $L$ elements, the bound improves to $O(pn \log L)$. This suggests that the complexity is even lower when the range of possible values is restricted.
  • Naturally Ordered Semirings: For semirings that possess a "natural order" with a maximum chain length of $k$, the authors prove a tighter bound of $O(kn)$.

Notably, the authors also clarify the state of the field by correcting a previous claim regarding lower bounds. While it was once thought that $n^3$ was a strictly necessary bound, the authors acknowledge that proving a matching lower bound remains an open and subtle challenge.

Implications and Future Work

This research provides the first efficient theoretical guarantees for a critical class of recursive queries. By proving that linear Datalog◦ converges in polynomial time, the authors provide a mathematical foundation for the high performance observed in modern deductive database systems.

However, several questions remain. While $O(pn^3)$ is polynomial, it may still be pessimistic; for specific instances like the tropical semiring, the actual convergence rate is known to be $O(pn)$. Furthermore, the bounds for non-linear Datalog◦ programs—where rules may contain multiple recursive atoms—remain exponential in the worst case. Future research will likely focus on narrowing the gap between the $n^3$ and $n$ bounds and exploring whether similar polynomial guarantees can be extended to broader classes of non-linear programs.

Summary updated

BibTeX
@inproceedings{im2024convergence,
  author = {Sungjin Im and Benjamin Moseley and Hung Q. Ngo and Kirk Pruhs},
  title = {{On the Convergence Rate of Linear Datalogo over Stable Semirings}},
  booktitle = {ICDT},
  year = {2024},
  url = {https://openreview.net/forum?id=mH0TWjPrTi},
}
Figure