Relational Algebra: Understanding Operators, Expression Trees, and Bag Model of Data, Slides of Database Management Systems (DBMS)

An introduction to relational algebra, focusing on operators, expression trees, and the bag model of data. It covers topics such as union, intersection, difference, selection, projection, product, theta-join, natural join, renaming, sequences of assignments, expressions in a single assignment, precedence of relational operators, and schemas for results. Additionally, it discusses relational algebra on bags, why bags are used, and operations on bags. The document also includes examples and explanations of various concepts.

Typology: Slides

2012/2013

Uploaded on 04/26/2013

parina
parina 🇮🇳

4.4

(67)

222 documents

1 / 56

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Relational Algebra
Operators
Expression Trees
Bag Model of Data
1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38

Partial preview of the text

Download Relational Algebra: Understanding Operators, Expression Trees, and Bag Model of Data and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Relational Algebra

Operators

Expression Trees

Bag Model of Data

What is an “Algebra”

• Mathematical system consisting of:

  • Operands --- variables or values from which new

values can be constructed.

  • Operators --- symbols denoting procedures that

construct new values from given values.

Roadmap

• There is a core relational algebra that has

traditionally been thought of as the relational

algebra.

• But there are several other operators we shall

add to the core in order to model better the

language SQL --- the principal language used

in relational database systems.

Core Relational Algebra

• Union, intersection, and difference.

  • Usual set operations, but require both operands

have the same relation schema.

• Selection: picking certain rows.

• Projection: picking certain columns.

• Products and joins: compositions of relations.

• Renaming of relations and attributes.

Example

7

Relation Sells: store candy price 7-11 Twizzlers 2. 7-11 Kitkat 2. Kroger Twizzlers 2. Kroger Kitkat 3.

7-11Menu := SELECTstore=“7-11”(Sells): store candy price 7-11 Twizzlers 2. 7-11 Kitkat 2.

Projection

• R1 := PROJ L (R2)

  • L is a list of attributes from the schema of R2.
  • R1 is constructed by looking at each tuple of R2,

extracting the attributes on list L , in the order

specified, and creating from those components a

tuple for R1.

  • Eliminate duplicate tuples, if any.

Product

• R3 := R1 * R

  • Pair each tuple t1 of R1 with each tuple t2 of R2.
  • Concatenation t1t2 is a tuple of R3.
  • Schema of R3 is the attributes of R1 and then R2,

in order.

  • But beware attribute A of the same name in R

and R2: use R1. A and R2. A.

Example: R3 := R1 * R

11

R1( A, B )

R2( B, C )

R3( A, R1.B, R2.B, C )

Example

13

Sells( store, candy, price ) Stores(name, addr ) 7-11 Twiz. 2.50 7-11 Maple St. 7-11 Kitkat 2.75 Kroger River Rd. Kroger Twiz. 2. Kroger Pez 3.

StoreInfo := Sells JOIN (^) Sells.store = Stores.name Stores

StoreInfo(store, candy, price, name, addr ) 7-11 Twiz. 2.50 7-11 Maple St. 7-11 Kitkat 2.75 7-11 Maple St. Kroger Twiz. 2.50 Kroger River Rd. Kroger Pez 3.00 Kroger River Rd.

Natural Join

• A frequent type of join connects two relations

by:

  • Equating attributes of the same name, and
  • Projecting out one copy of each pair of equated

attributes.

• Called natural join.

• Denoted R3 := R1 JOIN R2.

Renaming

• The RENAME operator gives a new schema

to a relation.

• R1 := RENAME R1(A1,…,A n ) (R2) makes R1 be a

relation with attributes A1,…,A n and the

same tuples as R2.

• Simplified notation: R1(A1,…,A n ) := R2.

Example

17

Stores(name, addr ) 7-11 Maple St. Kroger River Rd.

R( store, addr ) 7-11 Maple St. Kroger River Rd.

R(store, addr) := Stores

Sequences of Assignments

• Create temporary relation names.

• Renaming can be implied by giving relations a

list of attributes.

• Example: R3 := R1 JOIN C R2 can be written:

R4 := R1 * R

R3 := SELECT C (R4)

Expressions in a Single Assignment

• Example: the theta-join

R3 := R1 JOIN C R2 can be written

R3 := SELECT C (R1 * R2)

• Precedence of relational operators:

– [SELECT, PROJECT, RENAME] (highest).

– [PRODUCT, JOIN].

– INTERSECTION.

– [UNION, --]