






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







University of Washington [email protected]
University of Washington [email protected]
The problem of answering queries using views is to find efficient methods of answering a query us- ing a set of previously materialized views over the database, rather than accessing the database rela- tions. The problem has received significant atten- tion because of its relevance to a wide variety of data management problems, such as data integra- tion, query optimization, and the maintenance of physical data independence. To date, the perfor- mance of proposed algorithms has received very little attention, and in particular, their scale up in the presence of a large number of views is un- known.
We first analyze two previous algorithms, the bucket algorithm and the inverse-rules algorithm, and show their deficiencies. We then describe the MiniCon algorithm, a novel algorithm for find- ing the maximally-contained rewriting of a con- junctive query using a set of conjunctive views. We present the first experimental study of algo- rithms for answering queries using views. The study shows that the MiniCon algorithm scales up well and significantly outperforms the previous al- gorithms. Finally, we describe an extension of the MiniCon algorithm to handle comparison predi- cates, and show its performance experimentally.
Manolescu, Dan Weld, and Steve Wolfman for their comments on ear- lier drafts of this paper. This research was funded by a Sloan Fellowship, NSF Grant #IIS-9978567, a NSF Graduate Research Fellowship, and a Lucent Technologies GRPW Grant
Permission to copy without fee all or part of this material is granted pro- vided that the copies are not made or distributed for direct commercial advantage, the VLDB copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Very Large Data Base Endowment. To copy otherwise, or to republish, requires a fee and/or special permission from the Endowment.
Proceedings of the 26th VLDB Conference, Cairo, Egypt, 2000.
The problem of answering queries using views (a.k.a. rewriting queries using views) has recently received sig- nificant attention because of its relevance to a wide vari- ety of data management problems [20]: query optimiza- tion [6, 21, 36], maintenance of physical data indepen- dence [35, 33, 27], data integration [22, 9, 18, 19], and data warehouse and web-site design [16, 32]. Informally speak- ing, the problem is the following. Suppose we are given a query
over a database schema, and a set of view def-
to answer the query
using only the answers to the views
There are two main contexts in which the problem of answering queries using views has been considered. In the first context, where the goal is query optimization or maintenance of physical data independence [35, 33, 6], we search for an expression that uses the views and is equiva- lent to the original query. Here it is usually assumed that the number of views is on the same order as the size of the schema. The second context is that of data integration, where views describe a set of autonomous heterogenous data sources. A user poses a query in terms of a mediated schema, and the data integration system needs to reformu- late the query to refer to the data sources. In a subsequent phase, the queries over the sources are optimized and ex- ecuted. The reformulation problem can be solved by al- gorithms for answering queries using views, though in this context, we usually cannot find a rewriting that is equiva- lent to the user query because of the data sources’ limited coverage. Instead, we search for a maximally-contained rewriting , which provides the best answer possible, given the available sources. When the query and views are con- junctive (i.e., select-project-join) without comparison pred- icates, the maximally-contained rewriting is a union of con- junctive queries over the views. The key challenge in this context is to develop an algorithm that scales up in the num- ber of views. We consider the problem of answering conjunctive queries using a set of conjunctive views in the presence of a large number of views. In general, this problem is NP-Complete because it involves searching through a pos- sibly exponential number of rewritings [21]. Previous work has mainly considered two algorithms for this purpose.
The bucket algorithm, developed as part of the Information Manifold System [22], controls its search by first consid- ering each subgoal in the query in isolation, and creating a bucket that contains only the views that are relevant to that subgoal. The algorithm then creates rewritings by combin- ing one view from every bucket. As we show, the com- bination step has several deficiencies, and does not scale up well. The inverse-rules algorithm, developed primarily in the InfoMaster System [29, 8], considers rewritings for each database relation independent of any particular query. Given a user query, these rewritings are combined appropri- ately. We show that the rewritings produced by the inverse- rules algorithm need to be further processed in order to be appropriate for query evaluation. Unfortunately, in this ad- ditional processing step the algorithm must duplicate much of the work done in the second phase of the bucket algo- rithm. Based on the insights into the previous algorithms, we introduce the MiniCon algorithm, which addresses their limitations and scales up to a large number of views. The key idea underlying the MiniCon algorithm is a change of perspective: instead of building rewritings by combining rewritings for each query subgoal or database relation, we consider how each of the variables in the query can inter- act with the available views. The result is that the second phase of the MiniCon algorithm needs to consider drasti- cally fewer combinations of views. Hence, as we show ex- perimentally, the MiniCon algorithm scales up much better. The specific contributions of the paper are the following:
analysis of algorithms for answering queries using views. The experimental results show (1) the Mini- Con algorithm significantly outperforms the bucket and inverse-rules algorithms, (2) the MiniCon algo- rithm scales up to hundreds of views, thereby showing for the first time that answering queries using views can be efficient on large scale problems. We believe that our experimental evaluation in itself is a signifi- cant contribution that fills a void in previous work on this topic.
to handle comparison predicates and experimental re- sults on its performance.
This paper focuses on the problem of answering queries using views for select-project-join queries under set seman- tics. While such queries are quite common in data inte- gration applications, many applications will need to deal with queries involving grouping and aggregation, semi- structured data, nested structures and integrity constraints. Indeed, the problem of answering queries using views has been considered in these contexts as well [15, 31, 7, 13, 26, 4, 10, 14]. In contrast to these works, our focus is on obtaining a scalable algorithm for answering queries us- ing views and the experimental evaluation of such algo- rithms. Hence, we begin with the class of select-project- join queries.
The paper is organized as follows. Section 2 presents the problem formally, and Section 3 discusses the limita- tions of the previous algorithms. Section 4 describes the MiniCon algorithm, and Section 5 presents the experimen- tal evaluation. Section 6 describes an extension of the MiniCon algorithm to comparison predicates. Section 7 discusses related work and Section 8 concludes.
Queries and views: We consider the problem of answer- ing queries using views for conjunctive queries (i.e., select- project-join queries). A conjunctive query has the form:
are the subgoals in the body of the
is called the head of the query, and refers to the
contain either variables or constants. We require that the query be safe ,
(that is, every variable that appears in the head must also appear in the body). The
are the distinguished variables of the query, and all the others are existential variables. We denote in-
, and
Note that unions can be expressed in this notation by allowing a set of conjunctive queries with the same head predicate. A view is a named query. If the query results are stored, we refer to them as a materialized view, and we refer to the result set as the extension of the view. In Section 6 we consider queries that contain subgoals with
Example 2.1 Consider the following schema that we use throughout the paper. The relation cites(p1,p2) stores pairs of publication identifiers where p1 cites p2. The rela- tion sameTopic stores pairs of papers that are on the same topic. The unary relations inSIGMOD and inVLDB store ids of papers published in SIGMOD and VLDB respec- tively. The following query asks for pairs of papers on the same topic that also cite each other. Note that join predi- cates in this notation are expressed by multiple occurrences of the same variables.
Query containment and equivalence: The concepts of query containment and equivalence enable us to compare between queries and rewritings. We say that a query
contained in the query
, denoted by
, if the an- swer to
for any database instance. We say that
are equivalent if
and
Containment mappings provide a necessary and suffi- cient condition for testing query containment. A mapping
above (1)
, and there exists at least one
Given a conjunctive query
and a set of conjunctive
tive query may be a union of conjunctive queries (we refer to the individual conjunctive queries as conjunctive rewrit- ings ). When the queries and the views are conjunctive and do not contain comparison predicates, it follows from [21] that we need only consider conjunctive rewritings
that have at most the number of subgoals in the query
Remark 1 It is important to emphasize at this point that the definitions considered in this section only ensure that the rewriting of the query obtains as many answers as pos- sible from a set of views, which is the main concern in the context of data integration. We are not considering here the problem of finding the rewriting that yields the cheapest query execution plan over the views, which would be the main concern when using algorithms for answering queries using views for query optimization and maintenance of physical data independence. In the concluding section we revisit this issue. In addition, we do not consider here the
The theoretical results on answering queries using views [21] showed that when there are no comparison pred- icates in the query, the search for a maximally-contained rewriting can be confined to a finite space: an algorithm
query. Two previous algorithms, the bucket algorithm and the inverse-rules algorithm, attempted to find more effec- tive methods to produce rewritings that do not require such exhaustive search. In this section we briefly describe these algorithms and point out their limitations. In Section 5 we compare these algorithms to our MiniCon algorithm and show that the MiniCon algorithm significantly outperforms them. We describe the algorithms for queries and views without comparison subgoals.
3.1 The Bucket Algorithm
The bucket algorithm was developed as part of the Infor- mation Manifold System [22]. The key idea underlying the bucket algorithm is that the number of query rewritings that need to be considered can be drastically reduced if we first consider each subgoal in the query in isolation and deter- mine which views may be relevant to a particular subgoal. We illustrate the bucket algorithm with the following query and views. Note that the query now only asks for a set of papers, rather than pairs of papers.
Q1(x) :- cites(x,y),cites(y,x),sameTopic(x,y) V4(a) :- cites(a,b), cites(b,a) V5(c,d) :- sameTopic(c,d) V6(f,h) :- cites(f,g),cites(g,h),sameTopic(f,g) In the first step, the bucket algorithm creates a bucket for
would create the following buckets: cites(x,y) cites(y,x) sameTopic(x,y) V4(x) V4(x) V5(x,y) V6(x,y) V6(x,y) V6(x,y) Note that it is possible to unify the subgoal cites(x,y) in the query with the subgoal cites(b,a) in V4, with the
include the entry V4(y) in the bucket because it requires that every distinguished variable in the query be mapped to a distinguished variable in the view. In the second step, for each element of the Cartesian product of the buckets, the algorithm constructs a conjunc- tive rewriting and checks whether it is contained (or can be made to be contained) in the query. If so, the rewriting is added to the answer. Hence, the result of the bucket algo- rithm is a union of conjunctive rewritings. In our example, the algorithm will try to combine V with the other views and fail (as we explain below). Then it will consider the rewritings involving V6, and note that by equating the variables in the head of V6 a contained rewrit- ing is obtained. Finally, the algorithm will also note that V and V5 can be combined. Though not originally described as part of the bucket algorithm, it is possible to add an ad- ditional simple check that will determine that the resulting rewriting will be redundant (because V5 can be removed). Hence, the only rewriting in this example (which also turns out to be an equivalent rewriting) is: Q1’(x) :- V6(x,x) The main inefficiency of the bucket algorithm is that it misses some important interactions between view subgoals by considering each subgoal in isolation. As a result, the buckets contain irrelevant views, and hence the second step of the algorithm becomes very expensive. We illustrate this point on our example. Consider the view V4, and suppose that we decide to use V4 in such a way that the subgoal cites(x,y) is mapped to the subgoal cites(a,b) in the view, as shown below:
V4(a) :- cites(a,b)cites( b,a) However, the variable b does not appear in the head of V4, and therefore, if we use V4, then we will not be able to apply the join predicate between cites(x,y) and Same- Topic(x,y) in the query. Therefore, V4 is not usable for the query, but the bucket algorithm would not discover this. Furthermore, even if the query did not contain Same- Topic(x,y), the bucket algorithm would not realize that if it
uses V4, then it has to use it for both of the query subgoals.
combinations in the second phase. As we explain later, the MiniCon algorithm discovers these interactions. In this example, MiniCon will determine that V4 is irrelevant to the query. In the case in which the query does not contain the subgoal SameTopic(x,y), the MiniCon algorithm will discover that the two cite subgoals need to be treated atomically.
3.2 The Inverse-Rules Algorithm
Like the bucket algorithm, the inverse-rules algorithm [29, 8] was also developed in the context of a data integration system. The key idea underlying the algorithm is to con- struct a set of rules that invert the view definitions, i.e., rules that show how to compute tuples for the database re- lations from tuples of the views. Given the views in the previous example, the algorithm would construct the fol- lowing inverse rules:
R1: cites(a, f1(a)) :- V4(a) R2: cites(f1(a), a) :- V4(a) R3: sameTopic(c,d) :- V5(c,d) R4: cites(f, f2(f,h)) :- V6(f,h) R5: cites(f2(f,h), h) :- V6(f,h) R6: sameTopic(f, f2(f,h)) :- V6(f,h)
Consider the rules R1 and R2; intuitively, their meaning is the following. A tuple of the form (p1) in the extension of the view V4 is a witness of two tuples in the relation cites. It is a witness in the sense that it tells that the relation cites contains a tuple of the form (p1, Z), for some value of Z, and that the relation also contains a tuple of the form (Z, p1), for the same value of Z. In order to express the information that the unknown value of Z is the same in the two atoms, we refer to it using the functional Skolem term f1(Z). Note that there may be several values of Z in the database that cause the tuple (p1) to be in the self-join of cites, but all that we know is that there exists at least one such value. The rewriting of a query
simply the composition of
Hence, one of the important advantages of the algorithm is that the inverse rules can be constructed ahead of time in polynomial time, independent of a particular query. The rewritings produced by the inverse-rules algorithm, as originally described in [8], are not appropriate for query evaluation for two reasons. First, applying the inverse rules to the extension of the views may invert some of the useful computation done to produce the view. Second, we may end up accessing views that are irrelevant to the query. To illustrate the first point, suppose we use the rewriting pro- duced by the inverse-rules algorithm in the case where the
First, we would apply the inverse rules to the exten- sions of the views. Applying R4 would yield cites(p1, f2(p1,p1)), cites(p2, f2(p2,p2)), and similarly applying R5 and R6 would yield the following tuples:
cites(p1, f2(p1,p1)), cites(f2(p1,p1),p1), cites(f2(p2,p2),p2), sameTopic(p1,p1), sameTopic(p2,p2).
Applying the query Q1 to the tuples computed above obtains the answers p1 and p2. However, this computa- tion is highly inefficient. Instead of directly using the tu- ples of V6 for the answer, the inverse-rules algorithm first computed tuples for the relation cites, and then had to re- compute the self-join of cites that was already computed for V6. Furthermore, if the extensions of the views V4 and V5 are not empty, then applying the inverse rules would produce useless tuples as explained in Section 3.1. Hence, before we can fairly compare the inverse-rules algorithm to the others, we need to further process the rules. Specifically, we need to expand the query with every possi- ble combination of inverse rules. However, expanding the query with the inverse rules turns out to repeat much of the work done in the second phase of the bucket algorithm. In the experiments described in Section 5 we consider an extended version of the inverse-rules algorithm that pro- duces a union of conjunctive queries by expanding the def- initions of the inverse rules. We expanded the subgoals of the query one at a time, so we could stop an expansion of the query at the moment when we detect that a unifica- tion for a subset of the subgoals will not yield a rewriting (thereby optimizing the performance of the inverse-rules algorithm). We show that the inverse-rules algorithm can perform much better than the bucket algorithm, but the MiniCon algorithm scales up significantly better than ei- ther algorithm.
The MiniCon algorithm begins like the bucket algorithm, considering which views contain subgoals that correspond to subgoals in the query. However, once the algorithm finds
the variables in the query. The algorithm considers the join predicates in the query and finds the minimal additional set
ping information is called a MiniCon Description (MCD), and can be viewed as a generalization of buckets. In the second phase, the algorithm combines the MCDs to pro- duce the rewritings. It is important to note that because of the way we construct the MCDs, the MiniCon algorithm does not require containment checks in the second phase, giving it an additional speedup compared to the bucket al- gorithm. Section 4.1 describes the construction of MCDs, and Section 4.2 describes the combination step. The proof of correctness of the algorithm is omitted for lack of space, but is described in the full version of this paper [28].
discover this many times (each time it considers V4 in con-
uses a containment check, which is much more expensive. Hence, as we show in the next section, with a little more ef- fort spent in the first phase, the overall performance of the MiniCon algorithm outperforms the bucket algorithm and the inverse-rules algorithm.
Remark 2 (covered subgoals) When we construct a MCD
that are covered by the MCD. The algorithm includes in
in order to satisfy Property 1. To see why this is not an obvious choice, suppose we have the following query and views:
Q1’(x) :- cites(x,y),cites(z,x), inSIGMOD(x) V7(a) :- cites(a,b),inSIGMOD(a) V8(c) :- cites(d,c),inSIGMOD(c)
One can also consider including the subgoal in- SIGMOD(x) in the set of covered subgoals for the MCD for both V7 and V8, because x is in the domain of their respective variable mappings anyway. However, our algo- rithm will not include inSIGMOD(x), and will instead cre- ate a special MCD for it. The reason for our choice is that it enables us to focus in the second phase only on rewritings where the MCD cover mutually exclusive sets of subgoals in the query, rather than overlapping subsets. This yields a more efficient second
4.2 Combining the MCDs
Our method for constructing MCDs pays off in the second phase of the algorithm, where we combine MCDs to build the conjunctive rewritings. In this phase we consider com- binations of MCDs, and for each valid combination we cre- ate a conjunctive rewriting of the query. The final rewriting is a union of conjunctive queries. The following property states that the MiniCon algo- rithm need only consider combinations of MCDs that cover pairwise disjoint subsets of subgoals of the query:
Property 2 Given a query
of MCDs that can result in non-redundant rewritings of
t zm`>[ 7 &('Q)+(-."0/i%
, and
>[_(t>[( 7 ^.The fact that we only need to consider sets of MCDs that provide partitions of the subgoals in the query drasti- cally reduces the search space of the algorithm. Further- more, even though we do not discuss it here, the algorithm can also be extended to output the rewriting in a compact encoding that identifies the common subexpressions of the conjunctive rewritings, and therefore leads to more efficient query evaluation. We note that had we chosen the alternate strategy in Remark 2, clause D2 would not hold.
procedure combineMCDs (
)
such that
« ~|¬ « « ~|H®
then
Else
Create the conjunctive rewriting
wx{=w,´ wt
y,y,y3gg
Figure 3: Phase 2: combining the MCDs.
Given a combination of MCDs that satisfies Property 2, the actual rewriting is constructed as shown in Figure 3. In the final step of the algorithm we tighten up the rewritings by removing redundant subgoals as follows. Suppose a rewriting
includes two atoms
of
, and the following conditions are satisfied: (1) whenever
) has a variable from
(resp.
either has the same variable or a variable that does not ap- pear in
and
ables of
and (2) is the most general unifier of
. The underlying justification for this optimization is discussed in [21], and it can also be applied to the bucket algorithm and the inverse-rules algorithm. We note that even after this step, the rewritings may still contain redundant subgoals. However, removing them in- volves several tests for query containment. In our example, the algorithm will consider using V to cover subgoal 3 , but when it realizes that there are no MCDs that cover either subgoal 1 or 2 without covering subgoal 3 , it will discard V5. Thus the only rewriting that will be considered is Q1’(x) :- V6(x,x). The following theorem summarizes the properties of the MiniCon algorithm:
Theorem 4.1 Given a conjunctive query
and conjunc-
Con algorithm produces the union of conjunctive queries that is the maximally-contained rewriting of
It should be noted that the worst-case asymptotic run- ning time of the MiniCon algorithm is the same as that of
the bucket algorithm and of the inverse-rules algorithm af-
The next section describes experimental results showing the differences between the three algorithms in practice.
The goal of our experiments was twofold. First, we wanted to compare the performance of the bucket algo- rithm, the inverse-rules algorithm, and MiniCon algorithm in different circumstances. Second, we wanted to validate that MiniCon can scale up to large number of views and large queries. Our experiments considered three classes of queries and views: (1) chain queries, (2) star queries and (3) complete queries, all of which are well known in the literature [25]. To facilitate the experiments, we implemented a random query generator which enables us to control the following parameters (1) the number of subgoals in the queries and views, (2) the number of variables per subgoal, (3) the num- ber of distinguished variables, and (4) the degree to which predicate names are duplicated in the queries and views. The results are averaged over multiple runs generated with the same parameters (at least 40, and usually more than 100). An important variable to keep in mind throughout the experiments is the number of rewritings that can actu- ally be obtained. In most experiments we considered queries and views that had the same query shape and size. Our experiments were all run on a dual Pentium II 450 MHz running Win- dows NT 4.0 with 512MB RAM. All of the algorithms were implemented in Java and compiled to an executable.
5.1 Chain queries
In the context of chain queries we consider several cases. In the first case, shown in Figure 4(a), only the first and last variables of the query and the view are distinguished. Therefore, in order to be usable, a view has to be identi- cal to the query, and as a result there are very few rewrit- ings. The bucket algorithm performs the worst, because of the cost of the query containment checks it needs to per- form (it took on the order of 20 seconds for 5 views of size 10 subgoals, and hence we do not even show it on the graph). The inverse-rules algorithm and the MiniCon algo- rithm scale linearly in the number of views, but the Mini- Con algorithm outperforms the inverse-rules algorithm by a factor of about 5 (and this factor is independent of query and view size). In fact, the MiniCon algorithm can handle more than 1000 views with 10 subgoals each in less than one second. The difference in the performance between the inverse- rules algorithm and the MiniCon algorithm in this context and in others is due to the second phases of the algorithms. In this phase, the inverse-rules algorithm is searching for a
unification of the subgoals of the query with heads of in- verse rules. The MiniCon algorithm is searching for sets of MCDs that cover all the subgoals in the query, but cover pairwise disjoint subsets. Hence, the MiniCon algorithm is searching a much smaller space, because the number of subgoals is smaller than the number of variables in the query. Moreover the MiniCon algorithm is performing bet- ter because in the first phase of the algorithm it already re- moved from consideration views that may not be usable due to violations of Property 1. In contrast, the inverse-rules al- gorithm must try unifications that include such views and then backtrack. The amount of work that the inverse-rules algorithm will waste depends on the order in which it con- siders the subgoals in the query when it unifies them with the corresponding inverse rules. If a failure appears late in the ordering, more work is wasted. The important point to note is that the optimal order in which to consider the sub- goals depends heavily on the specific views available and is, in general, very hard to find. Hence, it would be hard to extend the inverse-rules algorithm such that its second phase would compare in performance to that of the Mini- Con algorithm. In the second case we consider, shown in Figure 4(b), the views are shorter than the query (of lengths 2, 3 and 4, while the query has 12 subgoals). In this case the MiniCon algorithm stills scales linearly while the inverse-rules algo- rithm grows faster. For example, for 90 views, the MiniCon algorithm runs 3 times faster than the inverse-rules algo- rithm, and for 180 views it runs 6 times faster. Finally, though not shown here, we also considered an- other case in which all the variables in the views are dis- tinguished. In this case, there are many rewritings (often more than 1000), and hence the performance of the algo- rithms is limited because of the sheer number of rewritings. Since virtually all combinations produce contained rewrit- ings, any complete algorithm is forced to form an exponen- tial number of rewritings. The MiniCon algorithm still per- forms better than the inverse-rules algorithm by anywhere between 10% better and a factor of 2, but with queries and views with 5 subgoals, the algorithms take on the order of 10 seconds for 10 views. It should be emphasized that the difference in performance between the MiniCon algorithm and the inverse-rules algorithm in this case is only due to the smaller search space being considered by the MiniCon algorithm.
5.2 Star and complete queries
In star queries, there exists a unique subgoal in the query that is joined with every other subgoal, and there are no joins between the other subgoals. In the cases of two dis- tinguished variables in the views or all view variables being distinguished, the performance of the algorithms mirrors the corresponding cases of chain queries. Hence, we omit the details of these experiments. Figure 5(a) shows the run- ning times of the inverse-rules algorithm and the MiniCon algorithm in the case where the distinguished variables in the views are the ones that do not participate in the joins. In
Star queries with 10 subgoals with
distinguished non-joined variables
0
1
1 3 5 7 9 11 13 15 17 19
Number of views
Time (in Seconds)
MiniCon Algorithm Inverse Rules Bucket Algorithm
Complete queries with 10 subgoals and three distinguished variables
0
0 10 20 30 40 50 Number of Views
Time (in Seconds)
MiniCon Algorithm Inverse Rules
Figure 5: The left figure shows the running times for star queries, where the distinguished variables in the views are those not partici- pating in the joins. The graph on the right shows running times for complete queries with a similar setting. In both cases the MiniCon algorithm significantly outperforms the inverse-rules algorithm.
contain comparison predicates but the query does not, then the MiniCon algorithm without any changes still yields the maximally-contained query rewriting. On the other hand, if the query contains comparison predicates, then it fol- lows from [1] that there can be no algorithm that returns a maximally-contained rewriting, even if we consider rewrit- ings that are recursive datalog programs (let alone unions of conjunctive queries). In this section we present an extension to the MiniCon algorithm that would (1) always find only correct rewritings (2) find the maximally-contained rewriting in many of the common cases in which comparison predicates are used, and (3) is guaranteed to produce the maximally-contained rewriting when the query contains only semi-interval con- straints, i.e., when all the comparison predicates in the
up of the extended algorithm. Finally, we show an exam- ple that provides an intuition for which cases the algorithm will not capture. In our discussion, we refer to the set of comparison sub- goals in a query
or constants and (2) contains at least one existential variable of
. Intuitively,
denotes the set of comparison subgoals in the query
is the domain of a
is
. We
in time that is quadratic in the size of
We make three changes to the MiniCon algorithm to handle comparison predicates. First, we only consider
is an existential variable in
is the set of variables in the domain of the map-
The first condition is an extension of Property 1, and the second condition guarantees the comparison subgoals in the view logically entail the relevant comparison subgoals in the query. Note that because of the second condition,
added to the rewriting after the MCDs are combined. The second change is that we disallow all MCDs that constrain variables to be incompatible with the variables they map in the query. For example, if a query has a sub-
The third change we make to the MiniCon algorithm is the following: after forming a rewriting
by combining a
for any subgoal
that is not satisfied by
Example 6.1 Consider a variation on our running exam- ple, where the predicate year denotes the year of publica- tion of a paper. Q2(x) :- inSIGMOD(x), cites(x,y), year(x,r1),
V7(a,s1) :- inSIGMOD(a), cites(a,b), year(a,s1),
V8(a,s1) :- inSIGMOD(a), cites(a,b), year(a,s1),
Our algorithm would first consider V7 with the mapping
is not. However, since s1 is a distinguished variable in V7, the algorithm can create the rewriting:
When the algorithm considers a similar variable map- ping to V8, it will notice that the constraint on r2 is not satisfied, and since it is mapped to an existential variable in
Example 6.2 The following example provides an intuition
cover. Consider the following query and view:
V1(a) :- e(a,b), e(b,a)
The algorithm will not create any MCD because the sub-
ever, the following is a contained rewriting of
Q’(u) :- V1(u)
In order to show that the query contains the rewriting, we need to consider two different containment mappings, de-
is mapped to a different sub- goal. Our algorithm will only find rewritings in which the target of the mapping for a subgoal in the query is the same
Figure 6 shows sample experiments that we ran on the extended algorithm in the case of chain queries. In the ex- periments, we added to the queries and views a number of
The experiments show that the same trends we saw with- out comparison predicates appear here as well. In general, the addition of comparison predicates reduces the number of rewritings because more views can be deemed irrelevant. This is illustrated in Figure 6(b) where all of the variables in the views are distinguished and therefore without compari- son predicates there would be many more rewritings. How- ever, since the comparison predicates reduce the number of relevant views, the algorithm with comparison predicates scales up to a larger number of views. In Figure 6(a), the number of rewritings is very small, and the extra overhead of processing the comparison predicates causes slow down of a factor of 4. This factor can be decreased with further optimizations of our comparison predicate code that we did not explore.
Algorithms for rewriting queries using views are surveyed in [20]. Most of the previous work on the problem fo- cused on developing algorithms for the problem, rather that on studying their performance. In addition to the al- gorithms mentioned previously, algorithms have been de- veloped for conjunctive queries with comparison predi- cates [35], queries and views with grouping and aggrega- tion [15, 31, 7, 13], OQL queries [11], and queries over semi-structured data [26, 4]. The problem of answer- ing queries using views has been considered for schemas with functional and inclusion dependencies [10, 14], lan- guages that query both data and schema [23], and disjunc- tive views [2]. Clearly, each of the above extensions to the basic problem represents an opportunity for a possible ex- tension of the MiniCon algorithm. Mitra [24] developed a rewriting algorithm that also captures the intuition of Prop- erty 1, and thus would likely lead to better performance than the bucket algorithm and the inverse-rules algorithm.
Several works discussed extensions to query optimizers that try to make use of materialized views in query pro- cessing [33, 6, 3, 27, 36]. In some cases, they modified the System-R style join enumeration component [33, 6], and in others they incorporated view rewritings into the rewrite phase of the optimizer [36, 27]. These works showed that considering the presence of materialized views did not neg- atively impact the performance of the optimizer. However, in these works the number of views tended to be relatively small. In [27], the authors consider a more general set- ting where they use a constraint language to describe views, physical structures and standard types of constraints. Un- like our algorithm, the above works are designed to pro- duce a single conjunctive rewriting that is equivalent to the query and has the least cost, whereas we search for the maximally-contained rewriting.
This paper makes two important contributions. First, we present a new algorithm for answering queries using views, and second, we present the first experimental evaluation of such algorithms. We began by analyzing the two existing algorithms, the bucket algorithm and the inverse-rules algo- rithm, and found that they have significant limitations. We developed the MiniCon algorithm, a novel algorithm for answering queries using views, and showed that it scales gracefully and outperforms both existing algorithms. As a result of our work, we have established that answering queries using views can be done efficiently for large-scale problems. Finally, we described an extension of our algo- rithm to handle comparison predicates. As we show in the extended version of the paper, the MiniCon algorithm can also be extended in a straightforward fashion to deal with access-pattern limitations [30] in the same spirit of [10]. An interesting direction of future research is to extend the MiniCon algorithm to the context of using material- ized views for query optimization and to consider bag se- mantics. In this context, we are interested in the cheap- est rewriting of the query. Conceivably, it is possible as in [33, 6] to modify the second phase of the MiniCon algo- rithm such that it combines the MCDs in a bottom-up dy- namic programming style, and hence saves only the cheap- est rewriting. However, for the algorithm to guarantee find- ing the cheapest rewriting, we now need to consider rewrit- ings that contain logically redundant subgoals.
Example 8.1 Suppose we have the following query and views: Q(x,y) :- e1(x,z), e2(z,y) V1(x,y) :- e1(x,y) V2(z,y) :- e2(z,y) V3(x) :- e1(x,z), e2(z,y) If the join of e1 and e2 is very selective, the rewriting of the query that will yield the cheapest query execution plan may be: q’(x,y) :- v3(x), v1(x,y), v2(z,y).