Algorithms for Rewriting Aggregate Queries Using Views

Sara Cohen, Werner Nutt, Alexander Serebrenik

TL;DR

This paper tackles the challenge of optimizing aggregate queries (like SUM, COUNT, MIN, MAX) by rewriting them to leverage pre-computed views. They introduce a formal framework and practical algorithms for this task, aiming for sound and complete rewritings, which are crucial for efficient data warehousing and information systems.

What Problem Does This Paper Address?

In data-intensive applications like data warehousing, aggregate queries are common but computationally expensive. A key optimization strategy is to reuse previously computed results stored in "views." However, rewriting aggregate queries to effectively use these views is complex. Existing approaches were often "ad-hoc," meaning they produced correct rewritings but couldn't guarantee finding a rewriting if one existed, nor could they find all possible rewritings. This paper aims to bridge this gap by providing a theoretical foundation and practical algorithms for systematically generating complete and sound rewritings of aggregate queries using views.

Methods

The authors extend the Datalog query language to formally handle aggregate queries. They then develop a framework for defining "equivalence modulo a set of views," which is essential for verifying if a rewritten query using views is equivalent to the original query. The core of their contribution lies in presenting practical algorithms for rewriting specific types of aggregate queries:

  • Count-Queries: They focus on using "count-views" for rewriting count-queries, as these views preserve multiplicity information crucial for counts. They introduce "count-rewriting candidates" and an algorithm that incrementally covers the query body with views.
  • Sum-Queries: Similar to count-queries, sum-views are important. Their algorithm for sum-queries builds upon the count-query algorithm, handling the specific challenges of sum aggregation.
  • Max-Queries: For max-queries, which are insensitive to multiplicities, they leverage non-aggregate views and at most one max-view. They adapt existing algorithms for non-aggregate queries, like the "buckets algorithm," to handle max-queries.

A key technique used throughout is "unfolding," where view definitions are substituted into the query to create an equivalent query that only uses base relations. This allows for easier comparison and verification.

Datasets

Not discussed in the paper. The paper uses examples to illustrate its concepts and algorithms, but does not refer to specific datasets for training or evaluation.

Key Insights and Ideas

  • Formalizing Equivalence Modulo Views: The paper introduces a crucial concept of "equivalence modulo a set of views." This is vital because a rewriting doesn't just need to be equivalent to the original query; it must also be expressible using the defined views.
  • Count-Views are King for Count-Queries: They highlight that only count-views are truly useful for rewriting count-queries because they preserve the multiplicity information that is fundamental to counting.
  • The "Unfolding" Technique is Central: The paper heavily relies on the "unfolding" of queries and views. This process of substituting view definitions into a query allows for a more direct comparison of queries and is key to their algorithmic approach.
  • Bridging Theory and Practice: While previous work provided theoretical characterizations, this paper focuses on deriving practical algorithms that can be implemented in optimizers.
  • Generalizing Non-Aggregate Techniques: A significant insight is that many techniques for rewriting non-aggregate queries can be adapted and extended to handle aggregate queries, albeit with specific considerations for each aggregation type.

Key Results

The paper presents algorithms for rewriting count, sum, and max queries using views. They demonstrate that these algorithms are:

  • Sound: They always produce valid rewritings.
  • Complete for Important Cases: For relational and linear queries (a common and practical subset), their algorithms are proven to be complete, meaning they will find a rewriting if one exists.
  • Tractable: The algorithms are designed to run in nondeterministic polynomial time, making them practical for query optimization.

Limitations and Future Work

  • Completeness for General Queries: While complete for linear and relational queries, the algorithms are noted as not being complete for arbitrary aggregate queries. This suggests that finding rewritings for more complex query structures remains an open challenge.
  • Efficiency Trade-offs: The paper acknowledges that achieving both efficiency and completeness might require trade-offs, and their algorithms aim for a good balance.
  • Future Work: The authors suggest that their techniques can be adapted to improve existing algorithms for rewriting relational queries, and that further research could explore more expressive query languages and handling of more complex aggregate scenarios. They also mention that their algorithms have been implemented in SICStus Prolog, indicating a path towards practical application.

Summary updated

BibTeX
@inproceedings{cohen2000algorithms,
  author = {Sara Cohen and Werner Nutt and Alexander Serebrenik},
  title = {{Algorithms for Rewriting Aggregate Queries Using Views}},
  booktitle = {Adbis-dasfaa},
  year = {2000},
  doi = {10.1007/3-540-44472-6\_6},
}
Figure