Built-in Predicates for Extended Relational Algebra Operations in a Logic Database Language Yiu-Kai Ngy Qing Chang Computer Science Department Brigham Young University Provo, Utah 84602 U.S.A. Email:
[email protected] Abstract
Existing rule-based nested relational database query languages do not provide built-in predicates for extended relational algebra operations. As a result, these query languages lack these traditional operators and are thus less convenient for query speci ers who recognize the expressive advantage of extended relational algebra operators. To overcome this shortcoming, we introduce a generalized Datalog language, called LDL=NR, that includes a basic set of extended relational algebra operators as builtin predicates. LDL=NR thus not only has the power to express recursive queries, but also has the expressive advantage of built-in extended relational algebra operators.
Keywords: Logic programming, logic database language, nested relation, relational algebra.
1 Introduction Extended relational algebra operators, which extend the traditional relational algebra operators to work with nested relations, are de ned in [1] [6] [13]. These operators allow users to manipulate data in a nested relational structure, and thus enhance the expressive power of traditional relational algebra operators. Nevertheless, these database languages are non-rule-based and cannot handle recursive queries. Existing rule-based nested relational database query languages such as [4] [5] [15] which handle recursive queries, however, are insucient from the user's point of view since these languages lack built-in predicates for the basic set of extended relational algebra operations. As a result, existing rule-based The preliminary version of this paper appeared in the Proceedings of Abstracts and Summaries of the 1st Joint Conference on Information Sciences (JCIS94) [3]. y To whom correspondence should be addressed.
1
nested relational query languages are not as easy to use as they could be because database users of these languages are expected to specify the extended relational algebra operations on their own, and hence could not take the advantage of the simplicity of queries constructed by query languages with built-in predicates for extended relational algebra operations. We resolve this problem in this paper by introducing built-in logic predicates for extended relational algebra operations. The language in which we express the syntax and semantics of the built-in predicates for extended relational algebra operations is LDL=NR, a logic database language for nested relations. LDL=NR replaces predicate symbols and function symbols, as used in logic database languages [2] [9] [15], by tuple terms and set terms, respectively as used in [4] [5], so that LDL=NR can uniformly handle nested relations at arbitrary levels of nesting in a hierarchical structure and has full expressive power for manipulating mutually nested tuples and sets. LDL=NR, as de ned, is a \natural" logic database language for nested relations since LDL=NR precisely follows and captures the constraints of alternating tuple terms and set terms in a nested relation [8]. Generally speaking, LDL=NR restricts HILOG [4] to nested relations, and is simpler in notation than HILOG-R [5] which requires type and named attribute to be attached to each argument of a type declaration, and named attribute to each data value in a tuple. In addition, LDL=NR is more complete in terms of language structure for nested relations than LDL [14] which allows only nested tuples rather than nested sets. Furthermore, the semantics of sets in the logic database language de ned by [9] is dierent from the semantics of set terms as de ned in LDL=NR. From the theoretical point of view, set terms as de ned in [9] cannot handle the nested relational structure since they do not capture the constraint of alternating tuple terms and set terms in a nested relation precisely and cannot represent the constraints of a nested relation explicitly. On the other hand, LDL=NR is a logic database language for nested relations, and the semantics of sets in LDL=NR follows the de nition of nested relations [8] which extends the semantics of rst-order logic languages to handle recursion. From the implementation point of view, [9] has not addressed how to implement set(-term) matching and set(-term) uni cation and their respective semantics as LDL=NR does for processing queries with set terms [10, 11]. Also, since for each complex object type there is a nested relation type with the same \information capacity" [8], LDL=NR is capable of handling complex object queries. The syntax and semantics of LDL=NR are introduced in Section 2. Using rule expressions in LDL=NR, we formalize a set of built-in predicates for extended relational algebra operations. These built-in predicates can be integrated into any rule expression of LDL=NR wherever they are needed. Since these built-in predicates work with nested relations, they generalize the Datalog rule expressions that specify traditional relational algebra operations for at relations. Our built-in predicates for extended algebra operations, except extended selection, are based on the work of [13]. The set of built-in predicates for extended relational algebra operations are introduced in Section 3, and their formal de nitions are given in Section 4. Concluding remarks are given in Section 5.
2
2 Syntax and Semantics of LDL=N R 2.1 Syntax of LDL=N R
LDL=NR is based on the notions of type, term, formula, rule, fact, and query, which in turn are de ned on an alphabet. Constants and variables in LDL=NR are of atomic type. There are two other types: tuple type and set type, de ned in LDL=NR. Set type and tuple type can be used alternatively to form complex data types, as in [4] [5].
De nition 1 A type is recursively de ned as follows: (a) An atomic type is a type. (b) A set type sfrg is a type, where r is either an atomic type or a tuple type. (c) A tuple type p(s1; : : :; sn ) is a type1, where each si, 1 i n, is either an atomic type or a set type. 2
Example 1 The following type declaration de nes dept which is of tuple type with com-
ponents Dname, projects, and employees. Dname is of atomic type, and projects, which includes all projects controlled by department Dname, and employees, which includes all employees who work for department Dname, are of set types.
dept(Dname; projectsfPnameg; employeesfemployee(Ename;EID)g). 2 Objects of atomic type are called atomic terms, while objects of set type or tuple type are called complex terms.
De nition 2 A term is recursively de ned as follows: (a) A constant is a term. (b) A variable is a term. (c) For a set-type sfrg, sft1; : : :; tmg (m 2 I +) is a term called set term, where each ti, 1 i m, is of type r. (d) For a tuple-type p(s1; : : : ; sn), p(t1; : : :; tn) is a term called tuple term, where ti is of type si, 1 i n. 2
sfX g, where X is a variable, denotes a set term of arbitrary cardinality. Furthermore, LDL=NR adopts the Unique Name Assumption on types [4] which restricts names of different tuple types and set types to be distinct. A similar restriction applies to variables of dierent types in a rule. 1
Hence, the type symbols for set type and tuple type are fg and (), respectively.
3
Example 2 An instance of the tuple-type dept is dept (cs, projectsfdb; se; lpg, employees femployee(smith; 123), employee(jones; 567), employee(snow; 201)g). 2 De nition 3 A (well-formed) formula is inductively de ned as follows: (a) A tuple term or set term is a formula. (b) If T and S are terms of comparable types, then TS is a formula, where is an applicable (set) comparison operator. (c) If F is a formula and X is a variable, then 9X F and 8X F are formulas. (d) If F and G are formulas, so are :F , F _ G, F ^ G, F ! G, and F $ G. 2 A tuple term, set term, or (set) comparison operator with arguments is an atomic formula or simply an atom. A closed formula is a formula with no free occurrence of any variable. A ground formula (term) is a formula (term) without variables.
De nition 4 A rule (expression) is of the form head : { body, where head is a positive atom, body is a conjunction of positive atoms2, and : { is an implication symbol. A unit rule is a rule with an empty body. A fact is a positive unit rule. In a database, a nite set of facts forms an extensional database (EDB ). 2
Example 3 The following rule retrieves all employees who work on all database projects: works on pj(Ename) : { employee(Ename, EID), works on(EID, wprojsfProj IDg), wprojsfProj IDg db projectsfPIDg. 2 De nition 5 A program P is a collection of rules such that for each C 2 P , C is either a fact in EDB or a rule. A goal is a rule without a head, denoted ? ? body. A logic database query in LDL=NR consists of a program and a goal. 2
Example 4 Assume that a nested relational database, which consists of a nested relation parent and a at relation person, is represented by the following facts:
parent(john, childrenfchild(mary, 13), child(anthony, 10), child(bill, 5)g). person(john, male). person(mary, female). person(anthony, male). person(bill, male). and the rule R, father(X; childrenfY g) : { person(X; male); parent(X; childrenfY g)., which determines each father X and X 's children. The logic database query, which consists of the program that includes R and the facts above, and the goal, ? ? father(john; Z )., retrieves children of john. 2 Occasionally, we adopt the notation \;" which is commonly used in other logic database/programming languages to denote a disjunction in the body of a rule expression. 2
4
2.2 Semantics of LDL=N R
The declarative semantics of an LDL=NR program (query) is given by the usual semantics of formulas in LDL=NR. Meaning for each symbol in a formula should be assigned in order to discuss the truth or falsity of the formula. The various quanti ers and connectives have a xed meaning, but the meaning assigned to each term can vary [12]. We rst de ne LDL=NR universe and LDL=NR base.
De nition 6 Given an instance L of LDL=NR, the LDL=NR universe U of L, denoted UL, is the set of all ground atomic terms (constants), and the LDL=NR base B of L, denoted BL, is the set of all positive ground unit rules. 2 Example 5 Let L be an instance of LDL=NR which consists of a tuple-type project (Pname), a set-type projectsfproject(Pname)g, and constants db and se. Hence, UL = fdb, seg and BL = fproject(db), project(se), projectsfproject(db)g, projectsfproject(se)g, projectsfproject(db), project(se)gg. 2 To de ne formally the meaning of a fact as a logical consequence of a set of facts and LDL=NR rules, we introduce the concepts of LDL=NR interpretation and LDL=NR model.
De nition 7 Given an instance L of LDL=NR, an interpretation for L is an LDL=NR interpretation if the following conditions are satis ed:
(a) The domain of the interpretation is the LDL=NR universe UL . (b) Constants in L are assigned to \themselves" in UL. (c) For a set-term sfX g in L, the assignment of s is a mapping from ULm to ftrue; falseg, where m = jsj, the cardinality of s. (d) For a tuple-term p(t1; : : :; tn) in L, the assignment of p is a mapping from ULn to ftrue; falseg. 2
De nition 8 Given an LDL=NR interpretation I of an instance L of LDL=NR and a
closed formula F of L, I is an LDL=NR model, which is a subset of BL, for F if F is true with respect to I (or I is a model for F ). If S is a set of closed formulas of L, then I is an LDL=NR model for S if I is a model for every formula of S . 2
Example 6 Let F be 9Z father(john; Z ). An interpretation based on the logic program
in Example 4 is an LDL=NR model for F . 2
As in [4], it is assumed that the satisfaction of sf a, b, c g by an LDL=NR interpretation I implies the satisfaction of sfX g by I , where X fa; b; cg. Similarly, the satisfactions of sfag and sfbg by I imply the satisfaction of sfa; bg by I .
5
3 Rule Expressions for Extended Relational Algebra Operations In this section, we present sample rule expressions in LDL=NR which specify the extended relational algebra operations on nested relations. The formal de nitions of these extended operators as built-in predicates are given in Section 4. We assume that s and s are two nested relations, and for any extended set operation (i.e., union, intersection, and dierence), the two involved operand relations have the same relation scheme. Furthermore, in each rule expression for extended set operations and natural join, the rst two arguments and the third argument of the head tuple term are based on the relation schemes of the two operand relations and the resultant relation, respectively. 0
3.1 Extended Union (union or [e)
The extended union of s and s yields the resultant relation s in which a tuple t is generated from tuples t 2 s and t 2 s if the atomic components of t and t agree. In this case, the atomic component of t is the atomic component of t (t ). If the atomic component of t (t ) is dierent from the atomic component of each tuple in s (s), then t (t ) is simply included in s . This process is recursively applied to each level of nesting in each pair of corresponding non-atomic components of t and t . 0
00
0
00
0
0
00
0
0
0
0
00
0
Example 7 In Figure 1 there are two nested relations Managed and Managing which
contain information about employees who have been managed and are being managed by their supervisors, respectively. The data structure diagrams of these two nested relations are shown in Figure 2. Applying the (informal) de nition of extended union (given above) on Managed and Managing, we construct the nested relation all mgmt, as shown in Figure 3, which contains information about employees who have been managed or are being managed by their supervisors. 2 Assume that there does not exist a built-in predicate for extended union. Hence, a user must create rule expressions to specify the extended union operation. There are at least three expressions needed to be speci ed. Suppose A1; : : : ; An are the atomic attributes and s1; : : : ; sm are the non-atomic attributes of nested relations s and s . The rst rule expression for extended union on s and s applies if there exist t 2 s and t 2 s such that t[A1 : : : An] = t [A1 : : :An], and a new tuple t is generated in the resultant relation s such that t [A1 : : : An] = t[A1 : : : An] (= t [A1 : : :An]), and t [si] = t[si] [e t [si], 1 i m. Since the built-in predicate for extended union does not exist, rule expressions for computing the extended union on t[si] and t [si], i.e., t[si] [e t [si], 1 i m, must be speci ed. (See, for example, the additional rule expression expr in Example 8. Of course, expr can be eliminated in Example 8 by substituting the body of the rst rule expression with the body of expr. We include expr to illustrate the recursive de nition of extended union which in general is needed in a complex nested structure.) The second rule expression applies if there exists a tuple t 2 s such that 0
0
0
0
00
0
00
00
0
0
0
0
6
00
Managed Managing Supr id Supr name Supervisee Supe id Supe name Supr id Supr name Supervisee Supe id Supe name 1 Steve 10 Liz 37
21 5 12 18
Mary
Je Karl John Ann
1
Steve
12
John
21 37 42
Je Mary Lee
Figure 1: Nested Relations Managed and Managing.
mg
md managed
QQQ Q
managing
QQQ Q
Supr id Supr name supes
Supr id Supr name supes
supervisee
supervisee
## QQQ # Supe id Supe name
## QQQ # Supe id Supe name
Figure 2: Data Structure Diagrams for Nested Relations Managed and Managing.
All mgmt Supr id Supr name Supervisee Supe id Supe name 1 Steve 10 Liz 21 Je 5 Karl 37 Mary 37 Mary 12 John 18 Ann 12 John 42 Lee Figure 3: All mgmt = Managed [e Managing. 7
t[A1 : : :An] 6= t [A1 : : : An], for all t 2 s , and t becomes a new tuple in s . The third rule expression is similar to the second rule expression except that there exists a tuple t 2 s such that t[A1 : : : An] 6= t [A1 : : : An], for all t 2 s, and t becomes a new tuple in s . Example 8 We construct the following rule expressions in LDL=NR to specify the extended union operation on Managed and Managing, and a fact for each tuple in Managed and Managing. It is assumed that setof , a built-in predicate de ned in LDL=NR, is similar to the corresponding predicate de ned in other logic programming languages and has been augmented to handle nested relational structures. We treat a list as a (an ordered) set term. 0
0
0
00
0
0
0
00
Rule Expressions for Extended Union on Managed and Managing:
/* First Rule Expression */ union(mdfmanaged(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g, mgfmanaging(Supr id; Supr name; supesfsupervisee(Supe id ; Supe name )g)g, allfall mgmt(Supr id; Supr name; supesfsupervisee(Supe id ; Supe name )g)g) : { union(supesfsupervisee(Supe id; Supe name)g, supesfsupervisee(Supe id ; Supe name )g, supesfsupervisee(Supe id ; Supe name )g). 0
0
00
0
00
0
00
00
/* Additional Rule Expression */ union(supesfsupervisee(Supe id; Supe name)g, supesfsupervisee(Supe id ; Supe name )g, supesfsupervisee(Supe id ; Supe name )g) : { Supe id = Supe id; Supe name = Supe name; Supe id = Supe id ; Supe name = Supe name . 0
0
00
00
00
00
00
0
00
0
/* Second Rule Expression */ union(mdfmanaged(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g, mgfmanaging(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g, allfall mgmt(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g) : { setof (t(Supr id ; Supr name ), mgfmanaging(Supr id ; Supr name , supesfsupervisee(Supe id ; Supe name )g)g, L), t(Supr id; Supr name) 62 L. 0
0
0
0
0
0
0
0
0
0
/* Third Rule Expression */ union(mdfmanaged(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g, mgfmanaging(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g, allfall mgmt(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g) : { setof (t(Supr id; Supr name), mdfmanaged(Supr id; Supr name, supesfsupervisee(Supe id; Supe name)g)g, L), t(Supr id ; Supr name ) 62 L. 0
0
0
0
0
0
0
0
8
0
0
Facts for Managed and Managing:
mdfmanaged(1; steve; supsfsupervisee(10; liz); supervisee(21; jeff ); supervisee(5; karl)g), managed(37; mary; supsfsupervisee(12; john); supervisee(18; ann)g)g. mgfmanaging(1; steve; supsfsupervisee(21; jeff ); supervisee(37; mary)g), managing(12; john; supsfsupervisee(42; lee)g)g. 2 It is inconvenient to specify each extended union operation whenever it is needed in an LDL=NR program. A built-in predicate for extended union should resolve this problem. Example 9 Suppose the built-in predicate for extended union is available to be used. We can specify the following LDL=NR query for extended union on Managed and Managing to generate the desired nested relation all mgmt: ? ? union(mdfmanaged(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g, mgfmanaging(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g, allfall mgmt(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g): 2 0
0
00
0
00
0
00
00
We can integrate the built-in predicate for extended union into any rule expression in LDL=NR wherever it is needed. The following example illustrates how to embed the built-in predicate for extended union in a (recursive) rule. Example 10 The following rule expressions compute all supervisees who have been managed or are being managed, either directly or indirectly, by their supervisors. manage(allfall mgmt(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g) : { union(mdfmanaged(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g, mgfmanaging(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g, allfall mgmt(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g). 00
00
00
0
0
00
00
0
00
0
00
00
manage(allfall mgmt(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g) : { union(mdfmanaged(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g, mgfmanaging(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g, allfall mgmt(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g), manage(allfall mgmt(Supe id ; Supe name ; supesfsupervisee(Supe id ; Supe name )g)g). 2 00
00
000
0
00
00
0
00
00
000
0
00
000
0
00
000
Without the built-in predicate for extended union, we must substitute union whenever it appears in the rule expressions in Example 10 by its de nition, i.e., we must generate at least three dierent rule expressions, as given in Example 8, for each manage in Example 10 to specify the extended union operation on Managed and Managing. Note that even if the operand relations Managed and Managing are in Partitioned Normal Form (PNF) [13]3, the resultant relation Manage generated by the recursive rules in Example 10 may not be in PNF since there might exist dierent tuples in Manage with the same Supr id and Supr name (the atomic component of a tuple in Manage). In order to generate a resultant relation Manage in PNF, we simply merge all tuples with the same Supr id and Supr name in Manage. (A built-in predicate merge which accomplishes this task is de ned in Section 4.5.) 3
A nested relation s is in PNF if the atomic component of each tuple in s is unique.
9
3.2 Extended Intersection (inter or \e )
Given any two tuples t 2 s and t 2 s , t intersecting t yields a new tuple t in the resultant relation if (i) t and t agree on the atomic component (which also becomes the atomic component of t ), and (ii) the extended intersection of each pair of corresponding non-atomic components of t and t is non-empty. 0
0
0
00
0
00
0
Example 11 Following the de nition of extended intersection, we specify below the rule
expressions for extended intersection on the two nested relations in Figure 1. Again, we include the second rule expression given below to illustrate the recursive de nition of extended intersection. The resultant relation Com mgmt, generated upon the evaluation of the rule expression, is as shown in Figure 4 which yields all supervisees who have been managed and are being managed by their supervisors.
inter(mdfmanaged(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g, mgfmanaging(Supr id; Supr name; supesfsupervisee(Supe id ; Supe name )g)g, comfcom mgmt(Supr id; Supr name; supesfsupervisee(Supe id ; Supe name )g)g) : { inter(supesfsupervisee(Supe id; Supe name)g, supesfsupervisee(Supe id ; Supe name )g, supesfsupervisee(Supe id ; Supe name )g). 0
0
00
0
00
0
00
00
inter(supesfsupervisee(Supe id; Supe name)g, supesfsupervisee(Supe id ; Supe name )g, supesfsupervisee(Supe id; Supe name)g) : { Supe id = Supe id ; Supe name = Supe name . 2 0
0
0
0
3.3 Extended Dierence (diff or ?e )
Given each tuple t 2 s, t is retained in the resultant relation of s ?e s if there does not exist any tuple t 2 s such that the atomic components of t and t are the same. Otherwise, the extended set dierence is recursively applied to each pair of corresponding non-atomic components X of t and t , and a new tuple t with the same atomic component at the top-level scheme of t (t ) and with t [X ] = t[X ] ?e t [X ] (6= ;) is created in the resultant relation. We can construct two rule expressions, R1 and R2, for extended dierence so that R1 computes the former case while R2 computes the latter case. 0
0
0
0
0
00
0
00
0
Example 12 Suppose we want to construct a nested relation which includes all employees who are being managed but have not previously been managed by their current supervisors. Following the de nition of extended dierence, we specify below the rule expressions for extended dierence on the two nested relations Managed and Managing in Figure 1. The resultant relation Curr mgmt, generated upon the evaluation of these rule expressions, is shown in Figure 5.
diff (mgfmanaging(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g, mdfmanaged(Supr id ; Supr name ; supesfsupervisee(Supe id ; Supe name )g)g, 0
0
0
10
0
currfcurr mgmt(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g) : { setof (t(Supr id ; Supr name ), mdfmanaged(Supr id ; Supr name , supesfsupervisee(Supe id ; Supe name )g)g, L), t(Supr id; Supr name) 62 L. 0
0
0
0
0
0
diff (mgfmanaging(Supr id; Supr name; supesfsupervisee(Supe id; Supe name)g)g, mdfmanaged(Supr id; Supr name; supesfsupervisee(Supe id ; Supe name )g)g, currfcurr mgmt(Supr id; Supr name; supesfsupervisee(Supe id ; Supe name )g)g) : { diff (supesfsupervisee(Supe id; Supe name)g, supesfsupervisee(Supe id ; Supe name )g, supesfsupervisee(Supe id ; Supe name )g). 0
0
00
0
00
0
00
00
diff (supesfsupervisee(Supe id; Supe name)g, supesfsupervisee(Supe id ; Supe name )g, supesfsupervisee(Supe id; Supe name)g) : { Supe id 6= Supe id ; Supe name 6= Supe name : 2 0
0
0
0
3.4 Extended Natural Join (join or ./e)
Join operations are dicult to de ne in the nested relational model due to the possibility that (atomic and non-atomic) attributes may be nested at dierent levels in a nested relation [13]. We restrict common attributes of the operand relations in extended natural join to be the attributes of the top-level scheme. (Three kinds of join operations, namely 1-1, 1-N, and M-N joins, are introduced in [5], however, their formal de nitions are not given.) In the extended natural join, two tuples, t 2 s and t 2 s , are joinable if the extended intersection on the projections over common (atomic and non-atomic) attributes of t and t is non-empty. This constraint is similar to the constraint of the traditional natural join operation, i.e., two tuples contribute to the join if they agree on common attributes. Example 13 Following the de nition of extended natural join, we construct below the rule expression for natural joining the two nested relations Student and Faculty as shown in Figure 6. We assume that there exists a built-in predicate for extended intersection (inter). The extended natural join on Student and Faculty yields the information about students and faculty members such that a student is taking a class being taught by a faculty who is in the same department of the student. Upon being evaluated, the rule expression yields the resultant relation Student Faculty as shown in Figure 7. The data structure diagrams for Student, Faculty, and Student Faculty are given in Figure 8. join(stfstudent(Sname; Dept; coursesfcourse(Cname; Crhrs)g)g, ftffaculty(Fname;Dept; coursesfcourse(Cname ; Crhrs )g)g, sf fstudent faculty(Sname; Dept; Fname;coursesfcourse(Cname ; Crhrs )g)g) : { inter(coursesfcourse(Cname; Crhrs)g, coursesfcourse(Cname ; Crhrs )g, coursesfcourse(Cname ; Crhrs )g). 2 0
0
0
0
0
00
0
0
00
00
11
00
Com mgmt Supr id Supr name Supervisee Supe id Supe name 1 Steve 21 Je Figure 4: Com mgmt = Managed \e Managing.
Curr mgmt Supr id Supr name Supervisee Supe id Supe name 1 Steve 37 Mary 12 John 42 Lee Figure 5: Curr mgmt = Managing ?e Managed. Student Sname Dept Course Cname Crhrs Mary CS CS 230 4 Math 112 4 Chris CS CS 470 3 CS 580 3
Fname Davis Jones Smith
Faculty Dept Course Cname Crhrs Math Math 671 3 Math 112 4 CS CS 580 3 CS 130 2 CS CS 470 3 CS 230 4
Figure 6: Nested Relations Student and Faculty.
Student Faculty Sname Dept Fname Course Cname Crhrs Mary CS Smith CS 230 4 Chris CS Jones CS 580 3 Chris CS Smith CS 470 3 Figure 7: Student Faculty = Student ./e Faculty 12
3.5 Extended Projection (proj or e )
Similar to the traditional projection operation, the extended projection retains columns in a nested relation s which are speci ed in an attribute list that includes attributes (atomic as well as non-atomic) of the top-level scheme of s. In the head tuple term of the rule expression for extended projection, the rst and second arguments denote the nested relational schemes of the operand and resultant relations, respectively, while the third argument denotes the set of (atomic and non-atomic) attributes to be projected which are represented by their attribute names and are included in a set term w. The names of all (atomic and nonatomic) attributes appeared in the top-level scheme of the operand relation are included in a set-term w . A valid extended projection operation requires that w w . 0
0
Example 14 We construct below the rule expression for extended projection on Faculty in Figure 6 to project the atomic attribute Dept and the set term courses. Evaluating the rule expression yields the resultant relation Offer in Figure 9.
proj (ftffaculty(Fname; Dept; coursesfcourse(Cname;Crhrs)g)g, offersfoffer(Dept; coursesfcourse(Cname; Crhrs)g)g, wfDept; coursesg) : { wfDept; coursesg w fFname; Dept; coursesg: 2 0
Even though an operand relation of the extended projection is in PNF, the resultant relation s might not be in PNF since there might exist two tuples, t1 and t2, in s such that t1 and t2 have the same atomic components. The resultant relation Offer in Figure 9 is an example since Offer is not in PNF even though the operand relation Faculty is in PNF. In order to generate a resultant relation in PNF, we must apply the extended union operation on s which is generated by the extended projection so that tuples with the same atomic components in s are merged.
Example 15 The rule expression in Example 14 can be modi ed as follows to yield a
nested relation in PNF. We assume that there exists a built-in predicate for extended union (union).
proj (ftffaculty(Fname; Dept; coursesfcourse(Cname;Crhrs)g)g, List, wfDept; coursesg) : { wfDept; coursesg w fFname; Dept; coursesg, setof (t(Dept; coursesfcourse(Cname; Crhrs)g), ftffaculty(Fname; Dept; coursesfcourse(Cname; Crhrs)g)g; L), merge(L; List). 0
merge([t(T1)jT2]; Ls) : ?merge([t(T1)jT2]; offers foffer (T1)g; Ls). merge([t(Dept; coursesfcourse(Cname; Crhrs)g) j Ts], offers foffer (Dept ; coursesfcourse(Cname ; Crhrs )g)g; Ls) : { union(offersfoffer(Dept; coursesfcourse(Cname; Crhrs)g)g, offers foffer (Dept ; coursesfcourse(Cname ; Crhrs )g)g, 0
0
0
0
0
0
0
0
0
0
0
13
0
offers foffer (Dept ; coursesfcourse(Cname ; Crhrs )g)g), merge(Ts; offers foffer (Dept ; coursesfcourse(Cname ; Crhrs )g)g; Ls). merge([]; Ls; Ls). 00
00
00
00
00
00
00
00
00
00
After these rule expressions are evaluated, a nested relation in PNF is generated which is similar to the nested relation Offer in Figure 9 except that the last two tuples in Offer are collapsed into one tuple with the atomic value, CS . 2
3.6 Extended Selection (sel or e)
A selection condition is a boolean expression involving comparisons between attributes or between attributes and constants. Selection conditions are de ned on the atomic attributes of a nested relation or an embedded nested relation. If the selection condition on the toplevel atomic components of a tuple t in the operand relation is satis ed, then the extended selection is recursively applied to deal with selections on the non-atomic components of t if such selections are required, and tuples which satisfy the selection condition are included in the resultant relation. In the extended selection, each boolean term, c(Attr1; Op; Attr2) or c(Attr; Op; Const), is included in a set-term sp, where Attr1; Attr2, and Attr are attribute names, Op is a (set) comparison operator, and Const is a constant. Furthermore, in the head tuple term of the rule expression for extended selection, the rst argument denotes sp, while the second and third arguments denote the nested relational schemes of the operand and resultant relations, respectively.
Example 16 Following the de nition of extended selection, we construct the following rule expression with the selection condition `Dept = \CS " ^ Crhrs > 2 on Faculty in Figure 6. The boolean term, c(Dept; =; \CS "), is evaluated to be true if t[Dept] = \CS ", where t 2 Faculty; otherwise, it is evaluated to be false. Evaluating the expression given below 0
yields the resultant relation Sel Faculty in Figure 10.
sel(spfc(Dept; =; \CS "); c1(Crhrs; >; 2)g, ftffaculty(Fname;Dept; coursesfcourse(Cname;Crhrs)g)g, sf fsel faculty(Fname; Dept; coursesfcourse(Cname ; Crhrs )g)g) : { c(Dept; =; \CS "), sel(sp1fc1(Crhrs; >; 2)g, coursesfcourse(Cname; Crhrs)g, coursesfcourse(Cname ; Crhrs )g). 2 0
0
0
0
Note that the set term sp in Example 16 denotes a conjunction of the boolean terms c(Dept; =; \CS ") and c1(Crhrs; >; 2). Readers should not assume that the extended selection operation can handle only conjunctive boolean terms. Disjunctive boolean terms can be speci ed by using a number of rule expressions with conjunctive boolean terms. For example, if the selection condition in Example 16 is changed to 'Dept = \CS " _ Fname = \Smith" , then the two head tuple terms in two dierent rule expressions: sel(spfc(Dept; = ; \CS ")g; : : :) and sel(spfc(Fname; =; \Smith")g; : : :), yield all desired tuples for this selection condition. 0
14
st
ft
student
QQQ Q
Sname Dept
student faculty
faculty
QQQ Q
QQQ Q
courses Fname Dept course
sf
## QQQ # Cname Crhrs
courses Sname Dept Fname course
## QQQ # Cname Crhrs
course
## QQQ # Cname Crhrs
Figure 8: Data Structure Diagrams for Student, Faculty, and Student Faculty.
Offer Dept Course Cname Crhrs Math Math 671 3 Math 112 4 CS CS 580 3 CS 130 2 CS CS 470 3 CS 230 4 e Figure 9: Dept;course (faculty).
Sel Faculty Fname Dept Course Cname Crhrs Jones CS CS 580 3 Smith CS CS 470 3 CS 230 4 e Figure 10: Dept =\CS "
15
^
Crhrs>2 (Faculty ).
courses
4 Built-in Predicates for Extended Relational Algebra Operations In this section, we formally de ne all extended relational algebra operators which are introduced in Section 3.
4.1 Extended Union (union)
There are three rule expressions for extended union which are mutually exclusive and the rst one is de ned recursively. In the head tuple term of each rule expression, there are three arguments which are based on the same relation scheme. The rule expressions for extended union in Example 8 are generalized so that they can be applied to any two nested relations with the same relation scheme. In this and the following subsections, we assume that an attribute labeled with an `A' denotes an atomic attribute, `s' denotes a set term, `r' denotes a tuple term, and r; r1; : : : ; rl; r11 ; : : :, and rln are tuple terms embedded in s. To shorten the length of each rule expression, we assign the \don't-care"( ) symbol as the argument of each set term which is nested several levels deep in the schemes of the operand relations and the resultant relation. Readers should not misinterpret that these arguments (which have been replaced by the ` ' symbols) are insigni cant, but instead, the \don't-care" arguments are not being used for the computation performed at higher level of nesting. 0
union(sfr(A1; : : :; Ai, s1fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, v t s fr (A1 ; : : :; Ai , s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, sl frl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, v 1 t s fr (A1 ; : : :; Ai, s1 fr1(A11 ; : : :; A1j ; s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g) v 1 t : { union(s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g), 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
0
00
00
0
0
0
00
00
00
0
0
0
00
00
0
0
00
00
00
0
0
0
00
0
0
0
00
0
0
0
00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
00
00
00
0
0
0
0
0
00
00
.. .
union(slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, 0
0
16
0
0
sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g, t v slfrl(Al1 ; : : :; Alj ; sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g, v 1 t slfrl(Al1 ; : : :; Alj ; sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g). 0
0
0
0
0
0
0
0
0
0
0
0
0
00
0
0
00
0
0
0
0
00
0
0
0
00
0
0
0
0
00
0
0
0
0
00
0
0
0
0
t
1
v
0
0
union(sfr(A1; : : :; Ai, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, sl frl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, t v s fr (A1 ; : : :; Ai , s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, sl frl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, v 1 t s fr (A1 ; : : :; Ai, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g) v t : { setof (t(A1 ; : : :; Ai ); s fr (A1; : : :; Ai ; s1fr1(: : :)g; : : :; slfrl(: : :)g)g; L), t(A1 ; : : :; Ai) 62 L. 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
union(sfr(A1; : : :; Ai, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, sl frl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, v t s fr (A1 ; : : :; Ai , s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : : sl frl(Al1 ; : : :; Alj ; sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, v 1 t s fr (A1 ; : : :; Ai, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g) v 1 t : { setof (t(A1 ; : : :; Ai ); sfr(A1; : : :; Ai; s1fr1(: : :)g; : : :; sl frl(: : :)g)g; L), t(A1 ; : : :; Ai) 62 L. 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
0
0
0
00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4.2 Extended Intersection (inter)
As stated in Section 3.2, tuple t 2 s intersects tuple t 2 s if they agree on their atomic components and the recursively-applied extended intersection on each corresponding pair of 0
17
0
non-atomic components of t and t is non-empty. Thus, each tuple in the resultant relation is embedded within4 a tuple in s and s . All the notations and assumptions used in the rule expression for extended intersection given below (and other operations to be formally introduced later) are the same as those used in the rule expressions for extended union. 0
0
inter(sfr(A1; : : :; Ai, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, sl frl(Al1 ; : : :; Alj ; sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, v t s fr (A1 ; : : :; Ai, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : : slfrl(Al1 ; : : :; Alj ; sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, v 1 t s fr (A1 ; : : :; Ai , s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g) v 1 t : { inter(s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; s1 fr1(A11 ; : : :; A1j ; s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g), 0
0
0
0
0
0
0
0
0
0
0
0
0
00
00
0
0
0
00
00
00
00
0
0
0
0
00
00
0
0
0
0
00
00
00
0
00
0
0
0
0
00
00
00
0
0
0
0
0
0
0
0
0
00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
00
00
00
.. .
inter(slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g, t v slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g, v 1 t slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g). 0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
0
0
0
00
00
0
0
0
0
00
0
0
0
0
0
0
00
0
0
0
00
0
0
0
0
0
t
1
0
0
0
v
0
4.3 Extended Dierence (diff )
As mentioned in Section 3.3, to compute s ?e s , a tuple t 2 s is retained in the resultant relation s if t does not agree with any tuple t 2 s on the atomic component (A1; : : : ; Ai) at the top-level scheme, i.e., 8t 2 s , t[A1; : : :; Ai] 6= t [A1; : : : ; Ai]; in this case, the rst rule expression for extended dierence given below applies. If there exists such a tuple 4 A tuple t is embedded within another tuple t0 if UNNEST (ftg) UNNEST (ft0 g), where 0
00
0
0
0
0
0
UNNEST is the total unnesting operator as de ned in [7]. Hence, t is a tuple embedded within t0 if the totally unnesting of t is a subset of the totally unnesting of t0 .
18
t 2 s such that t[A1; : : :; Ai] = t [A1; : : :; Ai], then the second rule expression for extended dierence given below is used to recursively apply the extended dierence on each corresponding pair of non-atomic components of t and t to retain (embedded) tuples from the rst operand relation. Hence, each tuple t 2 s is embedded within a tuple in s, and none of the tuples in s is embedded within any tuple in s . 0
0
0
0
00
00
0
diff (sfr(A1; : : :; Ai , s1fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, v t s fr (A1 ; : : :; Ai, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : : sl frl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, v 1 t s fr (A1; : : :; Ai, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g) v t : { setof (t(A1 ; : : :; Ai); s fr (A1 ; : : :; Ai ; s1fr1(: : :)g; : : :; slfrl (: : :)g)g; L), t(A1 ; : : :; Ai) 62 L. 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
diff (sfr(A1; : : :; Ai , s1 fr1(A11 ; : : :; A1j ; s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, t v s fr (A1 ; : : :; Ai, s1 fr1(A11 ; : : :; A1j ; s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, sl frl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g, v 1 t s fr (A1; : : :; Ai, s1 fr1(A11 ; : : :; A1j ; s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g) v 1 t : { diff (s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g), 0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
0
00
00
00
00
00
0
0
0
00
0
0
00
00
0
0
0
0
0
0
0
0
0
00
00
00
00
.. .
diff (slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g, 0
0
0
0
0
0
0
t
19
0
00
0
0
0
0
0
00
00
00
0
0
0
0
00
0
0
0
00
0
0
0
00
0
0
0
0
0
0
0
0
0
0
v
0
0
slfrl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g, v 1 t slfrl(Al1 ; : : :; Alj ; sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g). 0
0
0
0
0
00
0
0
0
0
0
0
00
0
0
00
0
0
0
0
0
0
00
0
0
00
0
00
0
0
t
1
0
0
v
0
0
4.4 Extended Natural Join (join)
A tuple t in the resultant relation of the extended natural join on s and s is yielded by joining t 2 s and t 2 s such that t[X ] \e t [X ] 6= ;, where X is the set of common (atomic and non-atomic) attributes of t and t . Hence, t [XY ] and t [XZ ] are embedded within t and t , where XY and XZ form the relation schemes of s and s , respectively. To simplify the discussion, we assume that in the following rule expressions for extended natural join on s and s , the two operand relations have common atomic terms A1, : : :, Ap, p 0, and common set terms s1, : : :, sq , q 0. 00
0
0
0
0
0
00
00
0
0
0
join(sfr(A1; : : :; Ap, Ap+1 ; : : :; Ai, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1f g; : : :; s1nv f g)g)g; : : :, sq frq (Aq1 ; : : :; Aqj , sq1 frq1 (Aq11 ; : : :; Aq1k ; sq11 f g; : : :; sq1m f g)g; : : :, sqn frqn (Aqn1 ; : : :; Aqn ; sqn1 f g; : : :; sqn f g)g)g, v t sq+1 f g; : : :; slf g)g, s fr (A1; : : :; Ap; Ap+1 ; : : :; Ai , s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, sq frq (Aq1 ; : : :; Aqj ; sq1 frq1 (Aq11 ; : : :; Aq1k ; sq11 f g; : : :; sq1m f g)g; : : :, sqn frqn (Aqn ; : : :; Aqn ; sqn1 f g; : : :; sqn f g)g)g, 1 v t sq+1 f g; : : :; sl f g)g, s fr (A1; : : :; Ap; Ap+1; : : :; Ai; Ap+1 ; : : :; Ai , s1fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, sq frq (Aq1 ; : : :; Aqj , sq1 frq1 (Aq11 ; : : :; Aq1k ; sq11 f g; : : :; sq1m f g)g; : : :, sqn frqn (Aq1 ; : : :; Aqn , sqn1 f g; : : :; sqn f g)g)g, v t sq+1 f g; : : :; slf g; sq+1 f g; : : :; sl f g)g) : { inter(s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g), 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
00
0
0
00
00
00
00
00
00
00
00
00
00
0
0
0
00
0
0
00
0
0
0
00
0
0
0
0
0
0
0
0
0
00
0
0
0
0
0
0
0
0
0
0
00
0
0
0
0
00
00
00
00
.. .
inter(sq frq (Aq1 ; : : :; Aqj , sq1 frq1 (Aq11 ; : : :; Aq1k ; sq11 f g; : : :; sq1m f g)g; : : :, sqn frqn (Aqn1 ; : : :; Aqn ; sqn1 f g; : : :; sqn f g)g)g 0
0
0
0
0
0
0
t
20
0
0
0
v
0
sq frq (Aq1 ; : : :; Aqj ; sq1 frq1 (Aq11 ; : : :; Aq1k ; sq11 f g; : : :; sq1m f g)g; : : :, sqn frqn (Aqn ; : : :; Aqn ; sqn1 f g; : : :; sqn f g)g)g 1 v t sq frq (Aq1 ; : : :; Aqj ; sq1 frq1 (Aq11 ; : : :; Aq1k ; sq11 f g; : : :; sq1m f g)g; : : :, sqn frqn (Aqn ; : : :; Aqn , sqn1 f g; : : :; sqn f g)g)g). 0
0
0
0
0
00
0
0
0
0
0
0
00
0
0
00
0
0
0
0
00
0
0
0
00
0
0
0
t
0
1
0
0
0
v
0
4.5 Extended Projection (proj )
In the following rule expressions for extended projection, we assume that Ai1 ; : : : ; Aij , 1 ik m, 1 k j , are atomic terms, and sp1 ; : : :; spq , 1 pk n, 1 k q, are set terms in the operand relation s to be projected, and the resultant relation is s . proj (sfr(A1; : : :; Am; s1 f g; : : :; snf g)g, s fr (Ai1 ; : : :; Aij ; sp1 f g; : : :; spq f g)g, wfAi1 ; : : :; Aij ; sp1 ; : : :; spq g) : { wfAi1 ; : : :; Aij ; sp1 ; : : :; spq g w fA1; : : :; Am ; s1; : : :; sn g. Assume that s is in PNF. Then since the intermediate result L generated after applying the extended projection on s is not necessarily in PNF (there might exist tuples in L with the same atomic components), it is necessary to merge tuples in L with the same atomic components by using the extended union operation if the resultant relation of extended projection is expected to be in PNF. The modi ed rule expressions for extended projection on a nested relation in PNF are given below which yields a resultant relation in PNF. proj (sfr(A1; : : :; Am; s1 f g; : : :; snf g)g, R, wfAi1 ; : : :; Aij ; sp1 ; : : :; spq g) : { wfAi1 ; : : :; Aij ; sp1 ; : : :; spq g w fA1; : : :; Am ; s1; : : :; sn g, setof (t(Ai1 ; : : :; Aij ; sp1 f g; : : :; spq f g); sfr(A1; : : :; Am; s1f g; : : :; snf g)g; L), merge(L; R). 0
0
0
0
0
merge([t(T1)jT2]; Ls) : ?merge([t(T1)jT2]; s fr (T1)g; Ls). merge([t(Ai1 ; : : :; Aij ; sp1 f g; : : :; spq f g) j Ts], s fr (Ai1 ; : : :; Aij ; sp1 f g; : : :; spq f g)g; Ls) : { union(sfr(Ai1 ; : : :; Aij ; sp1 f g; : : :; spq f g)g, s fr (Ai1 ; : : :; Aij ; sp1 f g; : : :; spq f g)g, s fr (Ai1 ; : : :; Aij ; sp1 f g; : : :; spq f g)g), merge(Ts; s fr (Ai1 ; : : :; Aij ; sp1 f g; : : :; spq f g)g; Ls). merge([]; Ls; Ls). 0
0
0
0
00
0
0
00
00
0
0
0
0
00
00
00
00
00
4.6 Extended Selection (sel)
In the following rule expression for extended selection, we let c, ci, cij , and cijk , i; j; k 2 I +, denote the boolean teams on the atomic attributes in (embedded) relations s, si, sij , and sijk , respectively. As suggested earlier in Section 3.6, disjunctive boolean teams can be handled in LDL=NR by using a number of rule expressions for extended selection with conjunctive boolean terms. 21
sel(spfc; c1; c11 ; c111 ; : : :; c1n1 ; : : :; cl; cl1 ; cl11 ; : : :; cln1 ; : : :g, sfr(A1; : : :; Ai, s1fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, sl frl(Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g); t v s fr (A1; : : :; Ai, s1 fr1(A11 ; : : :; A1j , s11 fr11 (A111 ; : : :; A11k ; s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g; : : :, slfrl (Al1 ; : : :; Alj , sl1 frl1 (Al11 ; : : :; Al1k ; sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g)g) v 1 t : { c, sel(sp1fc1; c11 ; c111 ; : : :; c1n1 ; : : :g s1 fr1(A11 ; : : :; A1j ; s11 fr11 (A111 ; : : :; A11k , s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g, s1 fr1(A11 ; : : :; A1j ; s11 fr11 (A111 ; : : :; A11k , s111 f g; : : :; s11m f g)g; : : :, s1n fr1n (A1n1 ; : : :; A1nt ; s1n1 f g; : : :; s1nv f g)g)g), 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
.. .
sel(splfcl; cl1 ; cl11 ; : : :; cln1 ; : : :g, sl frl(Al1 ; : : :; Alj ; sl1 frl1 (Al11 ; : : :; Al1k , sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln1 ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g, v t sl frl(Al1 ; : : :; Alj ; sl1 frl1 (Al11 ; : : :; Al1k , sl11 f g; : : :; sl1m f g)g; : : :, sln frln (Aln ; : : :; Aln ; sln1 f g; : : :; sln f g)g)g). 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
t
1
0
0
0
v
0
5 Concluding Remarks We provided a set of built-in predicates for extended relational algebra operations in LDL=NR which can be used to manipulate complex data structures in nested relations. Using these built-in predicates, LDL=NR has the expressive advantage of the extended relational algebra operations, and thus is more convenient for query speci ers expressing (recursive) queries of nested relations.
References [1] S. Abiteboul and N. Bidoit. Non First Normal Form Relations: An Algebra Allowing Data Restructuring. Computer and System Sciences, 33:361{393, 1986. [2] C. Beeri, S. Naqvi, R. Ramakirishnan, O. Shmueli, and S. Tsur. Sets and Negation in a Logic Database Language (LDL1). In Proceedings of the Sixth ACM SIGACTSIGMOD Symposium on Principles on Database Systems, New York, 1987. ACM. [3] Q. Chang and Y.-K. Ng. Built-in Predicates for Extended Relational Algebra Operations in a Logic Database Languages. In Proceedings of Abstracts and Summaries of the 1st Joint Conference on Information Sciences (JCIS94), pages 96{99, Pinehurst, North Carolina, November 1994. 22
[4] Q. Chen and W.W. Chu. Deductive and Object-Oriented Database, chapter HILOG: A High-order Logic Programming Language for Non-1NF Deductive Databases. Elsevier Science Publishers, 1990. W. Kim, J. Nicolas, and S. Nishio (Editors). [5] Q. Chen and Y. Kambayashi. Nested Relation Based Database Knowledge Representation. In Proceedings of 1991 ACM SIGMOD International Conference on Management of Data, pages 328{337. ACM, 1991. [6] L. Colby. A Recursive Algebra and Query Optimization for Nested Relations. In Proceedings of 1989 ACM SIGMOD International Conference on Management of Data, pages 124{138, New York, 1989. ACM. [7] P. Fischer and S. Thomas. Operations for Non-First-Normal Form Relations. In Proceedings of IEEE COMPSAC, pages 464{475. IEEE, 1983. [8] Richard Hull. Four Views of Complex Objects: A Sophisticate's Introduction. In S. Abiteboul, P. Fischer, and H. Schek, editors, Nested Relations and Complex Objects in Databases, pages 87{116. Springer-Verlag, New York, 1989. Lecture Notes in Computer Science, 361. [9] G. Kuper. Logic Programming with Sets. Journal of Computer and System Sciences, 41:44{64, 1990. [10] S. J. Lim and Y.-K. Ng. Set-Term Matching in a Logic Database Language. In Proceedings of the 4th International Conference on Database Systems for Advanced Applications, pages 189{196, Singapore, April 1995. [11] S. J. Lim and Y.-K. Ng. Set-Term Uni cation in a Logic Database Language. In Proceedings of the 1st Annual International Computing and Combinatorics Conference, pages 101{110, Xian, China, August 1995. Springer-Verlag. Lecture Notes in Computer Science, 959. [12] J. W. Lloyd. Foundations of Logic Programming, Second, Extended Edition. SpringVerlag, New York, 1987. [13] M. Roth, H. Korth, and A. Silberschatz. Extended Algebra and Calculus for Nested Relational Databases. ACM Transactions on Database Systems, 13(4):389{417, December 1988. [14] O. Shmueli, S. Tsur, and C. Zaniolo. Compilation of Set Terms in the Logic Data Language (LDL). Logic Programming, 12(1):89{119, 1992. [15] C. Zaniolo. The Representation and Deductive Retrieval of Complex Objects. In Proceedings of the International Conference on Very Large Databases, pages 458{469, Stockholm, 1985. ACM.
23