1 / 12

ICS 321 Spring 2011 Algebraic and Logical Query Languages

ICS 321 Spring 2011 Algebraic and Logical Query Languages. Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa. Relational Algebra Review. Relations are sets of tuples – no duplicates allowed Basic operations:

lenora
Download Presentation

ICS 321 Spring 2011 Algebraic and Logical Query Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ICS 321 Spring 2011Algebraic and Logical Query Languages Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa Lipyeow Lim -- University of Hawaii at Manoa

  2. Relational Algebra Review • Relations are sets of tuples – no duplicates allowed • Basic operations: • Selection (σ) Selects a subset of rows from relation. • Projection (π) Deletes unwanted columns from relation. • Cross-product(×) Allows us to combine two relations. • Set-difference (−) Tuples in reln. 1, but not in reln. 2. • Union(U) Tuples in reln. 1 and in reln. 2. • Additional operations: • Intersection, join, division, renaming: Not essential, but (very!) useful. • Each operation returns a relation, operationscan be composed! (Algebra is “closed”.) Lipyeow Lim -- University of Hawaii at Manoa

  3. Bag Semantics Bag Set • Commercial DBMS implements relations as bags • Avoid duplicate elimination • Support aggregations Can relational algebra work with bags ? Lipyeow Lim -- University of Hawaii at Manoa

  4. Selection & Projection • Expected behavior • No duplicate elimination of results πage (S2) πage (σrating>6 (S2)) Lipyeow Lim -- University of Hawaii at Manoa

  5. Cross Product & Joins S R  S R Cross Product Join Treat duplicates like non-duplicates Lipyeow Lim -- University of Hawaii at Manoa

  6. Bag Union, Intersection & Difference S R R  S Bag Union Tuple t appears (n+m) times Bag Intersection Bag Difference R  S R - S S - R Treat duplicates like non-duplicates Tuple t appears min(n,m) times Tuple t appears max(0, n-m) times Lipyeow Lim -- University of Hawaii at Manoa

  7. Extended Operators • Duplicate elimination  • turns a bag into a set • Aggregation • calculates an aggregate (sum, average etc) over the values in a column • Grouping  • partitions tuples in a relation into groups based on values in some columns • Extended projection  • allow computation on column values to produce new values • Sorting  • sorts a relation according to the values in some column(s) • Outer join • preserves dangling pointers in the results of joins Lipyeow Lim -- University of Hawaii at Manoa

  8. Aggregation • Standard: SUM, AVG, MIN, MAX, COUNT • DBMS supports more sophisticated functions like Variance, standard deviation etc. • SUM(B) = 2+4+2+2 = 10 • AVG(A) = (1+3+1+1)/4 = 1.5 • MIN(A) = 1 • MAX(B) = 4 • COUNT(A) = 4 Lipyeow Lim -- University of Hawaii at Manoa

  9. Grouping Movies • Grouping operator  • Groups tuples by some columns • Apply aggregation function to each group • Generate a result tuple per group For each studio, find the total lengths of movies produced Lipyeow Lim -- University of Hawaii at Manoa

  10. Grouping Operator Arguments Movies studioName, SUM(length) sumOfLengths Aggregation functions on aggregated attributes with optional renaming Grouping attributes Lipyeow Lim -- University of Hawaii at Manoa

  11. Extended Projection AX, B+CY (R) Renaming of attributes Expressions that compute new values from attributes and naming the new values Lipyeow Lim -- University of Hawaii at Manoa

  12. Outer Join R S Discard right & left dangling pointers R S R RS R L S Keep right dangling pointers Keep left dangling pointers Lipyeow Lim -- University of Hawaii at Manoa

More Related