Incremental Maintenance of Aggregate Views Abhijeet Mohapatra and Michael Genesereth Stanford University {abhijeet, genesereth}@stanford.edu Abstract. We propose an algorithm called CReaM to incrementally maintain materialized aggregate views with user-defined aggregates in response to changes to the database tables from which the view is derived. CReaM is optimal and guar- antees the self-maintainability of aggregate views that are defined over a single database table. For aggregate views that are defined over multiple database ta- bles and do not contain all of the non-aggregated attributes in the database tables, CReaM speeds up the time taken to update a view as compared to prior view maintenance techniques. The speed up in the time taken to update a materialized view with n tuples is either n log n or log n depending on whether the physical de- sign of the underlying database is optimized or not. For other types of aggregate views, CReaM updates the view in no more time than that is required by prior view maintenance techniques to update the view. 1 Introduction In data management systems, views are derived relations that are computed over databa- se tables (which are also known as extensional database relations or edbs). Views are materialized in a database to support efficient querying of the data. A materialized view becomes out-of-date when the underlying edb relations from which the view is derived are changed. In such cases, the materialized view is either recomputed from the edb relations or the changes in the edb relations are incrementally propagated to the view to ensure the correctness of the answers to queries against the view. Prior work presented in [5, 20, 26] shows that incrementally maintaining a materialized view can be signifi- cantly faster than recomputing the view from the edb relations especially if the size of the view is large compared to the size of the changes. Several techniques [1–6, 10, 14–16, 18, 20–22, 25–27, 29–31, 33] have been prop- osed to incrementally maintain views in response to changes to the edb relations. How- ever, only a small fraction of the prior work on incremental view maintenance [10, 14, 15, 20, 23, 26, 27] addresses the maintenance of views that contain aggregates such as sum and count. The techniques proposed in [10, 14, 20, 23] incrementally maintain views that have only one aggregation operator. Furthermore, the incremental main- tenance algorithms presented in [10, 14, 15, 20, 23, 26, 27] support only a fixed set of built-in aggregate operators (min, max, sum, and count). In contrast, we present an algorithm to incrementally maintain views with multiple aggregates each of which could be user-defined. As our underlying query language, we extend Datalog using tuples and sets, and express aggregates as predicates over sets. In section 2, we discuss the specification of user-defined aggregates in our language.