Database Systems: The Complete Book- P6
Thông tin tài liệu:
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ìm kiếm theo từ khóa liên quan:
Oracle cơ bản giáo trình cơ sở dữ liệu bảo mật cơ sở dữ liệu cơ sở dữ liệu Mysql giáo trình sqlGợi ý tài liệu liên quan:
-
62 trang 402 3 0
-
Giáo trình Cơ sở dữ liệu: Phần 2 - TS. Nguyễn Hoàng Sơn
158 trang 294 0 0 -
Giáo trình Cơ sở dữ liệu: Phần 2 - Đại học Kinh tế TP. HCM
115 trang 176 0 0 -
Giáo trình Cơ sở dữ liệu: Phần 1 - Sở Bưu chính Viễn Thông TP Hà Nội
48 trang 171 1 0 -
Giáo Trình về Cơ Sở Dữ Liệu - Phan Tấn Quốc
114 trang 119 1 0 -
Giáo trình cơ sở dữ liệu quan hệ_3
26 trang 106 0 0 -
Giáo trình Cơ sở dữ liệu (Ngành: Công nghệ thông tin - Trung cấp) - Trường Cao đẳng Xây dựng số 1
49 trang 100 0 0 -
54 trang 70 0 0
-
134 trang 62 1 0
-
0 trang 57 0 0
-
Bài giảng cơ sở dữ liệu - chương 1 - ĐH KHTN Tp.HCM
46 trang 48 0 0 -
Giáo trình Cơ sở dữ liệu: Phần 1 - ĐH công nghiệp Tp.HCM
41 trang 42 0 0 -
57 trang 40 1 0
-
Giáo trình Cơ sở dữ liệu - Phần 2: SQL Server - ĐH Công nghiệp Tp.HCM
147 trang 39 2 0 -
Giáo trình Cơ sở dữ liệu: Phần 2 - Cao Thị Nhạn, Nguyễn Thị Thanh Bình
55 trang 36 0 0 -
Asp.Net 3.5 In Simple Steps- P6
10 trang 35 0 0 -
Asp.Net 3.5 In Simple Steps- P4
10 trang 35 0 0 -
Thực hành cơ sở dữ liệu: Phần 2
92 trang 34 0 0 -
THỰC HÀNH LAB : PHƯƠNG PHÁP TẤN CÔNG CỦA HACKER VÀO CÁC ỨNG DỤNG WEB BỊ LỖI SQL INJECTION
124 trang 34 1 0 -
Asp.Net 3.5 In Simple Steps- P5
10 trang 33 0 0