Abstract
Deductive databases often struggle with recursive queries involving aggregation, such as shortest-path problems. This paper introduces a formal framework for "aggregate relevance" to prune irrelevant facts during computation. By combining program rewriting with ordered evaluation, the authors demonstrate that general-purpose logic engines can achieve the same $O(E \log V)$ complexity as specialized algorithms like Dijkstra’s, while maintaining a declarative approach.
Introduction
In the early 1990s, the field of deductive databases sought to bridge the gap between the expressive power of logic programming and the robust scalability of relational database management systems. A significant hurdle in this endeavor was the efficient handling of recursive queries that incorporate aggregate functions, such as min or max. While specialized algorithms like Dijkstra’s shortest path or Warshall’s algorithm provided efficient solutions for specific graph problems, integrating these efficiencies into a general-purpose, declarative framework remained a challenge. This paper addresses that gap by formalizing how aggregate constraints can be "pushed" into the recursive evaluation process.
The Challenge of Recursive Aggregation
Standard "bottom-up" evaluation methods in deductive databases are notoriously inefficient for aggregation. In a typical shortest-path query, a naive engine would exhaustively generate every possible path between nodes before applying an aggregate function at the final step to select the minimum. This leads to an exponential explosion of facts. The core problem is that the engine lacks a mechanism to discard a suboptimal fact (e.g., a longer path) as soon as a better one (e.g., a shorter path) is discovered. To solve this, the authors propose a method to identify and utilize "aggregate relevance."
The Proposed Framework
The authors introduce a two-pronged approach to optimize these queries through program transformation and refined evaluation strategies.
1. Program Rewriting (Push-Selections)
This stage involves an algebraic transformation of the logic program. The algorithm identifies "aggregate selections"—conditions that determine if a fact is relevant based on the aggregate operation being performed. For instance, in a shortest-path calculation, a path fact is only relevant if no shorter path to the same destination has already been established. The rewriting process "pushes" these selections directly into the rules, creating a "Smart" version of the program where predicates are dynamically labeled with pruning constraints.
2. Refined Evaluation Techniques
To execute the rewritten programs efficiently, the authors suggest two modifications to standard evaluation:
- Aggregate Retaining Evaluation: This is a modification of the Semi-Naive evaluation method. At the conclusion of each iteration, the system proactively discards any facts that fail the aggregate selection tests, preventing them from being used in subsequent recursive steps.
- Ordered Search: To further mimic specialized algorithms, the authors introduce an evaluation order that prioritizes facts with the "best" cost values (e.g., the smallest distance). This allows the database engine to function similarly to a priority queue in a procedural algorithm.
Key Insights: Global Relevance and IncSel
A pivotal contribution of this work is the distinction between local and global relevance. Traditional optimizations, such as "Magic Sets," focus on local relevance—whether a fact helps derive the final query. This paper introduces global relevance, where a fact's utility is determined by its relationship to other facts discovered during the search.
This is made possible through Incremental Aggregate Selectors (IncSel). These are specific functions, such as min, max, or top-k, that allow for early decision-making. With an IncSel function, the system can determine that a value is unnecessary even before the entire set of possible values has been generated.
Results and Complexity
The theoretical results of this framework are significant. The authors prove that by applying "Ordered Search" to a rewritten "Smart" program, a general-purpose deductive engine can reduce the complexity of the shortest path problem from exponential to $O(E \log V)$. This matches the complexity of a hand-tuned Dijkstra implementation while remaining entirely declarative.
Furthermore, the method is more general than previous contemporary approaches. It can handle stratified programs that are not strictly monotonic, allowing the system to process graphs with negative edge weights, provided no negative cycles exist. The paper provides formal proofs of soundness and completeness, ensuring that these optimizations do not alter the final result of the query.
Limitations and Future Work
While powerful, the technique is currently limited to "Incremental Aggregate Selectors." It does not easily extend to operations like sum or count, where every individual fact contributes to the final result and cannot be discarded early. Additionally, the approach assumes "stratified" aggregation, where the aggregate function is not part of its own definition cycle. The authors identify the extension of these techniques to unstratified programs and the reduction of constant-factor implementation overhead as primary areas for future research.
Summary updated