5
Volume 14, Number 4 13 June 1982 GENERALIZED DIVISION FOR RELATIONAL ALGEBRAIC LAaNGUAGE * R. DEMOLOMBE ONERA-CERT. B.P. 4Lt25, 31055 Totdouse Cedex, France Received 13 May 198 1; revised version received 24 February 1982 KeyworrLF: Database, relational model, algebraic language 1. Introduction In [l] Codd has defined a set of algebraic operators on a set of tuples (i.e., relations) These operators when they are composed allow us to define a query language which is called “Rela- tional Algebraic Language”. In this language we can define a set of opera- tors :-which would just guarantee the completeness of the language. However, some queries may be very difficult to express if we only use these basic operators. So it is useful to add some other opera- tors which could be defined as functions of the previous ones, and which would facilitate the ex- pression of some of the queries. So Codd has defined the division operator which corresponds, more or less, to the universal quanti- fier, combined with implicatien, in Predicate Calculus language. In this paper we are going to give the definition of 9 generalized division opera- tor which will permit us to express easily some queries which are unpracticable even if we have the Codd’s division clperator. Moreover, we will give the corresponding meaning of this operator in Relational Calculus (see [ 11)and Predicate Calcu- lus language (see [3,5]). l A generalized division with the same semantic has also been defined independently by Pirotte [4]. 2. Defiiition of the generalized division We will use the following notation: R and S are relation names. A, z (resp. B, B) is a partition of the set of attributes of the relation R (resp. S) and we shall write R(& A) (resp. S(B, 8)). WA] is the projection of the relation R on the attribute A; let p be a tuple of IR. We note that p[A] will represent the compuilents of p corre- sponding to the attributes of A. gu(r[A]) = { r[A] 1 r E Rj is the image set of 4x1 under R. First we recall the definition of the division operator given by Codd. Definition 0 &odd). If A and B are union-compat- ible *, the division of R by S on the attributes A and B is defined as follows: R[A + B]S = (r[A] ]r E R A S[B] c g,(r[x])). If we detail the definition of S[B] c g&@J), we have R[A+B]S= (r[x]]rERAWs’ES3r’ER r’[A] = r[A] A r’[A] = s’[B]). We will now define the degeneralized division. Definition 1. If A and B are union-compatible, the generalized division of R and S on the attributes A Two sets of attributes are union-campatible if they have the me cardinality, and if the attributes which have the same rank are defmed on the same domain. 174 0020-O 190/82/0000-0000/$02.75 @ 1982 North-Holland

Generalized division for relational algebraic language

Embed Size (px)

Citation preview

Page 1: Generalized division for relational algebraic language

Volume 14, Number 4 13 June 1982

GENERALIZED DIVISION FOR RELATIONAL ALGEBRAIC LAaNGUAGE *

R. DEMOLOMBE ONERA-CERT. B.P. 4Lt25, 31055 Totdouse Cedex, France

Received 13 May 198 1; revised version received 24 February 1982

KeyworrLF: Database, relational model, algebraic language

1. Introduction

In [l] Codd has defined a set of algebraic operators on a set of tuples (i.e., relations) These operators when they are composed allow us to define a query language which is called “Rela- tional Algebraic Language”.

In this language we can define a set of opera- tors :-which would just guarantee the completeness of the language. However, some queries may be very difficult to express if we only use these basic operators. So it is useful to add some other opera- tors which could be defined as functions of the previous ones, and which would facilitate the ex- pression of some of the queries.

So Codd has defined the division operator which corresponds, more or less, to the universal quanti- fier, combined with implicatien, in Predicate Calculus language. In this paper we are going to give the definition of 9 generalized division opera- tor which will permit us to express easily some queries which are unpracticable even if we have the Codd’s division clperator. Moreover, we will give the corresponding meaning of this operator in Relational Calculus (see [ 11) and Predicate Calcu- lus language (see [3,5]).

l A generalized division with the same semantic has also been defined independently by Pirotte [4].

2. Defiiition of the generalized division

We will use the following notation: R and S are relation names. A, z (resp. B, B) is a partition of the set of attributes of the relation R (resp. S) and we shall write R(& A) (resp. S(B, 8)). WA] is the projection of the relation R on the attribute A; let p be a tuple of IR. We note that p[A] will represent the compuilents of p corre- sponding to the attributes of A. gu(r[A]) = { r[A] 1 r E Rj is the image set of 4x1 under R. First we recall the definition of the division

operator given by Codd.

Definition 0 &odd). If A and B are union-compat- ible *, the division of R by S on the attributes A and B is defined as follows:

R[A + B]S = (r[A] ]r E R A S[B] c g,(r[x])).

If we detail the definition of S[B] c g&@J), we have

R[A+B]S= (r[x]]rERAWs’ES3r’ER

r’[A] = r[A] A r’[A] = s’[B]).

We will now define the degeneralized division.

Definition 1. If A and B are union-compatible, the generalized division of R and S on the attributes A

’ Two sets of attributes are union-campatible if they have the me cardinality, and if the attributes which have the same rank are defmed on the same domain.

174 0020-O 190/82/0000-0000/$02.75 @ 1982 North-Holland

Page 2: Generalized division for relational algebraic language

Volume 14, Number 4 INFORMATION PROCESSING LE’ITERS 13 June 1982

and B is defined as follows:

R(A:B)E= ((r[A],s[B])/rERAsESA

Vs’ E s(,(s;[B] = s[B]) ‘J

(3r’ E R r’[K] = r[X]

M[A] = sis]))) .

The intuitive interpretation of this definition is the following: a tuple (r@], s,[B]) belonging to the result is such that the set of sub-tuples s[B] corresponding in S to s,[B] is included in the set of sub-tuples r[A] corresponding in R to r,[X] (see Fig. 1).

Now, we will see another definition of the gen- eralized division as a function of the basic opera- tors: Cartesian product (X), Difference (-) and Projection ([ I).

Definition 2. If A and B are union-compatible, the generali- 4 division of R by S on the attributes A and B is defined as follows:

R(A: B)S = R[A] X S[B]

- (R[A] X S - R X S[B])[& B].

Table 1

a b bq a a c c 9 e a d br f e b c r e d d r f b f c

R[A]XS

a b q a b r

a c 4 a c r a d r

ebq e b r

e c 9 e c r e d r

fbq f br

f c 9 f c r f dr

Rx S[E]

abq a b r

a c 9 a c r

adq

a d r

ebq e b r

e d 9 e d r

fbq R(A : B)S f br a 9 f c 9 a r f c r f 9

9 a 9 r a r

e 9 e r

f 9 f r

wx]XS-RXS[B]

e c 9 e c r f dr

-- (Nii] x S - RX S[E])[A, B]

e 9 e r f r

The intuitive interpretation of this definition is the following: - R[A] X S defines a set of tuples of the form

(3, b, b), - RX S[B] defines a set of tuples of the form

(3, a, 6). If (a, 6) belongs to (R@] X S - R X !@])[A, B], this means that there exists a tuple in R[x] X S of the form (8, b, 6) and there does not exist a tuple in R X !?@I of the form (8, a, 6) such that a = b. Therefore, if (a, 6) E R(A: B)S, then we have

r. [Al so Ii1 w

Fig. 1.

(a, 6) E R[x] X S[B] and for each tuple in NE] X S of the form (a, b, 6) there does not exist a tuple in R X S[B] of the form (a, a, 5) such that a = b.

Table 1 shows the details of the computations of R(A : B)S when we use Definition 2.

Now, we will prove the equivalence between Definitions 1 and 2. The idea of the proof is to translate both definitions into Predicate Calculus language and to prove that we obtain two equiva- lent expressions.

2.1. Equivalence between Defnitiori 1 and Definition 2

We will use the following notation: In R(x, y), x is a sub-tuple variable corre-

sponding to the attributes A, y is a sub-tuple variable corresponding to the attributes A. In S(Z, t), z is a sub-tuple variable corresponding to the attributes B, t is a sub-tuple variable corre- sponding to the attributes B.

175

Page 3: Generalized division for relational algebraic language

Volume 14, Number 4 Ih!FORMATION PROCESSING LETI’ERS 13 June 1982

Proof. Definition 1 defines the set of tuples: Definition 2 defines the set of tuples:

((x9 t> IF& t> > l { (XI 9 I F,h 0) l

ToI obtain the translation of Definition 1 into Predicate Calculus, we have that

((r[x],s[B])(rERkESAE;)

gives

To obtain the translation of Definition 2 into Predicate Calculus, we have that R.@J gives 3y R(x, y), S[B] gives 32 S(z, t), and wx] x S - R X S[B] gives

3y R(x, y) A S(z’, t) A ,(R(x, z’) A 32 S(z, t)).

((x~t)!3yR(x,y)A3zS(z,t)AE,).

The meaning of r E R (resp. s E S) is R(x, y) (resp. S(z, t)). However, if we use this interpretation, the variables x and y will be free in the expression R(x, y) A S(z, t) A E 1, when they must not be free. In fact, r G R (resp. s ES) must be interpreted here as 3y R(x, y) (resp. 32 S(z, t)).

In E;,

V s’ E S D; gives Vz’ VtLS(z’, t’) V D,

and

3r’ E R C’, gives 3x’ 3y’ R(x’, y’) A C,.

Finally,

C; = r’[x] = $A] A r’[A] = s’[B]

gives

C, ~x’=xAy’=z’.

Therefore, we have that

F?(x, t) = 3y R(x, y) A 32 S(z, t) A Vz’ Vt’

(-lS(z’, t’) v -l(t’ = t) v

(3x’ 3y’ R(x’, y’) A x’ = x A y’ = z’)) .

Factorizing the l and distributing Vt’ we have that

F,(x, t) = 3y R(x, y) A 32 S(z, t) A Vz’

(,(3t’ S(z’, t’) A t’ = t) V

(3x’ 3y’ R(x’, y’) A x’ = x A y’ = z’)).

For 41 the formulae F we have that

3u(F(u, v) Au = w) = F(w, v).

Therefore, we have that

F,(x, t) = 3y R(x, y) A 32 S(z, t) ‘&

W(,S(z’, t) V Rjx, z’)).

Therefore, (fix] X S - R X S[fi;]x& B] gives

32’ (3y R(x, y) A S(z’, t’)

A,(R(x, z’) A 32 S(z, t))).

Finally, we have that

F2(x, t) = 3y R(x, y) A 32 S(z, t) A 132’

(3~ R(x, Y) A S(z’, t)

/\,(R(x, z’) A 32 S(z, t))).

Expanding the l which is in -,3z’ we have that

F2(x, t) = 3y R(x, y) A 32 S(z, t) A Vz’

(7 3y R(x,, y) V 1 S(z’, t)

V (R(x, z’) A 32 S(z, t))).

If we use the notation,

G,(x) = 3y R(x, y), G,(t) = 3t S(z, t),

we will have that

F,(x, t) = G,(x) A G2(t) A Vz’

(-G,(x) V ,S(z’, t)

V (R(x, t’) A G,(t))) l

Expanding G,(x) A G,(t), we have that .

F,(x, t) = Vz’((Gr(x) A G,(t) A -G,(x)) V

(G,(x) A Gz(t) A yS(z’, t)) V

(G,(x) A G#) A R(x, t’) A G,(t))).

Thus we have that

F2(x, t) = Vz’( (G,(x) A G,(t) A ,S(z’, t)) V

(G,(x) A G,(t) A R(x, z’))).

Factorizing G,(x) A G,(t), we have that

176

Page 4: Generalized division for relational algebraic language

Volume 14, Number 4 INFORMATION PROCESSING LETTERS 13 June 1982

F2(x, t) = 3y R(x, y) A 32 S(z, t) A

Vz’(-lS(z’, 0) v R(x, z’)).

Therefore, we have that F,(x, t) = &(x, t).

Algebraic language and Predicate Calculus Ian- guage.

We can also remark that, according to these definitions, the generalized division is not defined when S[B] is an empty set.

This proof gives the meaning of the generalized division in Predicate Calculus language. Now, we will see how to simplify the formula F,, or F,, in order to provide a third definition of this operator.

2.2. Special case

We will proof that F, and F2 are equivalent to the formula F:

F(x, t) = 3z S(z, t) A Vz’(-,S(z’, t) \/’ R(x, z’)).

In the special case that B = {@} we find again that Codd’s division holds. In Definition 1, if B = {B}, the condition s’[B] = s[B] is always true, and the condition s E S, which is interpreted as 3z S(z, t), must be interpreted as 3 s E S when the set of components of t is empty. So we obtain that

Proof. First, we proof that we have F(x, t) --,

F,(x, t). R(A:B)S= (r[A]]rERA3sESAVs’ES

Let us consider a tuple (x0, t 0 > which satisfies F(x, t). Then, we have that

32 S(z, to) (1)

and

ijr’ E R r’[&] = r[ x] A r’[x] = s’ > .

Vz’(yS(z’, to) V R(x,, z’)). (2)

Let z. be the value of z such that S(z,, to) is true; then from (2) we have that

lS(zg, to) VR(x,, ~0).

This expression is Gghtly different from those of Definition 0 because we have the condition 3s E S which says that S must not be an empty set. The transformation of Definitions 2 and 3 is straight- forward in the case that B = (@} and gives that

R(A: B)S = R[x] - (R[x] x S - R)[A],

R(A : B)S = ((x) 132 S(z) A VZ’(-~(Z’) V R(x, 2’).

Therefore, we have that R(xo, z,) is true, and 3y 2.3. Examples of queries using the generalized

R(xo, y) is also true. division

Therefore, since F,(x. t) is of the form 3y R(x, y) A F(x, t), the tuple (x0, to) satisfies

F,(x, t).

Let us consider the relations:

On the other hand, it is obvious that we have F&x, t) 4 F(x, t). So we have that F(x, t) E F,(x, t).

SELL (SUPPLIER, PARTI),

BUY (CUSTOMER, PART2),

We can now give the third definition of the generalized division.

and the query: “What are the pairs (customer, supplier) such that all the parts bought by the customer are sold by the supplier?“. It is expressed by:

Definition 3. If A and B are union-compatible, the generalized division of R by S on the attributes A and B is defined as follows:

SELL (PART1 : PART2) BUY.

R(A : B)S = ((x, t) ]3z S(z, t) A

Vz’(,S(z’, t) V R(x, z’))) .

If we suppose now that a customer can buy the same part to several suppliers, then we have the relations:

SELL(SUPPLIER1, PARTI),

We can remark that Definitions 1, 2 and 3 give three equivalent definitions of the generalized divi- sion into Relational Calculus language (see [I]),

BUY(CUSTOMER, PART2, SUPPLIERZ).

Let us consider the query: “What are the pairs (customer, supplier} such that this customer buys

977

Page 5: Generalized division for relational algebraic language

Volume 14, I%mber 4 INFORMATION PROCESSING LE’ITERS 13 June 1982

all its parts from this supplier?“. It is expressed by:

(SELYPARTI : PART2) BUY)(SUPPLIERl = SUPPLIERa).

These two queries should be quite difficult to express withovzt the genera&d division using the operators X , - md [ 1, as indicated in Defiition 2. On the other hand, it seems to us that the standard division cannot provide any help for these queries.

References

[l] E.F. Codd, Relational completeness of database sublan- guages in database systems, m: R Rush, ed., Courant Computer Science Symposium 6 (Prentice-Hall, Engkwood

PI Cliffs, NJ, 1972). R Demolom~ Assigning meaning to illd9fined queries expressed in Predicate C%ldus Sanguage, in: H. G&&e, J. Minker and J.M. Nicolas, eds., Advances in Database The- ory, Vol. 1 (Plenum, New York, 1981).

13) E. Mendelsolm, Introduction to iWathematical Logic (Van Nostrand, New York, 1964).

[4] A. Pirotte, A precise definition of basic relational notions and of the relational algebra, Internat. Rept. Comput. Corp. of America, 1981.

is] J.D. Ullmaa, Principles of Database Systems (Pitman, London, 1980).

178