Docsity

Relational Databases-Lecture 11 Slides-Computer Science, Slides of Relational Database Management Systems (RDBMS)

Partial preview of the text

Download Relational Databases-Lecture 11 Slides-Computer Science and more Slides Relational Database Management Systems (RDBMS) in PDF only on Docsity!

Relational Databases - Comp2400 / Comp

Lecture 14: More Relational Algebra

Selection, some definitions and hacks

select joins: theta, equi, natural, outer union compatibility, and the set operations for relational algebra intermediate results and attribute renaming

The Query

SELECT enumber,fname,lname,dname FROM employee,department WHERE (dname=’Administration’ OR dname=’Finance’) AND dnumber=dno;

So far we have made sense of the SELECT ...FROM ... part of this query.

Condition Expressions

Each tuple in a relation gives a value to each index, or attribute name.

Condition Expressions

Each tuple in a relation gives a value to each index, or attribute name. So, expressions like dname=’Administration’ can be evaluated to true or false in the context of a tuple.

Condition Expressions

Each tuple in a relation gives a value to each index, or attribute name. So, expressions like dname=’Administration’ can be evaluated to true or false in the context of a tuple. Most of the domains we use are totally ordered, so we can also evaluate eg. dname < ’Administration’ or enumber ≥ 100 These atomic expressions can be combined in the obvious way using boolean connectives AND (∧, &), OR (∨) and NOT (¬, ∼)

Condition Expressions

Each tuple in a relation gives a value to each index, or attribute name. So, expressions like dname=’Administration’ can be evaluated to true or false in the context of a tuple. Most of the domains we use are totally ordered, so we can also evaluate eg. dname < ’Administration’ or enumber ≥ 100 These atomic expressions can be combined in the obvious way using boolean connectives AND (∧, &), OR (∨) and NOT (¬, ∼) Any such condition expression defines a function from the relation to {true, false}.

SQL’s WHERE is Relational Algebra’s select

We use the condition expression to “filter” a relation, keeping only the tuples that evaluate to true.

Here’s the notation and definition:

σcond (R) = {t ∈ R | cond (t) = true}

Facts about Select

Conjunction (and) is composition is intersection σc∧c′^ (R) = σc (σc′^ (R)) = σc′^ (σc (R)) = σc (R) ∩ σc′^ (R)

Facts about Select

Conjunction (and) is composition is intersection σc∧c′^ (R) = σc (σc′^ (R)) = σc′^ (σc (R)) = σc (R) ∩ σc′^ (R) σc∨c′ (R) = σc (R) ∪ σc′ (R) σ¬c (R) = R − σc (R)

Facts about Select

Conjunction (and) is composition is intersection σc∧c′^ (R) = σc (σc′^ (R)) = σc′^ (σc (R)) = σc (R) ∩ σc′^ (R) σc∨c′ (R) = σc (R) ∪ σc′ (R) σ¬c (R) = R − σc (R) |σc (R)| ≤ |R|

Facts about Select

Conjunction (and) is composition is intersection σc∧c′^ (R) = σc (σc′^ (R)) = σc′^ (σc (R)) = σc (R) ∩ σc′^ (R) σc∨c′ (R) = σc (R) ∪ σc′ (R) σ¬c (R) = R − σc (R) |σc (R)| ≤ |R|

The left-hand sides might be faster to process, since they pass through the relation just once.

Facts about Select

Conjunction (and) is composition is intersection σc∧c′^ (R) = σc (σc′^ (R)) = σc′^ (σc (R)) = σc (R) ∩ σc′^ (R) σc∨c′ (R) = σc (R) ∪ σc′ (R) σ¬c (R) = R − σc (R) |σc (R)| ≤ |R|

The left-hand sides might be faster to process, since they pass through the relation just once.

All depends on the access paths (index, hash) into the relation vs attributes used in query. The algebra gives us options to assess.

Join

Joining two tables using product and selection is so common, we define a new operation for it.

A ⊲⊳a=b B ≡ σa=b(A × B)

Join

Joining two tables using product and selection is so common, we define a new operation for it.

A ⊲⊳a=b B ≡ σa=b(A × B)

Using this, our query becomes

πfname,lname,dname( σdname=′Finance′∨dname=′Administration′ ( employee ⊲⊳dnum=dno department))