Danh mục

Database Systems: The Complete Book- P6

Số trang: 50      Loại file: pdf      Dung lượng: 4.13 MB      Lượt xem: 14      Lượt tải: 0    
tailieu_vip

Phí tải xuống: 12,000 VND Tải xuống file đầy đủ (50 trang) 0
Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Database Systems: The Complete Book- P6: Database Systems and Database Design and Application courses offered at the junior, senior and graduate levels in Computer Science departments. Written by well-known computer scientists, this introduction to database systems offers a comprehensive approach, focusing on database design, database use, and implementation of database applications and database management systems
Nội dung trích xuất từ tài liệu:
Database Systems: The Complete Book- P6 476 CHAPTER 10. LOGICAL QUERY LANGUAGES 10.2. FROM RELATIONAL ALGEBRA TO DATALOG 477 10.2.6 Product to perform the same operation. Ve have used ub as the variable corresponding to attribute B of U . and similarly used vb, uc, and vc, although any six distinct The product of txo relations R x S can be expressed by a single Datalog rule. variables for the six attributes of the two relations would be fine. The first two This rule has two subgoals, one for R and one for S. Each of these subgoals subgoals introduce the two relations, and the second two subgoals enforce the has distinct variables, one for each attribute of R or S. The IDB predicate in two comparisons that appear in the condition of the theta-join. the head has as arguments all the variables that appear in either subgoal, with the variables appearing in the R-subgoal listed before t,hose of the S-subgoal. If the condition of the theta-join is not a conjunction, then we convert it to Example 10.17: Let us consider the two four-attribute relations R and S disjunctive normal form, as discussed in Section 10.2.5. We then create one rule from Example 10.9. The rule for each conjunct. In this rule, we begin with the subgoals for the product and then add subgoals for each litera1 in the conjunct. The heads of all the rules are identical and have one argument for each attribute of the two relations being theta-joined. defines P to be R x S. We have arbitrarily used variables at the beginning of the alphabet for the arguments of R and variables at the end of the alphabet Example 10.20 : In this example, we shall make a simple modification to the for S. These variables all appear in the rule head. algebraic expression of Example 10.19. The AND will be replaced by an OR. There are no negations in this expression, so it is already in disjunctive normal 10.2.7 Joins form. There are two conjuncts, each with a single literal. The expression is: We can take the natural join of two relations by a Datalog rule that looks much like the rule for a product. The difference is that if we want R w S, then we must be careful to use the same variable for attributes of R and S that have the same name and to use different variables otherwise. For instance, we can use Using the same variable-naming scheme as in Example 10.19, we obtain the the attribute names themselves as the variables. The head is an IDB predicate two rules that has each variable appearing once. 1. J(a,ub,uc,vb,vc,d) t U(a,ub,uc) AND V(vb,vc,d) AND a < d Example 10.18 : Consider relations with schemas R(A,B) and S ( B ,C, D). 2. J(a,ub,uc,vb,vc,d) t U(a,ub,uc) AND V(vb,vc,d) AND ub # vb Their natural join may be defined by the rule Each rule has subgoals for the tn-o relations involved plus a subgoal for one of J(a,b,c,d) +- R(a,b) AND S(b,c,d) the two conditions d < D or L1.B # V.B. 0 Xotice how the variables used in the subgoals correspond in an obvious ivay to the attributes of the relat.ions R and S . 10.2.8 Simulating Multiple Operations with Datalog We also can convert theta-joins to Datalog. Recall from Section 5.2.10 how a Datalog rules are not only capable of mimicking a single operation of relational theta-join can be expressed as a product followed by a selection. If the selection algebra. We can in fact mimic a ...

Tài liệu được xem nhiều:

Gợi ý tài liệu liên quan: