Beruflich Dokumente
Kultur Dokumente
Languages
S1
S1 P1
P2 S2
S1 P2
S3
S2 P3
P2 S4
S2 P4
P4
S2 P1 S1
S2 P2 S4
S3 P2 P1
S2
S4 P2 P2
S4 P4 P4
Shipment Parts
© Prof. Navneet Goyal, BITS, Pilani
Join
A1 B1 B1 C1
A2 B1 B2 C2
A3 B2 B3 C3
A1 B1 C1
A2 B1 C1
NATURAL
JOIN A3 B2 C2
ρ (Tempboats, (σ Boats))
color =' red ' ∨ color =' green '
π sname(Tempboats !" Re serves !" Sailors)
..... /π (σ Boats)
bid bname =' Interlake'
© Prof. Navneet Goyal, BITS, Pilani
Summary
n The relational model has rigorously
defined query languages that are
simple and powerful.
n Relational algebra is more
operational; useful as internal
representation for query evaluation
plans.
n Several ways of expressing a given
query; a query optimizer should
choose the most efficient version.
R A B C
1 2 5
3 4 6 πA, B (R)
1 2 7
A B
1 2 8
1 2
Write down πA, B (R) 3 4
1 2
1 2
© Prof. Navneet Goyal, BITS, Pilani
Selection on BAGS
R A B C
1 2 5
3 4 6 σC>=6 (R)
1 2 7
A B C
1 2 7
3 4 6
Write down σC>=6 (R) 1 2 7
1 2 7
R A B S B C
2 3
1 2
4 5
1 2 4 5
A R.B S.B C
1 2 2 3
Write down RxS 1 2 2 3
1 2 4 5
1 2 4 5
1 2 4 5
© Prof. Navneet Goyal, BITS, Pilani
Natural Join of BAGS
R A B S B C
1 2 2 3
1 2 4 5
4 5
A B C
Write down R "! S 1 2 3
1 2 3
R A B S B C
1 2 2 3
1 2 4 5
4 5
A R.B S.B C
1 2 4 5
Write down R "! S
1 2 4 5
R.B < S.B
1 2 4 5
1 2 4 5
© Prof. Navneet Goyal, BITS, Pilani
Extended Operators of
RA
n Duplicate-Elimination Operator δ
n Aggregation Operators
• Sum
• Count
• Average
• Max
• Min
n Grouping Operator γ
n Sorting Operator τ
n Extended Projection
n Outerjoin Operator
α α 7
α β 7
β β 3
β β 10
27
Cust_name Credit_available
Curry 250
Hayes 0
Jones 5300
Smith 1600
Relation borrower
customer_name loan_number
Jones L-170
Smith L-230
Hayes L-155
loan Borrower
loan_number branch_name amount customer_name
L-170 Downtown 3000 Jones
L-230 Redwood 4000 Smith