{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

23-RelationalAlgebra

# 23-RelationalAlgebra - Discussion#23 Relational Algebra...

This preview shows pages 1–9. Sign up to view the full content.

Discussion #23 Chapter 12, Section 3 & 5.1 & 5.4 (through Basic Data Queries) 1/32 Discussion #23 Relational Algebra

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Discussion #23 Chapter 12, Section 3 & 5.1 & 5.4 (through Basic Data Queries) 2/32 Topics Algebras Relational Algebra use of standard notation set operators , , - renaming ρ selection σ projection π cross product × join | × | Queries (from English) Query optimization SQL
Discussion #23 Chapter 12, Section 3 & 5.1 & 5.4 (through Basic Data Queries) 3/32 Relational Algebra What is an algebra? a pair: (set of values, set of operations) ADT type Class Object e.g. stack: (set of all stacks, {pop, push, top, …}) integer: (set of all integers, {+, -, *, ÷ }) What is relational algebra? (set of relations, set of relational operators) { , , - , ρ , σ , π , × , | × |} Notation: We’ll use standard notation. Names: same as book’s (except selection = restriction) Definitions the same, syntax different

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Discussion #23 Chapter 12, Section 3 & 5.1 & 5.4 (through Basic Data Queries) 4/32 Relational Algebra is Closed Closed: all operations produce values in the value set (reals, {+, *, - }) closed (reals, {+, *, - , ÷ }) not closed (divide by 0) (reals, {+, *, >}) not closed (T/F not in value set) (computer reals, {+, *, - }) not closed (overflow, roundoff) (relations, relational operators) closed Implication: we can always nest relational operators; can’t for algebras that are not closed. e.g. after overflow, can do nothing e.g. can’t always nest: (2 < 3) + 5 = ?
Discussion #23 Chapter 12, Section 3 & 5.1 & 5.4 (through Basic Data Queries) 5/32 Set Operations: , , and - Relations are sets; thus set operations should work. Examples: R = A B 1 2 2 2 2 3 S = A B 2 2 2 3 4 2 5 5 R S = A B 1 2 2 2 2 3 4 2 5 5 R S = A B 2 2 2 3 R - S = A B 1 2 S - R = A B 4 2 5 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Discussion #23 Chapter 12, Section 3 & 5.1 & 5.4 (through Basic Data Queries) 6/32 Set Operations (continued …) Definition: schema(R) = {A, B} = AB, i.e. the set of attributes We sometimes write R(AB) to mean the relation R with schema AB. Definition: union compatible schema(R) = schema(S) required precondition for , , - Definitions: R S = { t | t R t S} R S = { t | t R t S} R - S = { t | t R t S}
Discussion #23 Chapter 12, Section 3 & 5.1 & 5.4 (through Basic Data Queries) 7/32 Tuple Restriction: [X] Restriction is a tuple operator (not a relational operator). t[X] restricts tuple t to the attributes in X. A B C t = 1 2 3 t[ A ] = (1) t[ AC ] = (1,3) t = (1,2,3) t[A] = (1,2,3)[A] = {(A,1), (B, 2), (C,3)}[A] = {(A,1)} = (1)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Discussion #23 Chapter 12, Section 3 & 5.1 & 5.4 (through Basic Data Queries) 8/32 Renaming: ρ 2200 ρ A B R renames attribute A to be B. A must be in schema(R) B must not be in schema(R) Example: let ρ C B Q = A B 2 2 3 2 R ∪ρ C B Q = A B 1 2 2 2 2 3 3 2 R = A B 1 2 2 2 2 3 Q = A C 2 2 3 2 But with ρ : R Q = ?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 32

23-RelationalAlgebra - Discussion#23 Relational Algebra...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online