SlideServe
Menu
Préférences
© SlideServe · v2026

Relational Algebra

brenda-warren avatar
14 diapositives · 384 Views · Nov 19, 2014

Relational Algebra. For CS420. Relational Algebra. The relational algebra is a collection of operators that take relations as their operands and return a relation as their result Eight operators Union, intersect, difference Restrict, project, Cartesian product, Join, divide

Relational Algebra - slide 1
01 / 14Relational Algebra
1 / 17

Télécharger la présentation

Relational Algebra
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Relational Algebra For CS420

  2. Relational Algebra • The relational algebra is a collection of operators that take relations as their operands and return a relation as their result • Eight operators • Union, intersect, difference • Restrict, project, • Cartesian product, Join, divide • The operators are “read only”

  3. The operations are closed • The output from any relational operator is another relation: the closure property • Relational expressions can be nested (analogously to arithmetic expressions) • RENAME changes the name of an attribute without changing its type or content

  4. Union - (A UNION B) or A + B • Union operates on two sets and returns a set that contains all elements belonging to either • Both sets must be of the same type - formerly known as union compatibility • Relations cannot have duplicate tuples; we say loosely that UNION “eliminates duplicates”

  5. Intersect and Difference • Intersect operates on two sets and returns a set that contains all tuples belonging to both • Difference operates on two sets and returns a set containing all tuples occuring in one but not the other, using MINUS • For both Intersect and Difference, the sets operated upon must be of the same type - formerly known as union compatibility • (A INTERSECT/MINUS B) OR A - B

  6. Semantics of the Original Algebra –Intersect and Difference

  7. Cartesian Product • A Cartesian Product is the set of all ordered pairs such that in each pair, the first element comes from the first set, and the second element comes from the second set • However, since the result of a relational operator is a relation, the result of each pair is a single tuple containing all the elements of both of the source tuples • (A TIMES B) or A x B

  8. Cartesian Product

  9. Restrict or Select • Yields a horizontal subset • Format: A WHERE p • p is called the restriction condition • p is a predicate, and returns boolean for each tuple

  10. Restrict and others • OR and Union • A WHERE p1 or p2 • (A WHERE p1) UNION (A WHERE p2) • AND and INTERSECT • A WHERE p1 AND p2 • (A WHERE p1) INTERSECT (A WHERE p2) • NOT and MINUS • A WHERE NPT (p) • A MINUS (A WHERE p)

  11. Project • Yields a vertical subset • The general form is a comma list of attributes to be kept in the result • For all attributes kept, all tuples are kept • Format A{C1, C2}

  12. Join – Natural Join • Join is a Product followed by Select • When unqualified, join means “natural join” • Format: A Join B on A.C1 = B.C2

  13. Examples • Get supplier names for suppliers who supply part p2 ((SP Join S on S.SNO = SP.SNO) Where PNO = ‘P2’) {SNAME} • Get supplier names for suppliers who supply a red part (((P WHERE COLOR = ‘Red’) JOIN SP on SP.PNO = P.PNO) JOIN S on SP.SNP = S.SNO) {SNAME} • Get supplier names for suppliers who supply all parts (S WHERE (SP WHERE SP.SNO = S.SNO) {PNO} = P {PNO}) {SNAME} • Get supplier names for suppliers who do not supply P2 ((S{SNO} MINUS (SP WHERE PNO = ‘P2’) {SNO}) Join S {SNAME}

  14. More Examples • Get pairs of supplier numbers such that the suppliers are located in the same city ( ( (S RENAME SNO as SA) {SA, CITY} JOIN // on city = city (S RENAME SNO as SB) {SB, CITY} ) WHERE SA < SB ) {SA, SB} S JOIN S as S1 on S.CITY=S1.CITY WHERE S.SNO < S1.SNO {S.SNO, S1.SNO} (S RENAME SNO as SA) {SA, CITY} as T1 (S RENAME SNO as SB) {SA, CITY} as T2 T1 Join T2 as T3 // Join condition is T1.City = T2.City T3 Where SA < SB {SA, SB}