CSE 326: Data Structures Lecture #22 Databases and Sorting Alon Halevy Spring Quarter 2001.

Slides:



Advertisements
Similar presentations
What is a Database By: Cristian Dubon.
Advertisements

Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19 Algorithms for Query Processing and Optimization.
Relational Algebra Tim Kaddoura CS157A. Introduction  Relational query languages are languages for describing queries on a relational database  Three.
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
CS4432: Database Systems II Query Operator & Algebraic Expressions 1.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
1 Relational Model and Translating ER into Relational.
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
1 Chapter 10 Query Processing: The Basics. 2 External Sorting Sorting is used in implementing many relational operations Problem: –Relations are typically.
1 Query Processing: The Basics Chapter Topics How does DBMS compute the result of a SQL queries? The most often executed operations: –Sort –Projection,
One More Normal Form Consider the dependencies: Product Company Company, State Product Is it in BCNF?
Relation Decomposition A, A, … A 12n Given a relation R with attributes Create two relations R1 and R2 with attributes B, B, … B 12m C, C, … C 12l Such.
1 Lecture 4: Database Modeling (end) The Relational Data Model April 8, 2002.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
CSCE Database Systems Chapter 15: Query Execution 1.
Relational Model Concepts. The relational model represents the database as a collection of relations. Each relation resembles a table of values. A table.
Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
1 Lecture 7: Normal Forms, Relational Algebra Monday, 10/15/2001.
CS4432: Database Systems II Query Processing- Part 2.
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
Query Processing – Query Trees. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
B+ Trees: An IO-Aware Index Structure Lecture 13.
Relational Algebra p BIT DBMS II.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 9 A First Course in Database Systems.
Query Execution. Where are we? File organizations: sorted, hashed, heaps. Indexes: hash index, B+-tree Indexes can be clustered or not. Data can be stored.
Lectures 2&3: Introduction to SQL. Lecture 2: SQL Part I Lecture 2.
Hassan Tariq INTRODUCTION TO SQL What is SQL? –When a user wants to get some information from a database file, he can issue a query. – A query is a user–request.
Query Processing – Implementing Set Operations and Joins Chap. 19.
1 Lecture 08: E/R Diagrams and Functional Dependencies Friday, January 21, 2005.
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
CSE202 Database Management Systems
COP5725 Database Management ER DIAGRAM AND RELATIONAL DATA MODEL
COP4710 Database Systems Relational Algebra.
Chapter # 6 The Relational Algebra and Calculus
Fundamental of Database Systems
Relational Algebra at a Glance
Lecture 8: Relational Algebra
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
CS 440 Database Management Systems
Chapter 2: Intro to Relational Model
Relational Algebra Chapter 4, Part A
Lecture 2 (cont’d) & Lecture 3: Advanced SQL – Part I
March 30th – intro to joins
Cse 344 January 10th –joins.
LECTURE 3: Relational Algebra
The Relational Algebra and Relational Calculus
The Relational Algebra
Introduction to SQL Wenhao Zhang October 5, 2018.
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Lecture 06 Data Modeling: E/R Diagrams
Lectures 3: Introduction to SQL 2
Introduction to Database Systems CSE 444 Lecture 02: SQL
One-Pass Algorithms for Database Operations (15.2)
The Relational Algebra
Chapter 2: Intro to Relational Model
Lecture 5: The Relational Data Model
Lecture 13: Query Execution
Terminology Product Attribute names Name Price Category Manufacturer
External Sorting Sorting is used in implementing many relational operations Problem: Relations are typically large, do not fit in main memory So cannot.
Lectures 2: Introduction to SQL 1
Syllabus Introduction Website Management Systems
Database Administration
Lecture 08: E/R Diagrams and Functional Dependencies
Presentation transcript:

CSE 326: Data Structures Lecture #22 Databases and Sorting Alon Halevy Spring Quarter 2001

Agenda Reminisce about Project 3. A bit on graphs. Get excited about Project 4 (short course on databases) Start talking about sorting.

Database Systems Enable you to manage large (huge) amounts of data: –Store the data efficiently –Pose complex queries on the data in a high-level language (e.g., SQL) –Enable concurrent access to the data by many users. –Embed database queries into application programs. The market: mostly relational databases.

Terminology Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi tuples Attribute names

More Terminology Every attribute has an atomic type. Relation Schema: relation name + attribute names + attribute types Relation instance: a set of tuples. Only one copy of any tuple! Database Schema: a set of relation schemas. Database instance: a relation instance for every relation in the schema.

Querying a Database The query language enables performing relational operators: –Selection (select a subset of the tuples from a table) –Projection (select a subset of the columns) –Join (match up two tables on certain attributes) –Union, negation, aggregation, etc., etc. Operations take table(s) as input and produce a table. SQL manual is a very effective doorstop.

Selection Produce a subset of the tuples in a relation which satisfy a given condition Unary operation… returns set with same attributes, but ‘selects’ rows Use and, or, not, >, <… to build condition Find all employees with salary more than $40,000:

Find all employees with salary more than $40,000.

Projection Unary operation, selects columns Eliminates duplicate tuples Example: project social-security number and names.

Join (Natural) Most important, expensive and exciting. Combines two relations, selecting only related tuples Resulting schema has all attributes of the two relations, but one copy of join condition attributes

Step 1 Read the schema (format given). Create the data structure to store tables. Read the data (each table is in a separate file, tuple per line).

Step 2 Read the query. The form is: Select attributes From Tables Where selection conditions, join conditions. Order By: attribute Note: no Cartesian products, may join two tables on more than one attribute. Dirty hack for self joins.

Step 3 Execute the query. Perform all joins (each join creates and intermediate table). Perform selections Perform projections Order the output (if necessary)

Notes on Mechanics Groups of 3-4 students. Send to Maya, Nic and Alon by Monday, the 21 st. Hash join (explained in section yesterday). Grading: demos (15 minutes per group) + 2-page writeup. Dates? You have a lot of freedom in this project. You’ll have to make a lot of choices on your own. Data (about you) Help: all of us + Peter Mork Homework 5 turn-in.

Sorting Given a set of N numbers, put them in order. We’ll see several algorithms for comparison sort: –Insertion sort –Merge sort –Quicksort –Heap sort. How well can we expect to do?? What is the minimum # of comparisons that any algorithm could do.

Decision tree to sort list A,B,C

Max depth of the decision tree How many permutations are there of N numbers? How many leaves does the tree have? What’s the shallowest tree with a given number of leaves? What is therefore the worst running time (number of comparisons) by the best possible sorting algorithm?

Stirling’s approximation