SlideShare a Scribd company logo
Relational Algebra
1
Fall 2001 Database Systems 1
Relational Algebra
• A relation is a set of tuples. Each relational
algebra operation takes as input a list of
relations and produces a single relation.
• General form:
OperatorArguments (List of Relations)
 
New Relation
• After each operation, the remaining attributes
are carried to the new relation. The attributes
may be renamed, but their domain remains the
same.
Fall 2001 Database Systems 2
Set Theoretic Operations
• Regular set operations on relations
• A set operation requires two participating relations R and
S to be compatible
– R and S should have the same attributes
• R(Name:D1, Email:D2)
• S(Name:D1, Email:D2, Address:D3)
• T(Name:D1, Email:D4)
• V(Name:D1, Email:D2)
Which relations above are union (set operation)
compatible?
– Union compatibility may require type conversion
(casting).
Relational Algebra
2
Fall 2001 Database Systems 3
Set Operations
 ¢¡¤£¦¥ §©¨£ ¥¡  ! #¤$%¥(')0¥$¡1$) 
243©5 673
SR ∪
8 9 @BADC7E F©GIHQP©RDHSR©T¤F
F 5H QPUFVT 5 3 8 6 T 9
W 3 H¤FVTGQFVXYH 56 V3
SR ∩
8 9 @BADC7E F©GIHQP©RDHSR©T¤F
` 6 HDP 5 3 8aR 3Yb 9
c 5d Qd FVT¤F 3 XQF
SR −
8 9 @BADC7E F©GIHQP©RDHSR©T¤F 5 3
8e`¦AQH 36 H 5 3 9
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Fall 2001 Database Systems 4
pYq¢rs0t%u pQvw r¤x€y¤ ‚yx0vƒ
„Y… †(‡Yˆ‰  Smith@aol.com
„Y‘ ’“€”€•—– Johns@geocities.com
˜™ d0e “gf)• Brown@netmail.com
˜h i1e j—k Gray@microsoft.com
l0m)n)o0p0q l‚r s0tu vw‚xy o0x w0tz
{%| })~  € Gray@microsoft,com
{% ‚‚ƒ‚„g…‚~ † ‡ Robert432@aol.com
{0ˆ ‰ƒgŠ‚‹—‡ Johns@somewhere.com
{€Œ ‰—‡ ƒg‹ Jj@yahoo.com
{0 Ž(g—… Duke@jazz.com‘g’¤“0”Q• ‘0–— ˜Q–— ™š‚›œ —–ž—Ÿ  g¡ œ ¢g£gž š€Ÿ—–£g¤
¥%¦ §Y¦ ¨)© ª‚«¬‚­ ®€¯€­ ° ¯g±
¥%² §Y² ³1´µgµ€´± ¶U®%´· ¸ ¹ ¯gº—­ ° ¯€±
¥0» §Y² ¼¬%«¬‚­ © ¯gµ—¬ ½¤¬€¾¦¿¯€· À
¥€Á §» ‚¯gäµ—ª—­ ­ ³ª‚« «ª—­
Ä0Å ÆÇ ÈÉ Ê€Ëg̤͂ʂΗςÐ
É€ÑÒ Ó—Ô Ô Ê ÕÖ
Ó—× ×—Ø
Ö
Ä0Ù ÆYÚ Æ¤Û€ÑË—ÜÝÉ€ÑÛ
Ö Þ
Ê€Ô × Êgß
à‚áâ%ã à%äå â%æ€ç è á‚äå à0é—êgá€å ë1ì¤í—égî ç
ï0ðñ%ò ó0ô—õ€ö ÷%ò ïø òù
ï0ðñ%ø ó0ô—õ€ö ÷gú ï%ù û0ù
ï0ðñ0õ ó0ô—õ%ò ÷%ò ï€ú òó
ï0ðñgú ü%ôgò ÷0ù ï%ù ý%ù
ï0ðñ0ù ü%ôgò ÷%ò ïø øgö
ï0ðñ0û ü%ôgø ÷gú ï€ú ý‚ö
ï0ðñ‚ý ü%ôgø ÷%ø ïò ú
ï0ðñ0ó ü%ô—õ ÷%ø ï%õ ù
Relational Algebra
3
Fall 2001 Database Systems 5
Assignment and Alias
• Given a relation R, head(R)=A1…An is the list of attributes
in R.
• For each attribute, dom(A) gives the domain of A,
name(A) gives the name of the attribute
• Suppose B1…Bn is a list of attributes such that for each i,
dom(Bi) = dom(Ai)
Then assignment (:=) changes the names of some or all of
the attributes in R and results in a new relation S,
S(B1…Bn) := R(A1…An)
and dom(B1) = dom(A1) … dom(Bn) = dom(An).
Fall 2001 Database Systems 6
Set Operations
• Find all people who are registered as buyers or owners
 ¢¡¤£¦¥¨§©   ! ! #
$% ')(10 243 Smith@aol.com
$65 798@3¤ACB Johns@geocities.com
DE% F¦GIHCP Gray@microsoft.com
QRQRQ QRQ@Q QRQRQ
BUYERS-2(oid,name,email) :=
BUYERS(buyid,name,email)
RESULT := BUYERS-2 ∪ OWNERS
Relational Algebra
4
Fall 2001 Database Systems 7
Set Operations
• Find all people who are owners but not buyers
 ¢¡¤£¦¥¨§©   ! !¤ #
$% ')(0 132 Smith@aol.com
$4 5768293@ Johns@geocities.com
$¨A B¦CED3F Gray@microsoft.com
G G G
BUYERS-2(oid,name,email) :=
BUYERS(buyid,name,email)
RESULT:= OWNERS - BUYERS-2
Fall 2001 Database Systems 8
Set Operations
• Find all people who are both owners and buyers
HPI7QSRUTV WYX ` acb7dUe e7dUbfXhg
BUYERS-2(oid,name,email) :=
BUYERS(buyid,name,email)
RESULT := OWNERS ∩ BUYERS-2
Relational Algebra
5
Fall 2001 Database Systems 9
Projection
• Select all tuples from relation R, restrict each tuple to the
input attributes
– written as R[A1…An] or
for attributes A1…An from R
– meaning
nAA ...1
π
for each tuple in R
construct a new tuple containing
only attributes A1…An
place the new tuple in the result
end-for
remove duplicate tuples to preserve
the set property
Fall 2001 Database Systems 10
Projection
• Find the names and email addresses of people who are
both buyers and owners
 ¢¡¤£¦¥¨§©  !#
$%('0) G ra y @ m ic ro s o ft.c o m
RESULT:= OWNERS[name,email] ∩ BUYERS[name,email]
Relational Algebra
6
Fall 2001 Database Systems 11
Projection
• Find all the items on which at least one bid was placed
 ¢¡¤£¦¥¨§© 


!
#
RESULT := BIDS[iid]
Fall 2001 Database Systems 12
Selection
• Select certain tuples from a relation R based on a boolean
condition C
– written as R where C or
– meaning:
RCσ
for each tuple t in R
if t makes C true then
return t in the resulting relation
end-for
Relational Algebra
7
Fall 2001 Database Systems 13
Selection
• The selection condition C is built of
– atomic conditions of the form Ai ∝ Aj or Ai ∝ c where
• Ai, Aj are attributes and c is a constant of the same domain of
values, and
• ∝ is a comparison predicate of the form: =,  ,  , = , = , etc.
• If C1, C2 are selection conditions, then so are
• C1 AND C2
• C1 OR C2
• NOT C1
Fall 2001 Database Systems 14
Selection
• Find the bid identifiers of bids for item number “I1”:
 ¢¡¤£¦¥¨§© 
 !
 $#
 ¤%
I1-BIDS := BIDS WHERE iid = “I1”
RESULT := I1-BIDS[bid]
Relational Algebra
8
Fall 2001 Database Systems 15
Selection
• Find the bid identifiers of bids for item number “I1” that are
strictly more than $15.
I1-BIDS := BIDS WHERE
iid = “I1” AND amount  15
RESULT := I1-BIDS[bid]
 ¢¡¤£¦¥¨§© 
!
#
Fall 2001 Database Systems 16
Selection
• Find the dates in which a bid for item number “I1” or
“I5” was placed
I1orI5-BIDS := BIDS WHERE
iid = “I1” OR iid = “i5”
RESULT := I1orI5-BIDS[date]
$%('#)¤021 3542687
9A@2BDC
9A@2BFE
G(@HE
Relational Algebra
9
Fall 2001 Database Systems 17
Cartesian Product
• Multiply the relations R and S, producing |R|x|S| many
tuples with attributes head(R)+head(S)
• Cartesian product combines two relations into one “big”
relation
• meaning
for each tuple r in R do
for each tuple s in S do
compute a new tuple containing
all attributes in r and s
end-for
end-for
Fall 2001 Database Systems 18
R := Bids WHERE Amount  20 T := Items WHERE oid=“O2”
S := T[iid,name]
P := R X S
  ¡£¢ ¤ ¥§¦©¨ ¢ ¤ ¡¤ !#©$¨
% '( )0213 465 %7 8£7
% '5 9@0A 47 %7 BC7
% '@8 9@02( 465 %5 B3
D EF G HPIQSR
T@U VXW Y2YW `badc£W egf
h@i p£q£r qstuY6q
v w§x€y‚ ƒ w§x „£…†b‡ w§x ˆ ƒ w‰x€y2g‘2ˆ6ƒ w§x ’§“X”•–† —Sx ˆ ƒ —Sx ˜#…©“X‡
™d e@f g2h6i6j kl ™m n‚m k2f oCd pp©d qgr
™d ste
™d e©l u2h©v k2m ™m w@m k2f oCd pp©d qgr
™d ste
™d en u2h©f kl ™l wj k2f oCd pp©d qgr
™d ste
™d e@f g2h6i6j kl ™m n‚m k©i x‚y@zy©{b|–}2pgy
™d e©l u2h©v k2m ™m w@m k©i x‚y@zy©{b|–}2pgy
™d en u2h©f kl ™l wj k©i x‚y@zy©{b|–}2pgy
Relational Algebra
10
Fall 2001 Database Systems 19
Relational Algebra - Join
• For all pairs of tuples r and s from relations R and S where
Head(R)=A1…AnB1…Bk and Head(S)=B1…BkC1…Cm
such that r[B1…Bk] = s[B1…Bk],
include a tuple in R
 ¢¡ S with
attributes A1…AnB1…BkC1…Cm
• The attributes in common between the two relations (B1…Bk) are
called the “join attributes”
• The join is a cartesian product followed by a selection on the join
attributes, and a projection to remove the duplication of the join
attributes [formally: you have to rename the join attributes in one
relation so that you can express the selection/projection
operations]
Also called equijoin since
the main criteria is the
equality of join attributes
Fall 2001 Database Systems 20
Relational Algebra - Join
• Find all people with the same name and email address from the
“buyers” and “owners” relations
– join attributes are “Name” and “Email” from the buyer and
owners relations
– the joined relation will have attributes “Buyid, Name, Email, Oid”
– there are 5 × 4 pairs of tuples to compare on the attributes
“Name” and “Email”
£¥¤§¦©¨
¥  ¨¥
£!$#%' )(1032 ¨ 03( %54  %'
67 8@9BADC G r a y @ m ic ro s o ft,c o m E3F
Relational Algebra
11
Fall 2001 Database Systems 21
Relational Algebra - Join
 ¢¡¤£¦¥¢§¢¨  ¢©  Gray@microsoft,com
 !# $% Smith@aol.com
#')(10323
45 6¤798A@B Johns@geocities.com
4DC)E#F¢GIH
PDQ RASUTWVYX Brown@netmail.com `badcDegf3h
iqp r¤sUtvu Gray@microsoft.com
ixw€ybA‚¢ƒ
„¢…¤†¦‡¢ˆ¢‰ „¢ ‘’“” Gray@microsoft,com
„¢…¤†¦‡¢ˆ¢‰ „¢ ‘’“” Gray@microsoft,com
•¢–¤—¦˜¢™¢d •¢e fghi Gray@microsoft,com
Example below shows four of the twenty pairs of tuples
considered for the join
Fall 2001 Database Systems 22
Relational Algebra - Join
• Find the names of items with bids over $20
• Find the names of the owners of items with bids over $20
and are located in Boston
Temp1 := Bids WHERE Amount  20
Temp2 := Items jlk Temp1
Result := Temp2[Name]
Temp1 := Bids WHERE Amount  20
Temp3 := Items WHERE Location = “Boston”
Temp2 := Temp3 jlk Temp1
Temp4 := Temp2 jlk Owners
Result := Temp4[Owners.Name]
Relational Algebra
12
Fall 2001 Database Systems 23
Relational Algebra - Division
• Let head(R)=A1…AnB1…Bk and head(S)= B1…Bk
• R ÷ S is the “maximal” set of tuples from R[A1…An] such that
R contains all tuples in (R ÷ S) x S.
• Division is often
used for “for-all”
queries, e.g. “Find
tuples in R that are
in a relation with
‘all’ tuples in S.”
• All the attributes in the dividing relation S must exist in the
divided relation R!
for all tuples r in R[A1…An]
if for all tuples s in S, r+s is in R
place r in R ÷ S
end-if
end-for
Fall 2001 Database Systems 24
Relational Algebra - Division
  ¡ ¢ £
¤¦¥ §¨¥ ©¥
¤ §¨¥ ©¥
¤¦¥ § ©¥
¤¦¥ § ©
¤ §¨¥ ©
¤¦¥ § ©
¤¦¥ § ©
¤¦¥ §¨¥ ©
!
$#
$%
 ' (
)10 230
4 5 6
798 @38
7BA @38
Find:
• R ÷ S
• R ÷ V
• R ÷ Y
C DEGFIH¦PQSR TUR VXW
÷ S
Relational Algebra
13
Fall 2001 Database Systems 25
Relational Algebra - Division
  ¡ ¢ £
¤¦¥ §¨¥ ©¥
¤ §¨¥ ©¥
¤¦¥ § ©¥
¤¦¥ § ©
¤ §¨¥ ©
¤¦¥ § ©
¤¦¥ § ©
¤¦¥ §¨¥ ©
!
$#
$%
 ' (
)10 230
4 5 6
798 @38
7BA @38
Find:
• R ÷ S
• R ÷ V
• R ÷ Y
Fall 2001 Database Systems 26
Relational Algebra - Division
• Find identifiers of buyers who placed a bid on “all” the items
• Find the identifiers of items that have a bid from “all” the buyers
Temp := Items[Iid]
Temp1:= Bids[Buyid,Iid]
Result := Temp1 ÷ Temp
A := Buyers[BuyId]
B := Bids[Iid, BuyId]
Result := B ÷ A
Relational Algebra
14
Fall 2001 Database Systems 27
Relational Algebra Operations
– Union R ∪ S
– Intersection R ∩ S
– Difference R - S
– Assignment S(B1…Bn) := R(A1…An)
– Selection R where C
– Projection R[A1…An]
– Cartesian Product R x S
– Join R
 ¢¡ S
– Division R ÷ S
Fall 2001 Database Systems 28
£¥¤§¦¥¨© £¥ ¦  !!#
$¥% (')021 Smith@aol.com
$¥3 465718@9 Johns@geocities.com
$A BC@5EDF8 Brown@netmail.com
$ G H(CPIRQ Gray@microsoft.com
S!TFU(VWX SY2`bac d¥ef g Vfe!ah
ibp qsrut2v Gray@microsoft,com
iw xy7€7!r@‚Pƒ Robert432@aol.com
i„ …6y7†‡Pƒ Johns@somewhere.com
i7ˆ …6tRƒRy!‡ Jj@yahoo.com
i‰ (‘E’@ Duke@jazz.com “R”F•–— “˜™ de˜™ f
gEh(i j2kRl2g2m
˜
kon
p7q req sbtuuvwRx yEz@x@{Pz7|
p7} re} ~6€R€o|u
y‚„ƒ …
zo†PxP{Pz7|
pE‡ re} ˆ!wvwox2t@zR€@w ‰FwoŠ
‹zR‚@Œ
2Ž  ‘7’o“s”@•2–P– —!•˜˜•@–
E™ FŽ š› 2’Rœ2
ž’oŸR 7¡
›R¢£u•2–P–@’
¤!¥ •@¦P¦o˜¥
o§ e¨ ›R¢” ¥ © ’@–@¦P’7ª
«!¬­(® «b¯° ­(±E²@³ ¬!¯° «´2µ¬E° ¶s· ¸7´E¹2²
º»¼b½ ¾!¿7À7Á ½ ºÃ ½uÄ
º»¼bà ¾!¿7À7Á ÂRÅ ºÄ ÆÄ
º»¼À ¾!¿7À½ ½ º7Å ½„¾
º»¼Å Ç!¿½ ÂEÆ ºÄ ÈbÄ
º»¼Ä Ç!¿½ ½ ºÃ ÃEÁ
º»¼Æ Ç!¿Ã ÂRÅ º7Å È!Á
º»¼!È Ç!¿Ã Âà º½ Å
º»¼¾ Ç!¿7À Âà ºÀ Ä
Auction Database
Relational Algebra
15
Fall 2001 Database Systems 29
Problem 1
Find the name and email of owners of items located in
“Boston”
A := Items WHERE Location = “Boston”
B := A
 ¢¡ Owners
Result := B[Owners.Name, Owners.Email]
Fall 2001 Database Systems 30
Problem 2
Find the identifiers and amount of bids placed by
buyer “Roberts”
A := Buyers WHERE Name = “Roberts”
B := A
 ¢¡ Bids
Result := B[Bid, Amount]
Relational Algebra
16
Fall 2001 Database Systems 31
Problem 3
Find the names of buyers who placed a bid on an item
owned by “Brown”
A := Owners WHERE Name = “Brown”
B := (A
 ¢¡ Items) [Iid]
C := B
 ¢¡ Bids
Result := (C
 ¢¡ Buyers) [Buyers.Name]
Fall 2001 Database Systems 32
Problem 4
Find the identifier of items with more than one bid
A := Bids[Bid, Iid]
B := A x Bids[Bid,Iid]
C := B WHERE (A.Bid  Bids.Bid)
AND (A.Iid = Bids.Iid)
Result := C[Iid]
Relational Algebra
17
Fall 2001 Database Systems 33
Problem 5
Find the names of items all buyers placed a bid on
A := (Bids[Iid, BuyId]) ÷ (Buyers[Buyid])
B := A
 ¢¡ Items
Result := B[Name]

More Related Content

Viewers also liked (7)

PDF
Tecnologo en gestión logística
Elvia Padilla
 
PDF
Verbinding in de keten FFF2017
TOPdesk
 
PPTX
Extending the Yahoo Streaming Benchmark + MapR Benchmarks
Jamie Grier
 
PPTX
Digestion biochemistry
santusan
 
ODP
Constitucion española
Ernesto Suarez Gonzalez
 
PPTX
Mozilla at Darbar college
Shreyas Kutty
 
PPTX
Manual en español syma x8 c venture
Manuel Cristóbal Muñoz Jiménez
 
Tecnologo en gestión logística
Elvia Padilla
 
Verbinding in de keten FFF2017
TOPdesk
 
Extending the Yahoo Streaming Benchmark + MapR Benchmarks
Jamie Grier
 
Digestion biochemistry
santusan
 
Constitucion española
Ernesto Suarez Gonzalez
 
Mozilla at Darbar college
Shreyas Kutty
 
Manual en español syma x8 c venture
Manuel Cristóbal Muñoz Jiménez
 

Similar to [Www.pkbulk.blogspot.com]dbms04 (20)

PPTX
uniT 4 (1).pptx
YashWaghmare27
 
PPT
Relational Algebra
SahilKaushik27
 
PPTX
Database managment System Relational Algebra
Uttara University
 
PDF
RelationalAlgebra-RelationalCalculus-SQL.pdf
10GUPTASOUMYARAMPRAK
 
PPTX
Introduction to Relational Database Management Systems
Adri Jovin
 
PPTX
Relational algebra
Edward Blurock
 
PDF
Chapter – 5 Relational Algebra.pdf
TamiratDejene1
 
PDF
19IS305_U2_LP4_LM4-22-23.pdf
GOWTHAMR721887
 
PPT
2 rel-algebra
Mahesh Jeedimalla
 
PPT
Relational Algebra
Amin Omi
 
PPTX
316_16SCCCS4_2020052505222431.pptdatabasex
abhaysonone0
 
PPTX
RELATIONAL MODEL CONCEPTS.pptx with good explanation
farsankadavandy
 
PPT
Intro to relational model
ATS SBGI MIRAJ
 
PDF
Cs501 rel algebra
Kamal Singh Lodhi
 
PPT
chapter 5-Relational Algebra and calculus.ppt
University of Gondar
 
DOCX
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Raj vardhan
 
PPTX
Data Base Management system relation algebra ER diageam Sql Query -nested qu...
kudiyarc
 
PPT
Lecture 06 relational algebra and calculus
emailharmeet
 
PDF
chapter 6 Relational Algebra and calculus.pdf
Getnet Tigabie Askale -(GM)
 
uniT 4 (1).pptx
YashWaghmare27
 
Relational Algebra
SahilKaushik27
 
Database managment System Relational Algebra
Uttara University
 
RelationalAlgebra-RelationalCalculus-SQL.pdf
10GUPTASOUMYARAMPRAK
 
Introduction to Relational Database Management Systems
Adri Jovin
 
Relational algebra
Edward Blurock
 
Chapter – 5 Relational Algebra.pdf
TamiratDejene1
 
19IS305_U2_LP4_LM4-22-23.pdf
GOWTHAMR721887
 
2 rel-algebra
Mahesh Jeedimalla
 
Relational Algebra
Amin Omi
 
316_16SCCCS4_2020052505222431.pptdatabasex
abhaysonone0
 
RELATIONAL MODEL CONCEPTS.pptx with good explanation
farsankadavandy
 
Intro to relational model
ATS SBGI MIRAJ
 
Cs501 rel algebra
Kamal Singh Lodhi
 
chapter 5-Relational Algebra and calculus.ppt
University of Gondar
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Raj vardhan
 
Data Base Management system relation algebra ER diageam Sql Query -nested qu...
kudiyarc
 
Lecture 06 relational algebra and calculus
emailharmeet
 
chapter 6 Relational Algebra and calculus.pdf
Getnet Tigabie Askale -(GM)
 
Ad

More from AnusAhmad (20)

PPT
[Www.pkbulk.blogspot.com]file and indexing
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms12
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms11
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms10
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms09
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms07
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms06
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms05
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms03
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms02
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms01
AnusAhmad
 
PDF
[Www.pkbulk.blogspot.com]dbms13
AnusAhmad
 
PPTX
9. java server faces
AnusAhmad
 
PPTX
8. java script
AnusAhmad
 
PPTX
7. struts
AnusAhmad
 
PPTX
5. servlets
AnusAhmad
 
PPTX
4. jsp
AnusAhmad
 
PPTX
3. applets
AnusAhmad
 
PPTX
2. http, html
AnusAhmad
 
PPTX
1. intro
AnusAhmad
 
[Www.pkbulk.blogspot.com]file and indexing
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms12
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms11
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms10
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms09
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms07
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms06
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms05
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms03
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms02
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms01
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms13
AnusAhmad
 
9. java server faces
AnusAhmad
 
8. java script
AnusAhmad
 
7. struts
AnusAhmad
 
5. servlets
AnusAhmad
 
4. jsp
AnusAhmad
 
3. applets
AnusAhmad
 
2. http, html
AnusAhmad
 
1. intro
AnusAhmad
 
Ad

Recently uploaded (20)

PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 

[Www.pkbulk.blogspot.com]dbms04

  • 1. Relational Algebra 1 Fall 2001 Database Systems 1 Relational Algebra • A relation is a set of tuples. Each relational algebra operation takes as input a list of relations and produces a single relation. • General form: OperatorArguments (List of Relations)   New Relation • After each operation, the remaining attributes are carried to the new relation. The attributes may be renamed, but their domain remains the same. Fall 2001 Database Systems 2 Set Theoretic Operations • Regular set operations on relations • A set operation requires two participating relations R and S to be compatible – R and S should have the same attributes • R(Name:D1, Email:D2) • S(Name:D1, Email:D2, Address:D3) • T(Name:D1, Email:D4) • V(Name:D1, Email:D2) Which relations above are union (set operation) compatible? – Union compatibility may require type conversion (casting).
  • 2. Relational Algebra 2 Fall 2001 Database Systems 3 Set Operations  ¢¡¤£¦¥ §©¨£ ¥¡ ! #¤$%¥(')0¥$¡1$) 243©5 673 SR ∪ 8 9 @BADC7E F©GIHQP©RDHSR©T¤F F 5H QPUFVT 5 3 8 6 T 9 W 3 H¤FVTGQFVXYH 56 V3 SR ∩ 8 9 @BADC7E F©GIHQP©RDHSR©T¤F ` 6 HDP 5 3 8aR 3Yb 9 c 5d Qd FVT¤F 3 XQF SR − 8 9 @BADC7E F©GIHQP©RDHSR©T¤F 5 3 8e`¦AQH 36 H 5 3 9 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii Fall 2001 Database Systems 4 pYq¢rs0t%u pQvw r¤x€y¤ ‚yx0vƒ „Y… †(‡Yˆ‰  [email protected] „Y‘ ’“€”€•—– [email protected] ˜™ d0e “gf)• [email protected] ˜h i1e j—k [email protected] l0m)n)o0p0q l‚r s0tu vw‚xy o0x w0tz {%| })~  € Gray@microsoft,com {% ‚‚ƒ‚„g…‚~ † ‡ [email protected] {0ˆ ‰ƒgŠ‚‹—‡ [email protected] {€Œ ‰—‡ ƒg‹ [email protected] {0 Ž(g—… [email protected]‘g’¤“0”Q• ‘0–— ˜Q–— ™š‚›œ —–ž—Ÿ  g¡ œ ¢g£gž š€Ÿ—–£g¤ ¥%¦ §Y¦ ¨)© ª‚«¬‚­ ®€¯€­ ° ¯g± ¥%² §Y² ³1´µgµ€´± ¶U®%´· ¸ ¹ ¯gº—­ ° ¯€± ¥0» §Y² ¼¬%«¬‚­ © ¯gµ—¬ ½¤¬€¾¦¿¯€· À ¥€Á §» ‚¯gäµ—ª—­ ­ ³ª‚« «ª—­ Ä0Å ÆÇ ÈÉ Ê€Ëg̤͂ʂΗςРɀÑÒ Ó—Ô Ô Ê ÕÖ Ó—× ×—Ø Ö Ä0Ù ÆYÚ Æ¤Û€ÑË—ÜÝÉ€ÑÛ Ö Þ Ê€Ô × Êgß à‚áâ%ã à%äå â%æ€ç è á‚äå à0é—êgá€å ë1ì¤í—égî ç ï0ðñ%ò ó0ô—õ€ö ÷%ò ïø òù ï0ðñ%ø ó0ô—õ€ö ÷gú ï%ù û0ù ï0ðñ0õ ó0ô—õ%ò ÷%ò ï€ú òó ï0ðñgú ü%ôgò ÷0ù ï%ù ý%ù ï0ðñ0ù ü%ôgò ÷%ò ïø øgö ï0ðñ0û ü%ôgø ÷gú ï€ú ý‚ö ï0ðñ‚ý ü%ôgø ÷%ø ïò ú ï0ðñ0ó ü%ô—õ ÷%ø ï%õ ù
  • 3. Relational Algebra 3 Fall 2001 Database Systems 5 Assignment and Alias • Given a relation R, head(R)=A1…An is the list of attributes in R. • For each attribute, dom(A) gives the domain of A, name(A) gives the name of the attribute • Suppose B1…Bn is a list of attributes such that for each i, dom(Bi) = dom(Ai) Then assignment (:=) changes the names of some or all of the attributes in R and results in a new relation S, S(B1…Bn) := R(A1…An) and dom(B1) = dom(A1) … dom(Bn) = dom(An). Fall 2001 Database Systems 6 Set Operations • Find all people who are registered as buyers or owners  ¢¡¤£¦¥¨§© ! ! # $% ')(10 243 [email protected] $65 798@3¤ACB [email protected] DE% F¦GIHCP [email protected] QRQRQ QRQ@Q QRQRQ BUYERS-2(oid,name,email) := BUYERS(buyid,name,email) RESULT := BUYERS-2 ∪ OWNERS
  • 4. Relational Algebra 4 Fall 2001 Database Systems 7 Set Operations • Find all people who are owners but not buyers  ¢¡¤£¦¥¨§© ! !¤ # $% ')(0 132 [email protected] $4 5768293@ [email protected] $¨A B¦CED3F [email protected] G G G BUYERS-2(oid,name,email) := BUYERS(buyid,name,email) RESULT:= OWNERS - BUYERS-2 Fall 2001 Database Systems 8 Set Operations • Find all people who are both owners and buyers HPI7QSRUTV WYX ` acb7dUe e7dUbfXhg BUYERS-2(oid,name,email) := BUYERS(buyid,name,email) RESULT := OWNERS ∩ BUYERS-2
  • 5. Relational Algebra 5 Fall 2001 Database Systems 9 Projection • Select all tuples from relation R, restrict each tuple to the input attributes – written as R[A1…An] or for attributes A1…An from R – meaning nAA ...1 π for each tuple in R construct a new tuple containing only attributes A1…An place the new tuple in the result end-for remove duplicate tuples to preserve the set property Fall 2001 Database Systems 10 Projection • Find the names and email addresses of people who are both buyers and owners  ¢¡¤£¦¥¨§© !# $%('0) G ra y @ m ic ro s o ft.c o m RESULT:= OWNERS[name,email] ∩ BUYERS[name,email]
  • 6. Relational Algebra 6 Fall 2001 Database Systems 11 Projection • Find all the items on which at least one bid was placed  ¢¡¤£¦¥¨§© ! # RESULT := BIDS[iid] Fall 2001 Database Systems 12 Selection • Select certain tuples from a relation R based on a boolean condition C – written as R where C or – meaning: RCσ for each tuple t in R if t makes C true then return t in the resulting relation end-for
  • 7. Relational Algebra 7 Fall 2001 Database Systems 13 Selection • The selection condition C is built of – atomic conditions of the form Ai ∝ Aj or Ai ∝ c where • Ai, Aj are attributes and c is a constant of the same domain of values, and • ∝ is a comparison predicate of the form: =, , , = , = , etc. • If C1, C2 are selection conditions, then so are • C1 AND C2 • C1 OR C2 • NOT C1 Fall 2001 Database Systems 14 Selection • Find the bid identifiers of bids for item number “I1”:  ¢¡¤£¦¥¨§© ! $# ¤% I1-BIDS := BIDS WHERE iid = “I1” RESULT := I1-BIDS[bid]
  • 8. Relational Algebra 8 Fall 2001 Database Systems 15 Selection • Find the bid identifiers of bids for item number “I1” that are strictly more than $15. I1-BIDS := BIDS WHERE iid = “I1” AND amount 15 RESULT := I1-BIDS[bid]  ¢¡¤£¦¥¨§© ! # Fall 2001 Database Systems 16 Selection • Find the dates in which a bid for item number “I1” or “I5” was placed I1orI5-BIDS := BIDS WHERE iid = “I1” OR iid = “i5” RESULT := I1orI5-BIDS[date] $%('#)¤021 3542687 9A@2BDC 9A@2BFE G(@HE
  • 9. Relational Algebra 9 Fall 2001 Database Systems 17 Cartesian Product • Multiply the relations R and S, producing |R|x|S| many tuples with attributes head(R)+head(S) • Cartesian product combines two relations into one “big” relation • meaning for each tuple r in R do for each tuple s in S do compute a new tuple containing all attributes in r and s end-for end-for Fall 2001 Database Systems 18 R := Bids WHERE Amount 20 T := Items WHERE oid=“O2” S := T[iid,name] P := R X S   ¡£¢ ¤ ¥§¦©¨ ¢ ¤ ¡¤ !#©$¨ % '( )0213 465 %7 8£7 % '5 9@0A 47 %7 BC7 % '@8 9@02( 465 %5 B3 D EF G HPIQSR T@U VXW Y2YW `badc£W egf h@i p£q£r qstuY6q v w§x€y‚ ƒ w§x „£…†b‡ w§x ˆ ƒ w‰x€y2g‘2ˆ6ƒ w§x ’§“X”•–† —Sx ˆ ƒ —Sx ˜#…©“X‡ ™d e@f g2h6i6j kl ™m n‚m k2f oCd pp©d qgr ™d ste ™d e©l u2h©v k2m ™m w@m k2f oCd pp©d qgr ™d ste ™d en u2h©f kl ™l wj k2f oCd pp©d qgr ™d ste ™d e@f g2h6i6j kl ™m n‚m k©i x‚y@zy©{b|–}2pgy ™d e©l u2h©v k2m ™m w@m k©i x‚y@zy©{b|–}2pgy ™d en u2h©f kl ™l wj k©i x‚y@zy©{b|–}2pgy
  • 10. Relational Algebra 10 Fall 2001 Database Systems 19 Relational Algebra - Join • For all pairs of tuples r and s from relations R and S where Head(R)=A1…AnB1…Bk and Head(S)=B1…BkC1…Cm such that r[B1…Bk] = s[B1…Bk], include a tuple in R  ¢¡ S with attributes A1…AnB1…BkC1…Cm • The attributes in common between the two relations (B1…Bk) are called the “join attributes” • The join is a cartesian product followed by a selection on the join attributes, and a projection to remove the duplication of the join attributes [formally: you have to rename the join attributes in one relation so that you can express the selection/projection operations] Also called equijoin since the main criteria is the equality of join attributes Fall 2001 Database Systems 20 Relational Algebra - Join • Find all people with the same name and email address from the “buyers” and “owners” relations – join attributes are “Name” and “Email” from the buyer and owners relations – the joined relation will have attributes “Buyid, Name, Email, Oid” – there are 5 × 4 pairs of tuples to compare on the attributes “Name” and “Email” £¥¤§¦©¨ ¥ ¨¥ £!$#%' )(1032 ¨ 03( %54 %' 67 8@9BADC G r a y @ m ic ro s o ft,c o m E3F
  • 11. Relational Algebra 11 Fall 2001 Database Systems 21 Relational Algebra - Join  ¢¡¤£¦¥¢§¢¨  ¢© Gray@microsoft,com !# $% [email protected] #')(10323 45 6¤798A@B [email protected] 4DC)E#F¢GIH PDQ RASUTWVYX [email protected] `badcDegf3h iqp r¤sUtvu [email protected] ixw€ybA‚¢ƒ „¢…¤†¦‡¢ˆ¢‰ „¢ ‘’“” Gray@microsoft,com „¢…¤†¦‡¢ˆ¢‰ „¢ ‘’“” Gray@microsoft,com •¢–¤—¦˜¢™¢d •¢e fghi Gray@microsoft,com Example below shows four of the twenty pairs of tuples considered for the join Fall 2001 Database Systems 22 Relational Algebra - Join • Find the names of items with bids over $20 • Find the names of the owners of items with bids over $20 and are located in Boston Temp1 := Bids WHERE Amount 20 Temp2 := Items jlk Temp1 Result := Temp2[Name] Temp1 := Bids WHERE Amount 20 Temp3 := Items WHERE Location = “Boston” Temp2 := Temp3 jlk Temp1 Temp4 := Temp2 jlk Owners Result := Temp4[Owners.Name]
  • 12. Relational Algebra 12 Fall 2001 Database Systems 23 Relational Algebra - Division • Let head(R)=A1…AnB1…Bk and head(S)= B1…Bk • R ÷ S is the “maximal” set of tuples from R[A1…An] such that R contains all tuples in (R ÷ S) x S. • Division is often used for “for-all” queries, e.g. “Find tuples in R that are in a relation with ‘all’ tuples in S.” • All the attributes in the dividing relation S must exist in the divided relation R! for all tuples r in R[A1…An] if for all tuples s in S, r+s is in R place r in R ÷ S end-if end-for Fall 2001 Database Systems 24 Relational Algebra - Division   ¡ ¢ £ ¤¦¥ §¨¥ ©¥ ¤ §¨¥ ©¥ ¤¦¥ § ©¥ ¤¦¥ § © ¤ §¨¥ © ¤¦¥ § © ¤¦¥ § © ¤¦¥ §¨¥ © ! $# $% ' ( )10 230 4 5 6 798 @38 7BA @38 Find: • R ÷ S • R ÷ V • R ÷ Y C DEGFIH¦PQSR TUR VXW ÷ S
  • 13. Relational Algebra 13 Fall 2001 Database Systems 25 Relational Algebra - Division   ¡ ¢ £ ¤¦¥ §¨¥ ©¥ ¤ §¨¥ ©¥ ¤¦¥ § ©¥ ¤¦¥ § © ¤ §¨¥ © ¤¦¥ § © ¤¦¥ § © ¤¦¥ §¨¥ © ! $# $% ' ( )10 230 4 5 6 798 @38 7BA @38 Find: • R ÷ S • R ÷ V • R ÷ Y Fall 2001 Database Systems 26 Relational Algebra - Division • Find identifiers of buyers who placed a bid on “all” the items • Find the identifiers of items that have a bid from “all” the buyers Temp := Items[Iid] Temp1:= Bids[Buyid,Iid] Result := Temp1 ÷ Temp A := Buyers[BuyId] B := Bids[Iid, BuyId] Result := B ÷ A
  • 14. Relational Algebra 14 Fall 2001 Database Systems 27 Relational Algebra Operations – Union R ∪ S – Intersection R ∩ S – Difference R - S – Assignment S(B1…Bn) := R(A1…An) – Selection R where C – Projection R[A1…An] – Cartesian Product R x S – Join R  ¢¡ S – Division R ÷ S Fall 2001 Database Systems 28 £¥¤§¦¥¨© £¥ ¦ !!# $¥% (')021 [email protected] $¥3 465718@9 [email protected] $A BC@5EDF8 [email protected] $ G H(CPIRQ [email protected] S!TFU(VWX SY2`bac d¥ef g Vfe!ah ibp qsrut2v Gray@microsoft,com iw xy7€7!r@‚Pƒ [email protected] i„ …6y7†‡Pƒ [email protected] i7ˆ …6tRƒRy!‡ [email protected] i‰ (‘E’@ [email protected] “R”F•–— “˜™ de˜™ f gEh(i j2kRl2g2m ˜ kon p7q req sbtuuvwRx yEz@x@{Pz7| p7} re} ~6€R€o|u y‚„ƒ … zo†PxP{Pz7| pE‡ re} ˆ!wvwox2t@zR€@w ‰FwoŠ ‹zR‚@Œ 2Ž  ‘7’o“s”@•2–P– —!•˜˜•@– E™ FŽ š› 2’Rœ2 ž’oŸR 7¡ ›R¢£u•2–P–@’ ¤!¥ •@¦P¦o˜¥ o§ e¨ ›R¢” ¥ © ’@–@¦P’7ª «!¬­(® «b¯° ­(±E²@³ ¬!¯° «´2µ¬E° ¶s· ¸7´E¹2² º»¼b½ ¾!¿7À7Á ½ ºÃ ½uÄ º»¼bà ¾!¿7À7Á ÂRÅ ºÄ ÆÄ º»¼À ¾!¿7À½ ½ º7Å ½„¾ º»¼Å Ç!¿½ ÂEÆ ºÄ ÈbÄ º»¼Ä Ç!¿½ ½ ºÃ ÃEÁ º»¼Æ Ç!¿Ã ÂRÅ º7Å È!Á º»¼!È Ç!¿Ã Âà º½ Å º»¼¾ Ç!¿7À Âà ºÀ Ä Auction Database
  • 15. Relational Algebra 15 Fall 2001 Database Systems 29 Problem 1 Find the name and email of owners of items located in “Boston” A := Items WHERE Location = “Boston” B := A  ¢¡ Owners Result := B[Owners.Name, Owners.Email] Fall 2001 Database Systems 30 Problem 2 Find the identifiers and amount of bids placed by buyer “Roberts” A := Buyers WHERE Name = “Roberts” B := A  ¢¡ Bids Result := B[Bid, Amount]
  • 16. Relational Algebra 16 Fall 2001 Database Systems 31 Problem 3 Find the names of buyers who placed a bid on an item owned by “Brown” A := Owners WHERE Name = “Brown” B := (A  ¢¡ Items) [Iid] C := B  ¢¡ Bids Result := (C  ¢¡ Buyers) [Buyers.Name] Fall 2001 Database Systems 32 Problem 4 Find the identifier of items with more than one bid A := Bids[Bid, Iid] B := A x Bids[Bid,Iid] C := B WHERE (A.Bid Bids.Bid) AND (A.Iid = Bids.Iid) Result := C[Iid]
  • 17. Relational Algebra 17 Fall 2001 Database Systems 33 Problem 5 Find the names of items all buyers placed a bid on A := (Bids[Iid, BuyId]) ÷ (Buyers[Buyid]) B := A  ¢¡ Items Result := B[Name]