Database Systems: The Complete Book- P6

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 | 476 . CHAPTER 10. LOGICAL QUERY LANGUAGES Product The product of two relations Rx S can be expressed by a single Datalog rule. This rule has two subgoals one for R and one for S. Each of these subgoals has distinct variables one for each attribute of R or S. The IDB predicate in the head has as arguments all the variables that appear in either subgoal with the variables appearing in the R-subgoal listed before those of the S-subgoal. Example Let us consider the two four-attribute relations R and S from Example . The rule P a b c d w x y z -R a b c d AND S w x y z 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 for S. These variables all appear in the rule head. Joins 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 ixi 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 the attribute names themselves as the variables. The head is an IDB predicate that has each variable appearing once. Example Consider relations with schemas R A B and S B . Their natural join may be defined by the rule J a b c d R a b AND S b c d Notice how the variables used in the subgoals correspond in an obvious way to the attributes of the relations R and S. We also can convert theta-joins to Datalog. Recall from Section how a theta-join can be expressed as a product followed by a selection. If the selection condition is a conjunct that is the AND of comparisons then we may simply start with the Datalog rule for the product and add additional arithmetic subgoals one for each of the comparisons. Example Let us consider the relations U A B C and V B C D from Example where we applied the theta-join rr 1X1 tz U A D AND V . FROM .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.