中文网站
  Advanced Search
Read the latest Blogs from IT professionals in the field. Read and write community created documents. Need IT help? Ask our staff. Connect with your peers. Check our Tech Shop for posters, books and software tools. Home

3.2.3 Database Systems: Additional Operations(2)

4. The Division Operation

Division, denoted ÷, is suited to queries that include the phrase "for all".Suppose we want to find all the customers who have an account at all branches located in Brooklyn. Strategy:think of it as three steps.
We can obtain the names of all branches located in Brooklyn by

r1 = â…¡bname(Σbcity="Brooklyn"(branch))

Figure 3.19 in the textbook shows the result.
We can also find all cname, bname pairs for which the customer has an account by

r2 = â…¡cname.bname(deposit)

Figure 3.20 in the textbook shows the result.

Now we need to find all customers who appear in r2 with every branch name in r1. The divide operation provides exactly those customers:

â…¡cname.bname(deposit) ÷ â…¡bname(Σbcity="Brooklyn"(branch))

which is simply r2 ÷r1.

Formally,

  • Let r(R) and s(S) be relations.
  • Let S∈ R.
  • The relation r ÷s is a relation on scheme R - S.
  • A tuple t is in r÷ s if for every tuple ts in s there is a tuple tr in r satisfying both of the following:

tr [S] = ts[S] (3.2.1)
tr[R - S] = t[R - S] (3.2.2)

 These conditions say that the R - S portion of a tuple t is in r ÷ s if and only if there are tuples with
the r - s portion and the S portion in r for every value of the S portion in relation S.

We will look at this explanation in class more closely.
The division operation can be de ned in terms of the fundamental operations.

r ÷s = â…¡R-S(r)-â…¡R-S((â…¡R - S(r) × s)-r)

Read the text for a more detailed explanation.

5. The Assignment Operation

Sometimes it is useful to be able to write a relational algebra expression in parts using a temporary relation variable (as we did with r1 and r2 in the division example).
The assignment operation, denoted ← , works like assignment in a programming language. We could rewrite Division, denoted ÷, is suited to queries that include the phrase "for all".Suppose we want to find all the customers who have an account at all branches located in Brooklyn. Strategy:think of it as three steps.
We can obtain the names of all branches located in Brooklyn byour division definition as

temp1 ←R -S(r)
temp2 ←R -S((temp1 × s)- r)
result = temp1-temp2

No extra relation is added to the database, but the relation variable created can be used in subsequent
expressions. Assignment to a permanent relation would constitute a modi cation to the database.

Database System Structure: