












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Understanding Algebra & Calculus is key to understanding SQL, query processing! Page 4. Database Management Systems, R. Ramakrishnan. 4. Preliminaries.
Typology: Lecture notes
1 / 20
This page cannot be seen from the preview
Don't miss anything!













Allow manipulation and retrieval of data from a database. v Relational model supports simple, powerful QLs:–^ Strong formal foundation based on logic.–^ Allows for much optimization. v Query Languages
!=^ programming languages!
-^ QLs not expected to be “Turing complete”.–^ QLs not intended to be used for complex calculations.–^ QLs support easy, efficient access to large data sets.
relation instances
, and the
result of a query is also a relation instance.^ – Schemas^ of input relations for a query are fixed (butquery will run regardless of instance!)–^ The schema for the
result^ of a given query is also fixed! Determined by definition of query languageconstructs. v Positional vs. named-field notation:– Positional notation easier for formal definitions,named-field notation more readable.– Both used in SQL
Database Management Systems, R. Ramakrishnan
sid^ sname
rating^ age 22 dustin
31 lubber
58 rusty^
sid^ sname
rating^ age 28 yuppy
31 lubber
44 guppy
58 rusty^ sid^ bid^ day 22 101 10/10/96 58 103 11/12/96^10 35. R1 S1 S
v^ “Sailors” and “Reserves”relations for our examples. v^ We’ll use positional ornamed field notation,assume that names of fieldsin query results are`inherited’ from names offields in query inputrelations.
v^ Deletes attributes that are not in^ projection list
. v^ Schema^ of result contains exactlythe fields in the projection list,with the same names that theyhad in the (only) input relation. v^ Projection operator has toeliminate
duplicates! (Why??)– Note: real systems typicallydon’t do duplicate eliminationunless the user explicitly asksfor it. (Why not?)
sid^ sname
rating^
age
28 yuppy
58 rusty
sname^ ratingyuppy^9 rusty^10 π σ sname rating^
S ( ( (^) rating (^) , )) (^2) > 8
v^ Selects rows that satisfy^ selection condition
. v^ No duplicates in result!(Why?) v^ Schema^ of resultidentical to schema of(only) input relation. v^ Result^ relation can bethe^ input^
for anotherrelational algebraoperation! ( Operatorcomposition. )
has one field per field of S1 and R1, with field names `inherited’ if possible.^ – Conflict : Both S1 and R1 have a field called
sid.
(sid)^ sname^
rating^ age^ (sid)
bid^ day 22 dustin^
7 45.0^22
101 10/10/ 22 dustin^
7 45.0^58
103 11/12/ 31 lubber^
8 55.5^22
101 10/10/ 31 lubber^
8 55.5^58
103 11/12/ 58 rusty^
10 35.0^22
101 10/10/ 58 rusty^
10 35.0^58
103 11/12/ *^ Renaming operator
:
v^ Result schema
same as that of cross-product. v^ Fewer tuples than cross-product, might beable to compute more efficiently v^ Sometimes called a
(sid)^ sname
rating^
age^ (sid)
bid^ day
22 dustin
7
45.0^58
103 11/12/
31 lubber
8
55.5^58
103 11/12/
Database Management Systems, R. Ramakrishnan
all^ boats.
v^ Let^ A^ have 2 fields,
x^ and^ y ;^ B
have only field
y :
- A/B^ = –^ i.e.,^ A/B^ contains all
x^ tuples (sailors) such that for
every^ y
tuple (boat) in
B , there is an
xy^ tuple in^
A****.
- Or : If the set of
y^ values (boats) associated with an
x^ value
(sailor) in^ A
contains all
y^ values in^
B , the^ x^ value is in
A/B.
v^ In general,
x^ and^ y^ can be any lists of fields;
y^ is the
list of fields in
B , and^ x^
y^ is the list of fields of
{^
} x^ x y^
A^ y^
B |^ ,∃^ ∈
π^ σ sname^ bid
serves Sailors ((^
Re^ )^
) =^103
<
v^ Solution 2
v^ Solution 3
σ sname color^ red
Boats^
serves^ Sailors ((^ '^
)^ Re'
)
=^
<^
<
v^ A more efficient solution:^ π^ π^
π^ σ sname^ sid^
bid^ color^
Boats^ red
s^ Sailors
(^ ((^
)^ ' ' Re )^
) =^
<^ ><
*^ A query optimizer can find this given the first solution!
sid^ is a key for Sailors):
ρ^
π^ σ (^
,^ ((^
'^ '^
)^ Re^
))
Tempgreen
sid^ color
Boats green serves =^
<
Database Management Systems, R. Ramakrishnan
π^
π
(^ , (
Re,^
) / (^
))
Tempsids^
servessid bid Boatsbid
.....