Querying Relational Data: Algebra
Gerome Miklau
UMass Amherst CMPSCI 645 – Database Systems
Jan 31, 2008
Some slide content courtesy of Zack Ives, Ramakrishnan & Gehrke, Dan Suciu, Ullman & Widom
Querying Relational Data: Algebra Gerome Miklau UMass Amherst - - PowerPoint PPT Presentation
Querying Relational Data: Algebra Gerome Miklau UMass Amherst CMPSCI 645 Database Systems Jan 31, 2008 Some slide content courtesy of Zack Ives, Ramakrishnan & Gehrke, Dan Suciu, Ullman & Widom Next lectures Today
Some slide content courtesy of Zack Ives, Ramakrishnan & Gehrke, Dan Suciu, Ullman & Widom
– Instance : a table, with rows and columns. – Schema : specifies name of relation, plus
Restriction: all attributes are of atomic type, no nested tables
column, attribute, field row, tuple
– Real systems may allow duplicates for efficiency or other reasons – we’ll come back to this.
– 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.
– Schema of input relations for a query are fixed – The schema for the result of a given query is also fixed:
– Later: we discuss how to extend this to bags
– Union: ∪ – Difference: - – Selection: σ – Projection: Π – Cartesian Product: ×
– Intersection, complement – Joins (natural,equi-join, theta join) – Renaming: ρ – Division: /
sid name 1 Jill 2 Bo 3 Maya fid name 1 Diao 2 Saul 8 Weems sid cid 1 645 1 683 3 635 cid name sem 645 DB F05 683 AI S05 635 Arch F05 fid cid 1 645 2 683 8 635
sid name 1 Jill 2 Bo 3 Maya
sid name 1 Jill 4 Bob
sid name 2 Bo 3 Maya sid name 1 Jill 2 Bo 3 Maya 4 Bob
cid name sem 645 DB F05 683 AI S05 635 Arch F05
cid name sem 645 DB F05 683 AI S05 645 DB S05
cid name 645 DB 683 AI
17
sid cid 1 645 1 683 3 635 sid name 1 Jill 2 Bo
sid name sid cid 1 Jill 1 645 1 Jill 1 683 1 Jill 3 635 2 Bo 1 645 2 Bo 1 683 2 Bo 3 635
cid name sem 645 DB F05 683 AI S05 645 DB S05
courseID
cname term
645 DB F05 683 AI S05 645 DB S05
20
sid name 1 Jill 2 Bo 3 Maya sid cid 1 645 1 683 3 635
sid name cid 1 Jill 645 1 Jill 683 3 Maya 635
sid name 1 Jill 2 Bo 3 Maya fid name 1 Diao 2 Saul 8 Weems sid cid 1 645 1 683 3 635 cid name sem 645 DB F05 683 AI S05 635 Arch F05 fid cid 1 645 2 683 8 635
Not supported as a primitive operator, but useful for
Let A have 2 fields, x and y; B have only field y:
In general, x and y can be any lists of fields; y is the
Division is not essential op; just a useful
Idea: For A/B, compute all x values that are not
σname=”DB”
33
{xname, xsid | ∃xcid∃xterm Students(xsid,xname) ∧ Takes(xsid,xcid) ∧ Course(xcid,”DB”, xterm) }
36